[PATCH 2/5] unshare: add signal forwarding handler
Kiran Rangoon <[email protected]> Thu, 8 Jan 2026 13:31:31 -0500
| Newsgroups | org.kernel.vger.util-linux |
|---|---|
| Message-ID | <[email protected]> |
Add forward_signal() function that forwards SIGTERM/SIGINT from the parent process to the child process. This will be installed as a signal handler in the next step. Signed-off-by: Kiran Rangoon <[email protected]> --- sys-utils/unshare.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 6df53666a..3850e5f4a 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -122,6 +122,19 @@ static void setgroups_control(int action) close(fd); } +/** + * forward_signal() - Forward signal to child process + * @sig: Signal number to forward + * + * Signal handler that forwards SIGTERM/SIGINT from parent to child. + * This allows the child to handle signals properly when using --fork. + */ +static void forward_signal(int sig) +{ + if (child_pid > 0) + kill(child_pid, sig); +} + static void map_id(const char *file, uint32_t from, uint32_t to) { char *buf; -- 2.47.3