[PATCH 4/5] unshare: store child PID in global variable
Kiran Rangoon <[email protected]> Thu, 8 Jan 2026 13:31:33 -0500
| Newsgroups | org.kernel.vger.util-linux |
|---|---|
| Message-ID | <[email protected]> |
After fork(), store the child PID in the global child_pid variable so the signal handler can forward signals to it. Clear child_pid in the child process to prevent recursion. Signed-off-by: Kiran Rangoon <[email protected]> --- sys-utils/unshare.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 9255ff4f8..8bc805e05 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -1149,6 +1149,7 @@ int main(int argc, char *argv[]) case -1: err(EXIT_FAILURE, _("fork failed")); case 0: /* child */ + child_pid = 0; /* Clear in child process */ if (sigprocmask(SIG_SETMASK, &oldsigset, NULL)) err(EXIT_FAILURE, _("sigprocmask restore failed")); @@ -1156,6 +1157,7 @@ int main(int argc, char *argv[]) close(fd_bind); break; default: /* parent */ + child_pid = pid; /* Store child PID for signal handler */ break; } } -- 2.47.3