Skip to content

Commit d92af7a

Browse files
authored
Merge pull request #571 from containers/545
Fix container exit detection when process is not a child of conmon in systemd scope environments
2 parents a39e92e + 90d6038 commit d92af7a

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)