initial checkin
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 20 Feb 2004 20:27:03 +0000 (20:27 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Fri, 20 Feb 2004 20:27:03 +0000 (20:27 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@983 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/src/enter-namespace.c [new file with mode: 0644]

diff --git a/util-vserver/src/enter-namespace.c b/util-vserver/src/enter-namespace.c
new file mode 100644 (file)
index 0000000..d672a4b
--- /dev/null
@@ -0,0 +1,78 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 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 "util.h"
+#include <vserver.h>
+
+#include <libgen.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static void
+showHelp(int fd, char const *cmd, int exit_code)
+{
+  VSERVER_DECLARE_CMD(cmd);
+  
+  WRITE_MSG(fd,        "Usage:  ");
+  WRITE_STR(fd, cmd);
+  WRITE_MSG(fd,
+           " <xid> <cmd> <args*>\n"
+           "\n"
+           "Enters namespace of context <xid> and executes <cmd> there.\n"
+           "\n"
+           "Report bugs to " PACKAGE_BUGREPORT "\n");
+
+  exit(exit_code);
+}
+
+static void
+showVersion()
+{
+  WRITE_MSG(1,
+           "enter-namespace " VERSION " -- enters namespaces and executes programs there\n"
+           "This program is part of " PACKAGE_STRING "\n"
+           "Copyright (C) 2003 Enrico Scholz\n"
+           VERSION_COPYRIGHT_DISCLAIMER);
+  exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+  if (argc==1) showHelp(2, argv[0], 255);
+  if (!strcmp(argv[1], "--help"))    showHelp(1, argv[0], 0);
+  if (!strcmp(argv[1], "--version")) showVersion();
+  if (!strcmp(argv[1], "--"))        { ++argv; --argc; }
+
+  if (argc<2) {
+    WRITE_MSG(2, "No context and/or command specified; try '--help' for more information\n");
+    exit(255);
+  }
+
+  if (vc_enter_namespace(atoi(argv[1]))==-1) {
+    perror("enter-namespace: vc_enter_namespace()");
+    exit(255);
+  }
+
+  execvp(argv[2], argv+2);
+  perror("enter-namespace: execvp()");
+  exit(255);
+}