From: Enrico Scholz Date: Thu, 16 Oct 2003 13:59:28 +0000 (+0000) Subject: use new utilvserver_getProcEntry() function X-Git-Tag: VERSION_0_10~1238 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ccd630515a13e0b3cee577831e306c094189681;p=util-vserver.git use new utilvserver_getProcEntry() function recall vc_X_getctx_legacy() automatically when buffersize was too small git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@172 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib/getctx-legacy.hc b/util-vserver/lib/getctx-legacy.hc index 8551c8a..0f18bab 100644 --- a/util-vserver/lib/getctx-legacy.hc +++ b/util-vserver/lib/getctx-legacy.hc @@ -25,52 +25,34 @@ #include "compat.h" #include "vserver.h" -#include "vserver-internal.h" -#include "internal.h" +#include "utils-legacy.h" -#include -#include -#include #include -#include - -#define CTX_TAG "\ns_context: " +#include static ctx_t -vc_X_getctx_legacy(pid_t pid) +vc_X_getctx_legacy_internal(pid_t pid) { - static volatile size_t bufsize=4097; - // TODO: is this really race-free? - size_t cur_bufsize = bufsize; - int fd; - char status_name[ sizeof("/proc/01234/status") ]; - char buf[cur_bufsize]; - size_t len; + size_t bufsize = utilvserver_getProcEntryBufsize(); + char buf[bufsize]; 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"); - - fd = open(status_name, O_RDONLY); - if (fd==-1) return VC_NOCTX; + pos = utilvserver_getProcEntry(pid, "\ns_context: ", buf, bufsize); - len = read(fd, buf, cur_bufsize); - close(fd); + if (pos!=0) return atoi(pos); + else return VC_NOCTX; +} - if (len