Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

DaanDeMeyer
Copy link

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

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]>
Copy link
Collaborator

@smcv smcv left a 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) {
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis:

Suggested change
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>
Copy link
Collaborator

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"?

Comment on lines +475 to +477
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.
Copy link
Collaborator

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:

Suggested change
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.

@DaanDeMeyer
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ctrl+c sends SIGINT to bubblwrap instead of child process
2 participants