merge trellis branch to trunk.
[util-vserver-pl.git] / src / netns.c
index 8f0c598..cf91eff 100644 (file)
 #define     SPACE_FILE      "/spaces/net"
 #define     VSERVERCONF     "/etc/vservers/"
 
-uint32_t
-get_space_flag(xid_t xid) {
+int
+pl_unshare_netns(xid_t xid) {
     char *ctx_space_file, *space_name;
     struct passwd *slice_user;
-    uint32_t space_flag = 0;
+    int res = 0;
+    char buf[100];
+    FILE *fb;
 
     slice_user = getpwuid(xid);
 
     if (!slice_user)
-        return 0;
+      return 0;
 
     ctx_space_file=(char *) malloc(sizeof(VSERVERCONF SPACE_FILE "Z")+strlen(slice_user->pw_name));
     if (!ctx_space_file)
-        return 0;
+      return 0;
 
     sprintf(ctx_space_file,VSERVERCONF "%s" SPACE_FILE, slice_user->pw_name);
 
-    if (access(ctx_space_file, F_OK)==0)
-        space_flag |= CLONE_NEWNET;
+    if ((fb = fopen(ctx_space_file, "r")) == NULL)
+      return 0;
 
+    if (fgets(buf, sizeof(buf), fb) != NULL) {
+      res = atoi(buf);
+    }
+
+    fclose(fb);
     free(ctx_space_file);
-    return space_flag;
+    return res;
 }