-
Notifications
You must be signed in to change notification settings - Fork 346
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
survive bereaving #141
base: master
Are you sure you want to change the base?
survive bereaving #141
Conversation
Thanks for sending in this PR! This request has come up a couple of times, notably in #80, so I think there are definitely legitimate use-cases for it. Sort of continuing my comment in that thread, it'd be cool if we could find a way to implement this that works even when dumb-init isn't PID 1, since it makes testing a lot easier (and also we use dumb-init in some non-PID-1 places). In that case, we'd need a way to list all child processes of dumb-init (rather than all processes on the system), and I don't know of a portable way to do that. On Linux, we could read I guess maybe we could also support this feature on Linux only? Do you know if there's a straightforward way to modify this change so that it only considers child PIDs when counting? |
I am not completely sure what is the desired behavior as non-pid1. Wait for all children, grandchildren... to exit and then exit dumb-init? What kind of portability are you trying to achieve? POSIX? In that case, the answer is 'ps' utility. |
Can I help push this pull request forward somehow? I'd love to use this functionality (on Linux). |
@Mathiasdm thanks for the bump! I think this is a solid PR, I've got a couple minor comments I'll leave but overall I think we can merge this pretty soon. |
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.
Thanks again for sending this PR! We'll also want to update the documentation and add some tests -- I can help with those things too. Let me know your thoughts here, I'm also happy to help make some of these changes :)
" -c, --single-child Run in single-child mode.\n" | ||
" In this mode, signals are only proxied to the\n" | ||
" direct child and not any of its descendants.\n" | ||
" -b, --survive-bereaving Do not quit when the direct child dies.\n" |
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 think it'd be helpful to add another line to clarify further when it actually does quit. Maybe a line like "In this mode, dumb-init will quit when there are no other processes running on the host. This mode requires dumb-init to be running as PID 1."?
@@ -199,6 +257,9 @@ char **parse_command(int argc, char *argv[]) { | |||
case 'r': | |||
parse_rewrite_signum(optarg); | |||
break; | |||
case 'b': | |||
survive_bereaving = 1; | |||
break; | |||
default: | |||
exit(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.
Since survive_bereaving
only works properly when dumb-init is running as PID 1, I think it'd be a good idea to add a check like:
if (survive_bereaving && getpid() != 1) {
PRINTERR("--survive-bereaving is only valid when dumb-init is running as PID 1.\n");
exit(1);
}
I think that would reduce confusion for anybody who tries to use the feature without being PID1.
@@ -68,6 +71,43 @@ void forward_signal(int signum) { | |||
} | |||
|
|||
/* | |||
* Read /proc and see if there are processes except init(PIDs) | |||
*/ | |||
signed int process_count() { |
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.
Since this isn't exactly returning the total process count, maybe it'd be better to rename this function to is_only_process_running
?
signed int pc = process_count(); | ||
DEBUG("Process count: %d\n", pc); | ||
if (pc <= 1) { | ||
DEBUG("No process left, exitting.\n"); |
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.
nit: typo exitting
-> exiting
{ | ||
while ((ep = readdir (dp)) != NULL) { | ||
nonnumber = 0; | ||
for (int i = 0; ep->d_name[i] != 0; ++i) { |
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.
nit: I think it'd be slightly more clear to write ep->d_name[i] != '\0'
|
||
dp = opendir ("/proc"); | ||
if (dp != NULL) | ||
{ |
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.
nit: formatting...
Does Alternatively, if you're trying to monitor all processes in the namespace, you'll have to monitor |
I just ran into an issue that this would have solved nicely. Is there anything needed before this can be merged or? |
current MR failed to compile with :
|
Hi,
sometimes it is useful to keep init alive when its direct child dies. For example when running a double-forking daemon or SysV init scripts.
This pull request adds a new option '--survive-bereaving' or '-b' that keeps dumb-init running. It checks /proc/ after SIGCHLD and quits only when there are no processes left.
Documentation is not updated, I do not feel confident enough in English.
Any comments are welcome.
Have a nice day,
Fero