]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
unshare: add --forward-signals option to argument parser
authorKiran Rangoon <kiranrangoon0@gmail.com>
Fri, 16 Jan 2026 17:06:45 +0000 (12:06 -0500)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Jan 2026 10:51:29 +0000 (11:51 +0100)
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 <kiranrangoon0@gmail.com>
bash-completion/unshare
sys-utils/unshare.c

index 19eeb8f08f241b198c6706edd40209f130b76b20..fdd40e5cbea14167c8f69cd9718a1c2de22ba59c 100644 (file)
@@ -28,6 +28,7 @@ _unshare_module()
                                --cgroup
                                --time
                                --fork
+                               --forward-signals
                                --kill-child
                                --keep-caps
                                --mount-proc
index 5370ab98122d9686a1bc28fc85ed73154e85da2f..8a7a26df2df6fa6f044f1d315f164f69059e1eec 100644 (file)
@@ -769,6 +769,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -f, --fork                fork before launching <program>\n"), out);
        fputs(_(" --kill-child[=<signame>]  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;