]> git.wh0rd.org - home.git/blobdiff - vunshare.c
cros-board: update
[home.git] / vunshare.c
index 274eebcd9dc87e05008d3f57ff780012b1b2fb90..96fe7a35b677a3b24c6d7baae6222160591730d6 100644 (file)
@@ -4,7 +4,6 @@
  */
 
 /* TODO:
- * - Add userns support.
  * - Make pidns init optional.
  * - Make setproctitle nicer and include program argv[0].
  * - Set up prctl(PR_SET_PDEATHSIG).
@@ -51,14 +50,19 @@ static void unshare_net(void)
        if (!vunshare(CLONE_NEWNET))
                return;
 
-       int sock = socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+       int sock;
        struct ifreq ifr;
 
+       sock = socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+       if (sock < 0)
+               err(1, "socket(AF_LOCAL) failed");
+
        /* Equiv of `ip link set up lo`.  Kernel will assign 127.0.0.1 for us. */
        strcpy(ifr.ifr_name, "lo");
        if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
                err(1, "ioctl(SIOCGIFFLAGS) failed");
-       strcpy(ifr.ifr_name, "lo");
+
+       /* The kernel preserves ifr.ifr_name for use. */
        ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
        if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0)
                err(1, "ioctl(SIOCSIFFLAGS) failed");
@@ -190,7 +194,7 @@ static void setup_signal_handler(pid_t pid)
 
        child_pid = pid;
 
-       for (i = 1; i < SIGUNUSED; ++i)
+       for (i = 1; i < SIGRTMIN; ++i)
                if (sigaction(i, &sa, NULL) && errno != EINVAL)
                        fprintf(stderr, "sigaction(%i) failed: %s\n", i, strerror(errno));
        for (i = SIGRTMIN; i <= SIGRTMAX; ++i)
@@ -283,7 +287,18 @@ static const struct option opts[] = {
 
 static void usage(void)
 {
-       puts("Usage: unshare [options] <program>");
+       puts(
+               "Usage: unshare [options] <program>\n"
+               "\n"
+               "Options: [DimnpuU]\n"
+               "  -i   Use IPC namespaces\n"
+               "  -m   Use mount namespaces\n"
+               "  -n   Use net namespaces\n"
+               "  -p   Use pid namespaces\n"
+               "  -u   Use UTS namespaces\n"
+               "  -U   Use user namespaces\n"
+               "  -D   Daemonize program"
+       );
        exit(EX_USAGE);
 }