From 062e55ebd1b567ed007832a8aa9fb9d125e44dc8 Mon Sep 17 00:00:00 2001 From: Alexander Turenko <alexander.turenko@tarantool.org> Date: Mon, 13 Apr 2020 13:37:55 +0300 Subject: [PATCH] popen: clarify group signaling details Even when ..._SETSID and ..._GROUP_SIGNAL are set, we unable to safely kill a process group after the child process we spawned becomes died. So we don't do that. The behaviour seems to be indefeasible part of Unix process group design. The best that we can do here is describe those details in the documentation comment. NB: It seems that pid namespaces allow to overcome this problem, however it is the Linux specific feature, so we unlikely will use them. Part of #4031 Acked-by: Cyrill Gorcunov <gorcunov@gmail.com> --- src/lib/core/popen.c | 9 +++++++++ src/lib/core/popen.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index 411aad03ba..5cd7926d1f 100644 --- a/src/lib/core/popen.c +++ b/src/lib/core/popen.c @@ -539,6 +539,13 @@ popen_state_str(unsigned int state) * When POPEN_FLAG_GROUP_SIGNAL is set the function sends * a signal to a process group rather than a process. * + * A signal will not be sent if the child process is already + * dead: otherwise we might kill another process that occupies + * the same PID later. This means that if the child process + * dies before its own childs, the function will not send a + * signal to the process group even when ..._SETSID and + * ..._GROUP_SIGNAL are set. + * * Return 0 at success or -1 at failure (and set a diag). * * Possible errors: @@ -597,6 +604,8 @@ popen_send_signal(struct popen_handle *handle, int signo) * - Remove the handle from a living list. * - Free all occupied memory. * + * @see popen_send_signal() for note about ..._GROUP_SIGNAL. + * * Return 0 at success and -1 at failure (and set a diag). * * Possible errors: diff --git a/src/lib/core/popen.h b/src/lib/core/popen.h index 4cdd951751..8cb71e28d9 100644 --- a/src/lib/core/popen.h +++ b/src/lib/core/popen.h @@ -99,6 +99,8 @@ enum popen_flag_bits { /* * Send signal to a process group. + * + * @see popen_send_signal() for details. */ POPEN_FLAG_GROUP_SIGNAL_BIT = 16, POPEN_FLAG_GROUP_SIGNAL = (1 << POPEN_FLAG_GROUP_SIGNAL_BIT), -- GitLab