backported vc_X_getcctx() changes from HEAD
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sat, 18 Oct 2003 01:48:29 +0000 (01:48 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sat, 18 Oct 2003 01:48:29 +0000 (01:48 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@213 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib/getctx-legacy.hc
util-vserver/lib/vserver.h

index 17928c9..a3ac1be 100644 (file)
@@ -45,11 +45,19 @@ vc_X_getctx_legacy(pid_t pid)
   size_t                       len;
   char                         *pos = 0;
 
-  strcpy(status_name, "/proc/");
-  len = utilvserver_uint2str(status_name+sizeof("/proc/")-1,
-                            sizeof(status_name)-sizeof("/proc//status")+1,
-                            pid, 10);
-  strcpy(status_name+sizeof("/proc/")+len-1, "/status");
+  if (pid<0 || (uint32_t)(pid)>99999) {
+    errno = EINVAL;
+    return 0;
+  }
+
+  if (pid==0) strcpy(status_name, "/proc/self/status");
+  else {
+    strcpy(status_name, "/proc/");
+    len = utilvserver_uint2str(status_name+sizeof("/proc/")-1,
+                              sizeof(status_name)-sizeof("/proc//status")+1,
+                              pid, 10);
+    strcpy(status_name+sizeof("/proc/")+len-1, "/status");
+  }
 
   fd = open(status_name, O_RDONLY);
   if (fd==-1) return VC_NOCTX;
index c81a2a4..e776f09 100644 (file)
@@ -52,11 +52,8 @@ extern "C" {
   int  vc_chrootsafe(char const *dir);
 
 
-    /** Returns the context of the given process. */
+    /** Returns the context of the given process. pid==0 means the current process. */
   ctx_t        vc_X_getctx(pid_t pid);
-
-    /** Returns the context of the current process. */
-#define vc_X_getcctx()         (vc_X_getctx(getpid()))
     
 #ifdef __cplusplus
 }