From 94b917fd3ae16a7c4a4f52036723768a6ebf8d7d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 3 Dec 2012 17:38:36 +0000 Subject: [PATCH 2/6] dbus-spawn: draw a diagram There are enough pipes, fds and processes here that it's important to keep track of them. --- dbus/dbus-spawn.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index 5431602..96cd039 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -174,6 +174,36 @@ read_pid (int fd, * and the grandchild. The grandchild is our spawned process. The intermediate * child is a babysitter process; it keeps track of when the grandchild * exits/crashes, and reaps the grandchild. + * + * We automatically reap the babysitter process, killing it if necessary, + * when the DBusBabysitter's refcount goes to zero. + * + * Processes: + * + * main process + * | fork() A + * \- babysitter + * | fork () B + * \- grandchild --> exec --> spawned process + * + * IPC: + * + * main process | babysitter | grandchild + * ======================|======================|================| + * | child_err_report_pipe (genuinely a pipe) | + * |[READ_END]-------------<<------------------------[WRITE_END] | + * | << on failure: CHILD_EXEC_FAILED, errno | + * | << on success: nothing | | + * (error_pipe_from_child)| | (child_err_report_fd) + * | | | | + * | babysitter_pipe (misnamed, really a socketpair) | + * |[0]------------------<->------------[1] | | + * | << on fork() B failure: CHILD_FORK_FAILED, errno | + * | << on success: CHILD_PID, grandchild's pid| | + * | << on SIGCHLD: CHILD_EXITED, status | | + * | >> HUP or ERR when main process exits | | + * |(socket_to_babysitter)| (parent_pipe) | | + * |======================|======================|===============| */ /* Messages from children to parents */ -- 1.7.10.4