--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "vserver.h"
+#include "getversion-internal.hc"
+
+int
+utilvserver_checkCompatVersion()
+{
+ static int res=0;
+ static int v_errno;
+
+ if (res==0) {
+ res = vc_get_version_internal(VC_CAT_COMPAT);
+ v_errno = errno;
+#ifdef VC_ENABLE_API_LEGACY
+ if (res==-1 && errno==ENOSYS) res=0;
+#endif
+ }
+
+ errno = v_errno;
+ return res;
+}
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef H_UTIL_VSERVER_LIB_GETCTX_COMPAT_H
+#define H_UTIL_VSERVER_LIB_GETCTX_COMPAT_H
+
+#include "getctx-legacy.hc"
+
+static inline ALWAYSINLINE ctx_t
+vc_X_getctx_compat(pid_t pid)
+{
+ return vc_X_getctx_legacy(pid);
+}
+
+#endif // H_UTIL_VSERVER_LIB_GETCTX_COMPAT_H
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H
+#define H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "vserver.h"
+#include "vserver-internal.h"
+#include <string.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define CTX_TAG "\ns_context: "
+
+static ctx_t
+vc_X_getctx_legacy(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 VC_NOCTX;
+
+ len = read(fd, buf, cur_bufsize);
+ close(fd);
+
+ if (len<cur_bufsize) {
+ buf[len] = '\0';
+ pos = strstr(buf, CTX_TAG);
+ }
+ else if (len!=(size_t)-1) {
+ bufsize = cur_bufsize * 2 - 1;
+ errno = EAGAIN;
+ }
+
+ if (pos!=0) return atoi(pos+sizeof(CTX_TAG)-1);
+ else return VC_NOCTX;
+}
+
+#endif // H_UTIL_VSERVER_LIB_GETCTX_LEGACY_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-
#include "compat.h"
#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");
+#include "vserver-internal.h"
- 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 <sys/types.h>
- if (pos!=0) return atoi(pos+sizeof(CTX_TAG)-1);
- else return CTX_NOCTX;
-}
-
-#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
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef H_UTIL_VSERVER_LIB_GETVERSION_INTERNAL_H
+#define H_UTIL_VSERVER_LIB_GETVERSION_INTERNAL_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "vserver-internal.h"
+#include "linuxvirtual.h"
+
+static inline ALWAYSINLINE int
+vc_get_version_internal(int cat)
+{
+ return sys_virtual_context(VC_CMD(VERSION, 0, 0), cat, 0);
+}
+
+#endif // H_UTIL_VSERVER_LIB_GETVERSION_INTERNAL_H
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include "getversion-internal.hc"
+
+int
+vc_get_version(int cat)
+{
+ return vc_get_version(cat);
+}
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef H_UTIL_VSERVER_LIB_SAFECHROOT_INTERNAL_H
+#define H_UTIL_VSERVER_LIB_SAFECHROOT_INTERNAL_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifndef NDEBUG
+static void
+vc_tell_unsafe_chroot()
+{
+ static int flag = -1;
+ if (flag==-1) {
+ char const * const e = getenv("VC_TELL_UNSAFE_CHROOT");
+ flag = e ? atoi(e) : 0;
+ flag = flag ? 1 : 0;
+ }
+
+ if (flag) write(2, "Unsafe chroot() used\n", 23);
+}
+#else
+static ALWAYSINLINE UNUSED void vc_tell_unsafe_chroot() {}
+#endif
+
+
+#endif // H_UTIL_VSERVER_LIB_SAFECHROOT_INTERNAL_H
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "compat.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <string.h>
+
+size_t
+utilvserver_uint2str(char *buf, size_t len, unsigned int val, unsigned char base)
+{
+ char *ptr = buf+len-1;
+ register size_t res;
+ if (base>=36 || len==0) return 0;
+
+ *ptr = '\0';
+ while (ptr>buf) {
+ unsigned char digit = val%base;
+
+ --ptr;
+ *ptr = (digit<10 ? '0'+digit :
+ digit<36 ? 'a'+digit-10 :
+ (assert(false),'?'));
+
+ val /= base;
+ if (val==0) break;
+ }
+
+ assert(ptr>=buf && ptr<=buf+len-1);
+
+ res = buf+len-ptr;
+ memmove(buf, ptr, res);
+
+ return res-1;
+}