Skip to content

bubblewrap: add --as-pid-1#196

Merged
alexlarsson merged 1 commit intocontainers:masterfrom
giuseppe:no-reaper
Jun 13, 2017
Merged

bubblewrap: add --as-pid-1#196
alexlarsson merged 1 commit intocontainers:masterfrom
giuseppe:no-reaper

Conversation

@giuseppe
Copy link
Copy Markdown
Member

Useful to run a process with PID=1

Signed-off-by: Giuseppe Scrivano gscrivan@redhat.com

Copy link
Copy Markdown
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Only minor nits, though it should be pretty easy to at least add a use of this in tests/test-run.sh, something like run bash -c 'echo $$' and assert the output is 1?

Comment thread bubblewrap.c Outdated
" --info-fd FD Write information about the running container to FD\n"
" --new-session Create a new terminal session\n"
" --die-with-parent Kills with SIGKILL child process (COMMAND) when bwrap or bwrap's parent dies.\n"
" --no-reaper Do not install a reaper process with PID=1\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about --as-pid1, like the inverse of systemd-nspawn --as-pid2?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am fine with it. @alexlarsson do you like --as-pid1 more?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general, this option only makes sense with unshare-pid. Maybe we should verify that and print a warning if not. Maybe it could be --unshare-pid-noinit?

Copy link
Copy Markdown
Collaborator

@cgwalters cgwalters Jun 13, 2017

Choose a reason for hiding this comment

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

I dunno...it feels like we're optimizing for the wrong thing here. We can easily error out if the user doesn't pass --unshare-pid too.

But if I was looking at the --help output I would be a lot less likely to find --unshare-pid-noinit if I was looking for this functionality.

--as-pid1 The executed program will be PID 1 (suppress builtin init)
vs
--unshare-pid-noinit Do not install a reaper process with PID=1

?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(Sorry to bikeshed, but OTOH the command line is the bwrap "API" and it makes sense to consider it carefully I think)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also like --as-pid-1 more, easier to find it the --help output. I am fine to change the patch if consensus is reached

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

--as-pid-1 sounds good to me!

Comment thread bubblewrap.c Outdated
__debug__ (("forking for child\n"));

if (opt_unshare_pid || lock_files != NULL || opt_sync_fd != -1)
if (!no_reaper && (opt_unshare_pid || lock_files != NULL || opt_sync_fd != -1))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

!as_pid1 as a variable would also read better than the double-negative !no

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should also check if the user specified any lock files or a sync-fd and error out, because those require support from our own pid1.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, opt_die_with_parent needs pid1 too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, if opt_unshare_pid is set *and no_reaper, then we should not allocate event_fd (because it needs the init process).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hm.. doesn't opt_die_with_parent still work without pid1? The handle_die_with_parent() just before the execvp will still be valid no?

I've done a quick test and the process in the sandbox exits when bwrap is killed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

True, i was just looking at the handle_die_with_parent call in do_init(). It should work.

Comment thread bubblewrap.c Outdated

if (opt_sync_fd != -1)
close (opt_sync_fd);
if (!no_reaper)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't need this hunk, since we can rely on sync_fd = -1 in this case right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought of leaking opt_sync_fd into the container process so that sync_fd would still work with --no-reaper (unless the container process doesn't close it), so that the two options are not mutually exclusive.

I'd say it should be fine to leak opt_sync_fd, or do we change to an explicit error?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess that leaking the fd should work. However, please add a more detailed comment about this in the code.

Comment thread bubblewrap.c Outdated
static int proc_fd = -1;
static char *opt_exec_label = NULL;
static char *opt_file_label = NULL;
static bool no_reaper;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Call this opt_no_reaper to match the other options.

@giuseppe giuseppe force-pushed the no-reaper branch 2 times, most recently from a4d3cdd to a86d621 Compare June 13, 2017 15:28
@giuseppe
Copy link
Copy Markdown
Member Author

pushed a new version with all the comments addressed

@giuseppe giuseppe force-pushed the no-reaper branch 2 times, most recently from 06a606e to d6f611c Compare June 13, 2017 20:13
It allows to run a process with PID=1 in the new pid namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe changed the title bubblewrap: add --no-reaper bubblewrap: add --as-pid-1 Jun 13, 2017
@giuseppe
Copy link
Copy Markdown
Member Author

I changed the option name to --as-pid-1

@cgwalters
Copy link
Copy Markdown
Collaborator

@alexlarsson This repo uses homu, now we have a merge commit 😞

@alexlarsson
Copy link
Copy Markdown
Collaborator

@cgwalters :( too many different repos...

@cgwalters
Copy link
Copy Markdown
Collaborator

I understand, it bites me too. Things should now be set up on this repo though so that only homu can push.

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.

3 participants