dumb-init
dumb-init copied to clipboard
survive bereaving
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
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 /proc/<pid>/tasks/<pid>/children
, but to my knowledge this interface isn't available outside of Linux and the only other way is to iterate all processes on the system and read their parent PID (https://lwn.net/Articles/475688/ -- this also seems to be what pstree does).
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? My use-case is the opposite, I want init to keep running as long as there is any process in the namespace, including processes that are not descendants of init but entered the namespace from elsewhere. To achieve that, init must wake at regular intervals (I do not know of a better way) - init will not receive sigchld for those processes.
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.
Does PR_SET_CHILD_SUBREAPER
work for the non PID-1 case?
Alternatively, if you're trying to monitor all processes in the namespace, you'll have to monitor /proc
at regular intervals (not just when SIGCHLD is received) or write some hack with inotify...
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 :
dumb-init.c: In function 'handle_signal':
dumb-init.c:170:21: error: 'exit_status' may be used uninitialized in this function [-Werror=maybe-uninitialized]
exit(exit_status);
^
cc1: all warnings being treated as errors