This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtunnel-ns.c
771 lines (654 loc) · 19.1 KB
/
tunnel-ns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
/* Establish network namespaces that will use tunnel devices as their
* default routes.
*
* Copyright © 2015 Zack Weinberg
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* There is NO WARRANTY.
*
* tunnel-ns PREFIX N
*
* creates N network namespaces, imaginatively named PREFIX_ns0,
* PREFIX_ns1, ... The loopback device in each namespace is brought
* up, with the usual address. /etc/netns directories for each
* namespace are created. No other setup is performed. (The tunnel
* interfaces are expected to be created on the fly by a program like
* 'openvpn-netns', which see. This is because (AFAICT) if you create
* a persistent tunnel ahead of time, and put its interface side into
* a namespace, it then becomes impossible for anything to reattach
* to the device side.)
*
* This program expects to be run with both stdin and stdout connected
* to pipes. As it creates each namespace, it writes one line to its
* stdout:
*
* PREFIX_nsX <newline>
*
* After all namespaces have been created, stdout is closed.
*
* Anything written to stdin is read and discarded. When stdin is
* *closed*, however, all of the network namespaces are torn down
* (killing any processes still in there, if necessary) and the
* program exits. This also happens on receipt of any catchable
* signal whose default action is to terminate the process without
* a core dump (e.g. SIGTERM, SIGHUP).
*
* Errors, if any, will be written to stderr.
*
* This program must be installed setuid root.
*
* This program makes extensive use of Linux-specific network stack
* features. A port to a different OS might well entail a complete
* rewrite. Apart from that, C99 and POSIX.1-2001 features are used
* throughout. It also requires dirfd, strdup, and strsignal, from
* POSIX.1-2008; execvpe, pipe2, and vasprintf, from the shared
* BSD/GNU extension set; and the currently Linux-specific signalfd.
*/
#define _GNU_SOURCE 1
#define _FILE_OFFSET_BITS 64 /* large directory readdir(), large rlimits */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/resource.h>
#include <sys/signalfd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if defined __GNUC__ && __GNUC__ >= 4
#define NORETURN void __attribute__((noreturn))
#define PRINTFLIKE __attribute__((format(printf,1,2)))
#else
#define NORETURN void
#define PRINTFLIKE /*nothing*/
#endif
/* Global state. */
static const char *progname;
static const char *const *child_env;
static sigset_t child_sigmask;
/* cleanup needs to know: */
static bool is_child_process;
static size_t n_namespaces;
static const char **namespace_names;
static const char **nsconfdir_names;
/* Error reporting. */
static NORETURN cleanup_and_exit(int);
static NORETURN
fatal(const char *msg)
{
fprintf(stderr, "%s: %s\n", progname, msg);
cleanup_and_exit(1);
}
static NORETURN
fatal_perror(const char *msg)
{
fprintf(stderr, "%s: %s: %s\n", progname, msg, strerror(errno));
cleanup_and_exit(1);
}
static PRINTFLIKE NORETURN
fatal_printf(const char *msg, ...)
{
va_list ap;
fprintf(stderr, "%s: ", progname);
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
putc('\n', stderr);
cleanup_and_exit(1);
}
static PRINTFLIKE NORETURN
fatal_eprintf(const char *msg, ...)
{
int err = errno;
fprintf(stderr, "%s: ", progname);
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fprintf(stderr, ": %s\n", strerror(err));
cleanup_and_exit(1);
}
static PRINTFLIKE NORETURN
usage(const char *msg, ...)
{
fprintf(stderr, "%s: ", progname);
va_list ap;
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
fprintf(stderr, "\nusage: %s prefix n_namespaces\n", progname);
cleanup_and_exit(2);
}
static void
fatal_if_unsuccessful_child(const char *child, int status)
{
if (status == 0)
return;
if (status == -1)
fatal_eprintf("invoking %s", child);
if (WIFEXITED(status))
fatal_printf("%s: unsuccessful exit %d", child, WEXITSTATUS(status));
if (WIFSIGNALED(status))
fatal_printf("%s: %s%s", child, strsignal(WTERMSIG(status)),
WCOREDUMP(status) ? " (core dumped)" : "");
fatal_printf("%s: unexpected status %04x (neither exit nor fatal signal)",
child, status);
}
/* Utilities. */
#define startswith(x, y) (!strncmp((x), (y), sizeof(y) - 1))
static int
compar_str(const void *a, const void *b)
{
return strcmp(*(const char *const *)a, *(const char *const *)b);
}
static char * PRINTFLIKE
xasprintf(const char *fmt, ...)
{
char *rv;
va_list ap;
va_start(ap, fmt);
if (vasprintf(&rv, fmt, ap) == -1)
fatal_perror("asprintf");
va_end(ap);
return rv;
}
static void *
xreallocarray(void *optr, size_t nmemb, size_t size)
{
/* s1*s2 <= SIZE_MAX if both s1 < K and s2 < K where K = sqrt(SIZE_MAX+1) */
const size_t MUL_NO_OVERFLOW = ((size_t)1) << (sizeof(size_t) * 4);
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
errno = ENOMEM;
fatal_perror("malloc");
}
void *rv = realloc(optr, size * nmemb);
if (!rv)
fatal_perror("malloc");
return rv;
}
static long long
xstrtonum(const char *str, long long minval, long long maxval,
const char *msgprefix)
{
if (minval > maxval)
fatal_printf("xstrtonum: misuse: minval(%lld) > maxval(%lld)",
minval, maxval);
long long rv;
char *endp;
errno = 0;
rv = strtoll(str, &endp, 10);
if (endp == str || *endp != '\0')
fatal_printf("%s: '%s': invalid number", msgprefix, str);
else if (errno)
fatal_eprintf("%s: '%s'", msgprefix, str);
else if (rv < minval)
fatal_printf("%s: '%s': too small (minimum %lld)", msgprefix, str, minval);
else if (rv > maxval)
fatal_printf("%s: '%s': too large (maximum %lld)", msgprefix, str, maxval);
return rv;
}
static long long
xstrtonum_usage(const char *str, long long minval, long long maxval,
const char *msgprefix)
{
if (minval > maxval)
fatal_printf("xstrtonum: misuse: minval(%lld) > maxval(%lld)",
minval, maxval);
long long rv;
char *endp;
errno = 0;
rv = strtoll(str, &endp, 10);
if (endp == str || *endp != '\0')
usage("%s: '%s': invalid number", msgprefix, str);
else if (errno)
usage("%s: '%s': %s", msgprefix, str, strerror(errno));
else if (rv < minval)
usage("%s: '%s': too small (minimum %lld)", msgprefix, str, minval);
else if (rv > maxval)
usage("%s: '%s': too large (maximum %lld)", msgprefix, str, maxval);
return rv;
}
static char *
xreadall(int fd)
{
size_t nread = 0;
size_t alloc = BUFSIZ;
char *buf = xreallocarray(0, alloc, 1);
for (;;) {
ssize_t count = read(fd, buf + nread, alloc - nread);
if (count == 0)
break;
if (count < 0)
fatal_perror("read");
nread += (size_t)count;
while (nread >= alloc) {
alloc *= 2;
buf = xreallocarray(buf, alloc, 1);
}
}
buf = xreallocarray(buf, nread+1, 1);
buf[nread] = '\0';
return buf;
}
/* Vectors. */
typedef struct strvec {
const char **vec;
size_t alloc;
size_t used;
} strvec;
typedef struct pidvec {
pid_t *vec;
size_t alloc;
size_t used;
} pidvec;
static void
strvec_append(strvec *v, const char *val)
{
if (v->used >= v->alloc) {
if (v->alloc == 0)
v->alloc = 8;
else
v->alloc *= 2;
v->vec = xreallocarray(v->vec, v->alloc, sizeof(char *));
}
v->vec[v->used++] = val;
}
static void
pidvec_clear(pidvec *v)
{
free (v->vec);
memset(v, 0, sizeof(pidvec));
}
static void
pidvec_append(pidvec *v, pid_t val)
{
if (v->used >= v->alloc) {
if (v->alloc == 0)
v->alloc = 8;
else
v->alloc *= 2;
v->vec = xreallocarray(v->vec, v->alloc, sizeof(char *));
}
v->vec[v->used++] = val;
}
static void
pidvec_from_text(pidvec *v, char *text, const char *msgprefix)
{
char *p = text;
char *token;
while ((token = strsep(&p, " \t\n"))) {
if (*token)
pidvec_append(v, (pid_t)xstrtonum(token, 0, INT_MAX, msgprefix));
}
free (text);
}
static void
pidvec_kill(pidvec *v, int signo)
{
for (size_t i = 0; i < v->used; i++)
kill(v->vec[i], signo); /* errors deliberately ignored */
}
/* Child process management. */
/* A process which is setuid - that is, getuid() != 0, geteuid() == 0 -
behaves differently than one which holds _only_ root credentials.
We don't want the scripts acting up because of that. This is done
only for child processes because one of the differences is that a
setuid program can be killed by the invoking (real) UID, which we
do want to allow. */
static void
become_only_root(void)
{
if (geteuid() != 0)
fatal("must be run as root");
/* Discard all supplementary groups. */
if (setgroups(0, 0))
fatal_perror("setgroups");
/* Set the real GID and UID to zero. This _should_ also set the
saved GID and UID, divorcing the process completely from its
original invoking user. */
if (setgid(0))
fatal_perror("setgid");
if (setuid(0))
fatal_perror("setuid");
}
static pid_t
spawn_with_redir(const char *const *argv, int child_stdin, int child_stdout)
{
fflush(0);
pid_t child = fork();
if (child == -1)
fatal_perror("fork");
if (child != 0)
return child; /* to the parent */
/* We are the child. The parent has arranged for it to be safe for
us to write to stderr under error conditions, but the cleanup
handler should not do anything. */
is_child_process = true;
/* Child-side stdin and stdout redirections. */
if (child_stdin != 0) {
if (close(0) && errno != EBADF)
fatal_perror("close");
if (child_stdin < 0) {
if (open("/dev/null", O_RDONLY) != 0)
fatal_perror("open");
} else {
if (dup(child_stdin) != 0)
fatal_perror("dup");
}
}
if (child_stdout != 1) {
if (close(1) && errno != EBADF)
fatal_perror("close");
if (child_stdout < 1) {
if (open("/dev/null", O_WRONLY) != 1)
fatal_perror("open");
} else {
if (dup(child_stdout) != 1)
fatal_perror("dup");
}
}
become_only_root();
if (sigprocmask(SIG_SETMASK, &child_sigmask, 0))
fatal_perror("sigprocmask");
execvpe(argv[0], (char *const *)argv, (char *const *)child_env);
fatal_perror("execvpe");
}
static pid_t
xspawnvp(const char *const *argv)
{
return spawn_with_redir(argv, -1, 2);
}
static void
runv(const char *const *argv)
{
pid_t pid = xspawnvp(argv);
int status;
if (waitpid(pid, &status, 0) != pid)
fatal_perror("waitpid");
fatal_if_unsuccessful_child(argv[0], status);
}
#define run(...) runv((const char *const []){ __VA_ARGS__, 0 })
static void
runv_ignore_failure(const char *const *argv)
{
pid_t pid = xspawnvp(argv);
int status;
if (waitpid(pid, &status, 0) != pid)
fatal_perror("waitpid");
}
#define run_ignore_failure(...) \
runv_ignore_failure((const char *const []){ __VA_ARGS__, 0 })
static char *
runv_get_output(const char *const *argv)
{
int pipefds[2];
if (pipe2(pipefds, O_CLOEXEC))
fatal_perror("pipe");
pid_t pid = spawn_with_redir(argv, -1, pipefds[1]);
close(pipefds[1]);
char *output = xreadall(pipefds[0]);
close(pipefds[0]);
int status;
if (waitpid(pid, &status, 0) != pid)
fatal_perror("waitpid");
fatal_if_unsuccessful_child(argv[0], status);
return output;
}
static void
runv_get_output_pids(pidvec *v, const char *const *argv)
{
char *buf = runv_get_output(argv);
pidvec_from_text(v, buf, argv[0]);
}
/* General setup. */
/* Infuriatingly, Linux refuses to adopt closefrom(). This is the
least-bad approach I have found. */
static void
close_unnecessary_fds(void)
{
DIR *fdir = opendir("/proc/self/fd");
if (fdir) {
int dfd = dirfd(fdir);
struct dirent *dent;
int fd;
for (;;) {
errno = 0;
dent = readdir(fdir);
if (!dent) break;
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
continue;
fd = (int)xstrtonum(dent->d_name, 0, INT_MAX,
"invalid /proc/self/fd entry");
if (fd >= 3 && fd != dfd)
close((int)fd);
}
if (errno)
fatal_perror("readdir: /proc/self/fd");
closedir(fdir);
} else {
/* Double blech. */
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl))
fatal_perror("getrlimit");
for (int fd = 3; fd < (int)rl.rlim_max; fd++)
close(fd);
}
/* It is convenient to set stdin nonblocking at this point, too. */
int flags = fcntl(0, F_GETFL);
if (flags == -1 || fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
fatal_perror("fcntl");
}
/* We pass down the environment variables TERM, TZ, LANG, and LC_*.
We forcibly set PATH to a known-good value.
All other environment variables are cleared. */
static void
prepare_child_env(char **envp)
{
strvec nenv;
memset(&nenv, 0, sizeof(strvec));
for (size_t i = 0; envp[i]; i++)
if (startswith(envp[i], "TERM=") ||
startswith(envp[i], "TZ=") ||
startswith(envp[i], "LANG=") ||
startswith(envp[i], "LC_"))
strvec_append(&nenv, envp[i]);
strvec_append(&nenv,
"PATH=/usr/local/bin:/usr/bin:/bin:"
"/usr/local/sbin:/usr/sbin:/sbin");
strvec_append(&nenv, 0);
qsort(nenv.vec, nenv.used - 1, sizeof(char *), compar_str);
child_env = nenv.vec;
}
static int
prepare_signals(void)
{
sigset_t parent_sigmask;
/* Receipt of any catchable signal whose default action is to
terminate the process without a core dump is treated the same as
stdin being closed. All these signals are blocked and handled via
signalfd. It is easier to define the signal set negatively. */
sigfillset(&parent_sigmask);
/* signals that cannot be caught */
sigdelset(&parent_sigmask, SIGKILL);
sigdelset(&parent_sigmask, SIGSTOP);
/* signals that normally suspend the process */
sigdelset(&parent_sigmask, SIGTSTP);
sigdelset(&parent_sigmask, SIGTTIN);
sigdelset(&parent_sigmask, SIGTTOU);
/* signals that are normally ignored */
sigdelset(&parent_sigmask, SIGCHLD);
sigdelset(&parent_sigmask, SIGURG);
sigdelset(&parent_sigmask, SIGWINCH);
/* signals indicating a fatal CPU exception or user abort */
sigdelset(&parent_sigmask, SIGABRT);
sigdelset(&parent_sigmask, SIGBUS);
sigdelset(&parent_sigmask, SIGFPE);
sigdelset(&parent_sigmask, SIGILL);
sigdelset(&parent_sigmask, SIGQUIT);
sigdelset(&parent_sigmask, SIGSEGV);
sigdelset(&parent_sigmask, SIGSYS);
sigdelset(&parent_sigmask, SIGTRAP);
/* save current signal mask for child procs */
if (sigprocmask(SIG_SETMASK, &parent_sigmask, &child_sigmask))
fatal_perror("sigprocmask");
int sfd = signalfd(-1, &parent_sigmask, SFD_NONBLOCK|SFD_CLOEXEC);
if (sfd == -1)
fatal_perror("signalfd");
return sfd;
}
/* Master control. */
static bool
process_signals(int sigfd)
{
struct signalfd_siginfo ssi;
bool done = false;
for (;;) {
ssize_t n = read(sigfd, &ssi, sizeof ssi);
if (n == -1 && errno != EAGAIN)
fatal_perror("read(signalfd)");
if (n <= 0)
break;
done = true;
}
return done;
}
static bool
process_stdin(int fd, short events)
{
bool closed = false;
if (events & POLLIN) {
char scratch[4096];
ssize_t n;
do
n = read(fd, scratch, 4096);
while (n > 0);
if (n == 0)
closed = true;
if (n < 0 && errno != EAGAIN)
fatal_perror("read");
}
if (events & POLLHUP)
closed = true;
return closed;
}
static void
idle_loop(int sigfd)
{
/* We are waiting for either a signal, or stdin to be closed from
the far end. */
bool done = false;
struct pollfd pfds[2];
pfds[0].fd = sigfd;
pfds[0].events = POLLIN;
pfds[1].fd = 0;
pfds[1].events = POLLIN;
while (!done) {
if (poll(pfds, 2, -1) == -1)
fatal_perror("poll");
if (pfds[0].revents)
done |= process_signals(sigfd);
if (pfds[1].revents)
done |= process_stdin(0, pfds[1].revents);
}
}
static void
create_namespaces(const char *prefix, size_t n)
{
namespace_names = xreallocarray(0, n+1, sizeof(const char *));
nsconfdir_names = xreallocarray(0, n+1, sizeof(const char *));
memset(namespace_names, 0, (n+1) * sizeof(const char *));
memset(nsconfdir_names, 0, (n+1) * sizeof(const char *));
n_namespaces = n;
for (size_t i = 0; i < n; i++) {
const char *nsp = xasprintf("%s_ns%zd", prefix, i);
const char *nsc = xasprintf("/etc/netns/%s", nsp);
if (mkdir(nsc, 0777))
fatal_perror(nsc);
nsconfdir_names[i] = nsc;
run("ip", "netns", "add", nsp);
namespace_names[i] = nsp;
/* The loopback interface automatically exists in the namespace,
with the usual address and an appropriate routing table entry,
but it is not brought up automatically. */
run("ip", "netns", "exec", nsp,
"ip", "link", "set", "dev", "lo", "up");
puts(nsp);
fflush(stdout);
}
fclose(stdout);
}
static NORETURN
cleanup_and_exit(int status)
{
if (!is_child_process && n_namespaces > 0) {
pidvec to_kill;
memset(&to_kill, 0, sizeof(pidvec));
for (size_t i = 0; i < n_namespaces; i++) {
const char *nsp = namespace_names[i];
const char *nsc = nsconfdir_names[i];
if (nsp) {
const char *ipcmd[] = { "ip", "netns", "pids", nsp, 0 };
runv_get_output_pids(&to_kill, ipcmd);
if (to_kill.used) {
pidvec_kill(&to_kill, SIGTERM);
pidvec_clear(&to_kill);
sleep(5);
runv_get_output_pids(&to_kill, ipcmd);
pidvec_kill(&to_kill, SIGKILL);
pidvec_clear(&to_kill);
}
run_ignore_failure("ip", "netns", "exec", nsp,
"ip", "link", "set", "dev", "lo", "down");
run_ignore_failure("ip", "netns", "del", nsp);
}
if (nsc)
run_ignore_failure("rm", "-rf", nsc);
if (!nsp || !nsc)
break;
}
}
exit(status);
}
int
main(int argc, char **argv, char **envp)
{
progname = strrchr(argv[0], '/');
if (progname)
progname++;
else
progname = argv[0];
/* Line-buffer stderr so that any error messages we emit are atomically
written (all non-usage error messages are exactly one line). */
char stderr_buffer[BUFSIZ];
setvbuf(stderr, stderr_buffer, _IOLBF, BUFSIZ);
if (argc != 3)
usage("wrong number of command line arguments");
const char *prefix = argv[1];
if (strlen(prefix) != strspn(prefix,
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"_"))
usage("prefix must be only ASCII letters, digits, and underscores");
size_t nnsp = (size_t)xstrtonum_usage(argv[2], 0, 1024,
"number of namespaces");
close_unnecessary_fds();
int sigfd = prepare_signals();
prepare_child_env(envp);
create_namespaces(prefix, nnsp);
idle_loop(sigfd);
cleanup_and_exit(0);
}