-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --foreground option #588
Conversation
This option creates a new process group for the child process and if there's a controlling terminal, makes the new process group the foreground process group of the controlling terminal. This makes sure that SIGINT signals generated by CTRL+C are only sent to the child process and not to bubblewrap itself. While this can also be achieved with external utilities (e.g. util-linux/util-linux#2445), it still makes sense to support this natively in bubblewrap to avoid the need to install any other utilities in the sandbox to be able to make the child process the foreground process group of the controlling terminal. Fixes containers#369 Signed-off-by: Daan De Meyer <[email protected]>
a2d8edc
to
fcd1ff2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still work if the top-level sandboxed process is one that would normally setpgid()
itself, like an interactive bash
shell?
@@ -3276,6 +3282,30 @@ main (int argc, | |||
setsid () == (pid_t) -1) | |||
die_with_error ("setsid"); | |||
|
|||
if (opt_foreground) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use GNU-style indentation:
if (opt_foreground)
{
cleanup_fd int tty_fd = -1;
...
if (sigprocmask (SIG_BLOCK, &mask, &old_mask) == -1) | ||
die_with_error ("sigprocmask"); | ||
|
||
if (tcsetpgrp (tty_fd, getpgid(0)) == -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before opening parenthesis:
if (tcsetpgrp (tty_fd, getpgid(0)) == -1) | |
if (tcsetpgrp (tty_fd, getpgid (0)) == -1) |
@@ -469,6 +469,14 @@ | |||
(see CVE-2017-5226). | |||
</para></listitem> | |||
</varlistentry> | |||
<varlistentry> | |||
<term><option>--foreground</option></term> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this should have a name more like --terminal-foreground
or --tty-foreground
, to indicate that it isn't to do with daemonization or other things that might be referred to as "foreground" or "background"?
Create a new process group for the sandbox (calls setpgid()) and make it the | ||
foreground process group of the controlling terminal if there is a | ||
controlling terminal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's missing a mention of why this is useful to do things like resolving #369. Perhaps something like this:
Create a new process group for the sandbox (calls setpgid()) and make it the | |
foreground process group of the controlling terminal if there is a | |
controlling terminal. | |
Create a new process group for the sandbox, and make it the | |
foreground process group of the controlling terminal if there is a | |
controlling terminal. This means that keyboard shortcuts that send | |
signals, such as Ctrl+C for SIGINT or Ctrl+\ for SIGQUIT, will send | |
the signal to the sandboxed process instead of to bubblewrap itself. |
It turns out that for my use case reimplementing the bits I need from bubblewrap is easier than trying to fix the tool to support my use case so I'm closing this as I no longer need it. |
This option creates a new process group for the child process and if there's a controlling terminal, makes the new process group the foreground process group of the controlling terminal. This makes sure that SIGINT signals generated by CTRL+C are only sent to the child process and not to bubblewrap itself.
While this can also be achieved with external utilities (e.g. util-linux/util-linux#2445), it still makes sense to support this natively in bubblewrap to avoid the need to install any other utilities in the sandbox to be able to make the child process the foreground process group of the controlling terminal.
Fixes #369