From: Enrico Scholz Date: Sat, 18 Oct 2003 01:48:29 +0000 (+0000) Subject: backported vc_X_getcctx() changes from HEAD X-Git-Tag: version_0_23_96~29 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb94e28e0e8649d72f95f8de7e787babe9c514bd;p=util-vserver.git backported vc_X_getcctx() changes from HEAD git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@213 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib/getctx-legacy.hc b/util-vserver/lib/getctx-legacy.hc index 17928c9..a3ac1be 100644 --- a/util-vserver/lib/getctx-legacy.hc +++ b/util-vserver/lib/getctx-legacy.hc @@ -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; diff --git a/util-vserver/lib/vserver.h b/util-vserver/lib/vserver.h index c81a2a4..e776f09 100644 --- a/util-vserver/lib/vserver.h +++ b/util-vserver/lib/vserver.h @@ -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 }