2 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * LATCHESAR IONKOV AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
28 #include <sys/mount.h>
29 #include <sys/types.h>
34 #include <linux/unistd.h>
43 static char mntpt
[256];
52 snprintf(opts
, sizeof(opts
), "name=%s,port=%d,debug=1", uname
, port
);
53 n
= mount(host
, mntpt
, "9P", 0, opts
);
59 snprintf(mdir
, sizeof(mdir
), "%s/dev", mntpt
);
60 n
= mount("/dev", mdir
, NULL
, MS_BIND
, NULL
);
66 snprintf(mdir
, sizeof(mdir
), "%s/proc", mntpt
);
67 n
= mount("/proc", mdir
, NULL
, MS_BIND
, NULL
);
73 snprintf(mdir
, sizeof(mdir
), "%s/sys", mntpt
);
74 n
= mount("/sys", mdir
, NULL
, MS_BIND
, NULL
);
82 n
= mount(mntpt
, "/", NULL
, MS_MOVE
, NULL
);
91 snprintf(mdir
, sizeof(mdir
), "execv %s", cmd
);
99 fprintf(stderr
, "cpud uname host port\n");
104 main(int argc
, char **argv
)
116 port
= strtol(argv
[3], &s
, 10);
125 args
= calloc(nargs
, sizeof(char *));
128 for(i
= 4; i
< argc
; i
++)
137 snprintf(mntpt
, sizeof(mntpt
), "/tmp/cpu%d", getpid());
139 pid
= clone(procfn
, stk
+ 5000, CLONE_NEWNS
| CLONE_FILES
140 | CLONE_PTRACE
| SIGCHLD
, NULL
);
142 if ((int) pid
== -1) {
147 p
= waitpid(pid
, NULL
, 0);