initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 14 Oct 2003 15:19:14 +0000 (15:19 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Tue, 14 Oct 2003 15:19:14 +0000 (15:19 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@141 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib/checkversion.c [new file with mode: 0644]
util-vserver/lib/getctx-compat.hc [new file with mode: 0644]
util-vserver/lib/getctx-legacy.hc [new file with mode: 0644]
util-vserver/lib/getctx.c
util-vserver/lib/getversion-internal.hc [new file with mode: 0644]
util-vserver/lib/getversion.c [new file with mode: 0644]
util-vserver/lib/safechroot-internal.hc [new file with mode: 0644]
util-vserver/lib/uint2str.c [new file with mode: 0644]

diff --git a/util-vserver/lib/checkversion.c b/util-vserver/lib/checkversion.c
new file mode 100644 (file)
index 0000000..f2ff63f
--- /dev/null
@@ -0,0 +1,43 @@
+// $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;
+}
diff --git a/util-vserver/lib/getctx-compat.hc b/util-vserver/lib/getctx-compat.hc
new file mode 100644 (file)
index 0000000..96de609
--- /dev/null
@@ -0,0 +1,30 @@
+// $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
diff --git a/util-vserver/lib/getctx-legacy.hc b/util-vserver/lib/getctx-legacy.hc
new file mode 100644 (file)
index 0000000..17928c9
--- /dev/null
@@ -0,0 +1,73 @@
+// $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
index 211ca41..20b687c 100644 (file)
 #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
diff --git a/util-vserver/lib/getversion-internal.hc b/util-vserver/lib/getversion-internal.hc
new file mode 100644 (file)
index 0000000..a4a14d0
--- /dev/null
@@ -0,0 +1,36 @@
+// $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
diff --git a/util-vserver/lib/getversion.c b/util-vserver/lib/getversion.c
new file mode 100644 (file)
index 0000000..94e4168
--- /dev/null
@@ -0,0 +1,30 @@
+// $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);
+}
diff --git a/util-vserver/lib/safechroot-internal.hc b/util-vserver/lib/safechroot-internal.hc
new file mode 100644 (file)
index 0000000..0539889
--- /dev/null
@@ -0,0 +1,48 @@
+// $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
diff --git a/util-vserver/lib/uint2str.c b/util-vserver/lib/uint2str.c
new file mode 100644 (file)
index 0000000..2ba5bf1
--- /dev/null
@@ -0,0 +1,54 @@
+// $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;
+}