summaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2019-03-18 20:59:36 +0100
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>2019-10-21 16:37:15 +0200
commit79e9566ec0a61d887ab63f17192dbd71aae36ee0 (patch)
tree6e1c8b3167a2fee0ab69d58894764e5e712894a8 /src/core/socket.c
parentf057aa6bb604845fa10ad569bca306e5e1e8fe0d (diff)
downloadsystemd-79e9566ec0a61d887ab63f17192dbd71aae36ee0.tar.gz
core: reduce the number of stalled PIDs from the watched processes list when possible
Some PIDs can remain in the watched list even though their processes have exited since a long time. It can easily happen if the main process of a forking service manages to spawn a child before the control process exits for example. However when a pid is about to be mapped to a unit by calling unit_watch_pid(), the caller usually knows if the pid should belong to this unit exclusively: if we just forked() off a child, then we can be sure that its PID is otherwise unused. In this case we take this opportunity to remove any stalled PIDs from the watched process list. If we learnt about a PID in any other form (for example via PID file, via searching, MAINPID= and so on), then we can't assume anything. Thanks Renaud Métrich for backporting this to RHEL. Resolves: #1744972
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index d488c64e91..b034549634 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1816,7 +1816,7 @@ static int socket_coldplug(Unit *u) {
SOCKET_FINAL_SIGTERM,
SOCKET_FINAL_SIGKILL)) {
- r = unit_watch_pid(UNIT(s), s->control_pid);
+ r = unit_watch_pid(UNIT(s), s->control_pid, false);
if (r < 0)
return r;
@@ -1902,9 +1902,8 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
if (r < 0)
return r;
- r = unit_watch_pid(UNIT(s), pid);
+ r = unit_watch_pid(UNIT(s), pid, true);
if (r < 0)
- /* FIXME: we need to do something here */
return r;
*_pid = pid;
@@ -1973,7 +1972,7 @@ static int socket_chown(Socket *s, pid_t *_pid) {
_exit(EXIT_SUCCESS);
}
- r = unit_watch_pid(UNIT(s), pid);
+ r = unit_watch_pid(UNIT(s), pid, true);
if (r < 0)
goto fail;