From eb94e28e0e8649d72f95f8de7e787babe9c514bd Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sat, 18 Oct 2003 01:48:29 +0000 Subject: [PATCH] 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 --- util-vserver/lib/getctx-legacy.hc | 18 +++++++++++++----- util-vserver/lib/vserver.h | 5 +---- 2 files changed, 14 insertions(+), 9 deletions(-) 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 } -- 1.8.1.5