From: Kiran Rangoon Date: Fri, 16 Jan 2026 17:06:45 +0000 (-0500) Subject: unshare: add --forward-signals option to argument parser X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7de939de477e3ca977ce25cf795f4d51ac12150;p=thirdparty%2Futil-linux.git unshare: add --forward-signals option to argument parser Add a new --forward-signals command-line option that will allow unshare to forward SIGTERM and SIGINT signals from the parent process to the forked child process. This commit adds the option parsing infrastructure but does not implement the signal forwarding logic yet. The flag defaults to 0 (disabled) to maintain backward compatibility. Signed-off-by: Kiran Rangoon --- diff --git a/bash-completion/unshare b/bash-completion/unshare index 19eeb8f08..fdd40e5cb 100644 --- a/bash-completion/unshare +++ b/bash-completion/unshare @@ -28,6 +28,7 @@ _unshare_module() --cgroup --time --fork + --forward-signals --kill-child --keep-caps --mount-proc diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 5370ab981..8a7a26df2 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -769,6 +769,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -f, --fork fork before launching \n"), out); fputs(_(" --kill-child[=] when dying, kill the forked child (implies --fork)\n" " defaults to SIGKILL\n"), out); + fputs(_(" --forward-signals forward SIGTERM and SIGINT to child (implies --fork)\n"), out); fputs(USAGE_SEPARATOR, out); fputs(_(" --setgroups allow|deny control the setgroups syscall in user namespaces\n"), out); fputs(_(" --keep-caps retain capabilities granted in user namespaces\n"), out); @@ -801,6 +802,7 @@ int main(int argc, char *argv[]) OPT_MAPAUTO, OPT_MAPSUBIDS, OPT_OWNER, + OPT_FORWARD_SIGNALS, }; static const struct option longopts[] = { { "help", no_argument, NULL, 'h' }, @@ -817,6 +819,7 @@ int main(int argc, char *argv[]) { "fork", no_argument, NULL, 'f' }, { "kill-child", optional_argument, NULL, OPT_KILLCHILD }, + { "forward-signals", no_argument, NULL, OPT_FORWARD_SIGNALS }, { "mount-proc", optional_argument, NULL, OPT_MOUNTPROC }, { "mount-binfmt", optional_argument, NULL, OPT_MOUNTBINFMT }, { "map-user", required_argument, NULL, OPT_MAPUSER }, @@ -843,7 +846,7 @@ int main(int argc, char *argv[]) int setgrpcmd = SETGROUPS_NONE; int unshare_flags = 0; - int c, forkit = 0; + int c, forkit = 0, forward_signals = 0; uid_t mapuser = -1, owneruser = -1; gid_t mapgroup = -1, ownergroup = -1; struct map_range *usermap = NULL; @@ -1015,6 +1018,10 @@ int main(int argc, char *argv[]) keepcaps = 1; cap_last_cap(); /* Force last cap to be cached before we fork. */ break; + case OPT_FORWARD_SIGNALS: + forkit = 1; + forward_signals = 1; + break; case 'S': uid = strtoul_or_err(optarg, _("failed to parse uid")); force_uid = 1;