1 #include <sys/syscall.h>
8 #define CLONE_NEWNET 0x40000000 /* New network namespace (lo, device, names sockets, etc) */
11 #define __NR_set_space 327
14 int set_space(int pid, int id, int toggle, unsigned long unshare_flags) {
15 return syscall(__NR_set_space, pid, id, toggle, unshare_flags);
18 int get_slice_xid(char *slice_name) {
19 char slicepath[PATHLEN];
22 snprintf(slicepath, sizeof(slicepath), "/etc/vservers/%s/context");
24 if ((fp = fopen(slicepath, "r")) == NULL) {
25 printf("Could not open %s\n", slicepath);
29 if (fscanf(fp, "%d", &xid)==0) {
30 printf("Could not read ctx file\n");
38 int verify_ownership(int pid, int arg_xid) {
39 char procpath[PATHLEN];
42 snprintf(procpath, sizeof(procpath), "/proc/%d/vinfo");
44 if ((fp = fopen(procpath, "r")) == NULL) {
45 printf("Could not open %s\n", procpath);
49 if (fscanf(fp, "XID: %d", &xid)==0) {
50 printf("Could not read ctx file\n");
55 return (arg_xid==xid);
59 int main(int argc, char *argv[]) {
64 printf("Slice name missing. Was I invoked by vsys?\n");
70 if ((xid = get_slice_xid(argv[1]))==-1) {
71 printf("Could not get xid for slice %s\n",argv[1]);
75 if (!verify_ownership(pid, xid)) {
76 printf("Does xid %d really own %d?\n",xid,pid);
80 set_space(pid, xid, 0, CLONE_NEWNET);