From 13060ef4b5b813d6f294d4188d96ad073b4d88fe Mon Sep 17 00:00:00 2001 From: Karen Barsegyan Date: Thu, 5 Mar 2026 10:48:17 +0300 Subject: [PATCH] Fix zombie processes generation run_script function logic: forked process goes into if(!pid) and starts external script. After executing the script, process ends right after execvp and parent process continues working. It has to go to if(error) by origin logic, but it doesn't. Therefore waitpid isn't called and forked process lives in Z state until dhcp client stops. This bug leads to infinite spawning of Z processes. Therefore, just call waitpid in any case, not only error. And only after waitpid is done, check error code. --- toys/pending/dhcp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/toys/pending/dhcp.c b/toys/pending/dhcp.c index a72f9f0f..2c77720c 100644 --- a/toys/pending/dhcp.c +++ b/toys/pending/dhcp.c @@ -530,6 +530,7 @@ static int fill_envp(dhcpc_result_t *res) static void run_script(dhcpc_result_t *res, char *name) { volatile int error = 0; + int wstatus = 0; pid_t pid; char *argv[3]; struct stat sts; @@ -557,10 +558,15 @@ static void run_script(dhcpc_result_t *res, char *name) error = errno; _exit(111); } + waitpid(pid, &wstatus, 0); if (error) { - waitpid(pid, NULL,0); errno = error; perror_msg("script exec failed"); + } else if (!WIFEXITED(wstatus)) { + perror_msg("script process wait failed"); + } else if (WEXITSTATUS(wstatus)) { + errno = WEXITSTATUS(wstatus); + perror_msg("script exited with non-zero code: %d", WEXITSTATUS(wstatus)); } dbg("script complete.\n"); } -- 2.39.5