# include <config.h>
#endif
-#include "vserver.h"
-#include "internal.h"
-#include <string.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#define CTX_TAG "\ns_context: "
-
-ctx_t
-getctx(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;
- 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 CTX_NOCTX;
+#ifdef VC_ENABLE_API_COMPAT
+# include "getctx-compat.hc"
+#endif
- len = read(fd, buf, cur_bufsize);
- close(fd);
+#ifdef VC_ENABLE_API_LEGACY
+# include "getctx-legacy.hc"
+#endif
- if (len<cur_bufsize)
- pos = strstr(buf, CTX_TAG);
- else if (len!=(size_t)-1) {
- bufsize = cur_bufsize * 2 - 1;
- errno = EAGAIN;
- }
+#include "vserver.h"
+#include "vserver-internal.h"
+#include "internal.h"
- if (pos!=0) return atoi(pos+sizeof(CTX_TAG)-1);
- else return CTX_NOCTX;
-}
+#include <sys/types.h>
-#if 0
ctx_t
-getcctx()
+vc_X_getctx(pid_t pid)
{
- return getctx(getpid());
+ CALL_VC(CALL_VC_COMPAT(vc_X_getctx, pid),
+ CALL_VC_LEGACY(vc_X_getctx, pid));
}
-#endif