X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvcontext.c;h=1e23637cf4814cfdcf457b3df460299042ad356b;hb=148ab3024621f97b9cf95091657db2448098bc66;hp=140062cc4c0080933849b3f33f044af2a41daf17;hpb=569b1bfe1e5954fa083532dc37d2fe7418ec2d4a;p=util-vserver.git diff --git a/src/vcontext.c b/src/vcontext.c index 140062c..1e23637 100644 --- a/src/vcontext.c +++ b/src/vcontext.c @@ -1,16 +1,16 @@ // $Id$ --*- c -*-- // Copyright (C) 2004-2006 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. @@ -21,6 +21,7 @@ #endif #include "util.h" +#include "compat-pivot_root.h" #include "lib/internal.h" #include "lib_internal/jail.h" #include "lib_internal/sys_personality.h" @@ -71,6 +72,11 @@ #define CMD_PIVOT_ROOT 0x4011 +#ifndef MNT_DETACH +#define MNT_DETACH 0x0002 +#endif + + struct option const CMDLINE_OPTIONS[] = { { "help", no_argument, 0, CMD_HELP }, @@ -94,9 +100,9 @@ CMDLINE_OPTIONS[] = { { "personality-flags", required_argument, 0, CMD_PERSFLAG }, { "vlogin", no_argument, 0, CMD_VLOGIN }, { "pivot-root", no_argument, 0, CMD_PIVOT_ROOT }, -#if 1 +#if 1 { "fakeinit", no_argument, 0, CMD_INITPID }, // compatibility -#endif +#endif { 0,0,0,0 }, }; @@ -200,7 +206,7 @@ connectExternalSync(char const *filename) { int fd; struct sockaddr_un addr; - + if (filename==0) return -1; ENSC_INIT_UNIX_SOCK(addr, filename); @@ -232,7 +238,7 @@ static void doExternalSync(int fd, char const *msg) { char c; - + if (fd==-1) return; if (msg) EsendAll(fd, msg, strlen(msg)); @@ -251,13 +257,13 @@ doit(struct Arguments const *args, int argc, char *argv[]) { int p[2][2]; pid_t pid = initSync(p, args->do_disconnect); - + if (pid==0) { xid_t xid; int ext_sync_fd = connectExternalSync(args->sync_sock); - doSyncStage0(p, args->do_disconnect); - + doSyncStage0(p, args->do_disconnect); + if (args->do_create) { xid = vc_ctx_create(args->xid, NULL); if (xid==VC_NOCTX) { @@ -362,6 +368,10 @@ doit(struct Arguments const *args, int argc, char *argv[]) doExternalSync(ext_sync_fd, args->sync_msg); doSyncStage1(p, args->do_disconnect); DPRINTF("doit: pid=%u, ppid=%u\n", getpid(), getppid()); + + if (args->do_migrateself) + setsid(); + if (!args->do_vlogin) execvp (argv[optind],argv+optind); else @@ -373,7 +383,7 @@ doit(struct Arguments const *args, int argc, char *argv[]) } assert(args->do_disconnect); - + waitOnSync(pid, p, args->xid!=VC_DYNAMIC_XID && args->do_migrate); return EXIT_SUCCESS; } @@ -425,11 +435,11 @@ int main (int argc, char *argv[]) .personality_flags = 0, .sync_msg = "ok", }; - + while (1) { int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); if (c==-1) break; - + switch (c) { case CMD_HELP : showHelp(1, argv[0], 0); case CMD_VERSION : showVersion(); @@ -469,10 +479,10 @@ int main (int argc, char *argv[]) } signal(SIGCHLD, SIG_DFL); - + if (args.do_migrateself) args.xid = Evc_get_task_xid(0); - + if (!args.do_create && !args.do_migrate) WRITE_MSG(2, "Neither '--create' nor '--migrate' specified; try '--help' for more information\n"); else if (args.do_create && args.do_migrate)