Skip to content

Commit 90d6038

Browse files
committed
Fix container exit detection in systemd scope environments
When container processes are not direct children of conmon conmon fails to detect container exits because it never receives SIGCHLD signals. This fixes issue where conmon processes remain running after container exit in certain systemd cgroup manager configurations. Fixes: #545 Signed-off-by: Jindrich Novy <jnovy@redhat.com>
1 parent a39e92e commit 90d6038

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/ctr_exit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ static void check_child_processes(GHashTable *pid_to_handler, GHashTable *cache)
4646
continue;
4747

4848
if (pid < 0 && errno == ECHILD) {
49+
/* Before quitting, check if container_pid is still alive.
50+
* In some systemd configurations, the container process may not be
51+
* a direct child, so we won't receive SIGCHLD when it exits.
52+
* Use kill(pid, 0) to check if the process still exists. */
53+
if (container_pid > 0) {
54+
if (kill(container_pid, 0) == 0) {
55+
/* Container process is still alive but not our child.
56+
* Don't quit the main loop yet. */
57+
ninfof("Container process %d is still alive but not a direct child", container_pid);
58+
return;
59+
} else if (errno == ESRCH) {
60+
/* Container process has exited */
61+
ninfof("Container process %d has exited (detected via kill probe)", container_pid);
62+
/* Simulate container exit callback */
63+
container_status = 0; /* We can't get the real exit status */
64+
container_pid = -1;
65+
/* Fall through to quit the main loop */
66+
}
67+
}
4968
g_main_loop_quit(main_loop);
5069
return;
5170
}

0 commit comments

Comments
 (0)