From 6257723d783bca44a01333ce2d5cc85036b4fb85 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 20 Feb 2004 20:27:03 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@983 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/enter-namespace.c | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 util-vserver/src/enter-namespace.c diff --git a/util-vserver/src/enter-namespace.c b/util-vserver/src/enter-namespace.c new file mode 100644 index 0000000..d672a4b --- /dev/null +++ b/util-vserver/src/enter-namespace.c @@ -0,0 +1,78 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 +#endif + +#include "util.h" +#include + +#include +#include +#include + +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, + " \n" + "\n" + "Enters namespace of context and executes 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); +} -- 1.8.1.5