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. |
chriskuehl
left a comment
There was a problem hiding this comment.
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.
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."?
| break; | ||
| default: | ||
| exit(1); | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| /* | ||
| * Read /proc and see if there are processes except init(PIDs) | ||
| */ |
There was a problem hiding this comment.
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.
nit: typo exitting -> exiting
| if (dp != NULL) | ||
| { | ||
| while ((ep = readdir (dp)) != NULL) { | ||
| nonnumber = 0; |
There was a problem hiding this comment.
nit: I think it'd be slightly more clear to write ep->d_name[i] != '\0'
| signed int count = 0; | ||
|
|
||
| dp = opendir ("/proc"); | ||
| if (dp != NULL) |
|
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