Revision b85943dc
mnexec.c | ||
---|---|---|
29 | 29 |
#define VERSION "(devel)" |
30 | 30 |
#endif |
31 | 31 |
|
32 |
void usage(char *name)
|
|
32 |
void usage(char *name) |
|
33 | 33 |
{ |
34 | 34 |
printf("Execution utility for Mininet\n\n" |
35 | 35 |
"Usage: %s [-cdnp] [-a pid] [-g group] [-r rtprio] cmd args...\n\n" |
... | ... | |
99 | 99 |
char path[PATH_MAX]; |
100 | 100 |
int nsid; |
101 | 101 |
int pid; |
102 |
|
|
102 | 103 |
static struct sched_param sp; |
103 | 104 |
while ((c = getopt(argc, argv, "+cdnpa:g:r:vh")) != -1) |
104 | 105 |
switch(c) { |
... | ... | |
156 | 157 |
sprintf(path, "/proc/%d/ns/mnt", pid); |
157 | 158 |
nsid = open(path, O_RDONLY); |
158 | 159 |
if (nsid < 0 || setns(nsid, 0) != 0) { |
159 |
/* Plan B: chroot into pid's root file system */ |
|
160 |
char *cwd = get_current_dir_name(); |
|
161 |
/* Plan B: chroot/chdir into pid's root file system */ |
|
160 | 162 |
sprintf(path, "/proc/%d/root", pid); |
161 | 163 |
if (chroot(path) < 0) { |
162 | 164 |
perror(path); |
163 | 165 |
return 1; |
164 | 166 |
} |
167 |
/* need to chdir to correct working directory */ |
|
168 |
if (chdir(cwd) != 0) { |
|
169 |
perror(cwd); |
|
170 |
return 1; |
|
171 |
} |
|
165 | 172 |
} |
166 | 173 |
break; |
167 | 174 |
case 'g': |
... | ... | |
184 | 191 |
exit(0); |
185 | 192 |
default: |
186 | 193 |
usage(argv[0]); |
187 |
exit(1);
|
|
194 |
exit(1); |
|
188 | 195 |
} |
189 | 196 |
|
190 | 197 |
if (optind < argc) { |
... | ... | |
192 | 199 |
perror(argv[optind]); |
193 | 200 |
return 1; |
194 | 201 |
} |
195 |
|
|
202 |
|
|
196 | 203 |
usage(argv[0]); |
197 | 204 |
|
198 | 205 |
return 0; |
Also available in: Unified diff