X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fvserver-start%2Fmain.c;h=6957f1f210a1fc5e039a9894766b30e5e32b7e24;hb=ba16d5c90f5e6bdba1f2a10b51971d378340aa30;hp=58962813bd68bd7db5d62c41ec5df8e0f3c8cd6a;hpb=e3be43e3ee2157a63ea175463629c2433f595854;p=util-vserver.git diff --git a/util-vserver/vserver-start/main.c b/util-vserver/vserver-start/main.c index 5896281..6957f1f 100644 --- a/util-vserver/vserver-start/main.c +++ b/util-vserver/vserver-start/main.c @@ -25,12 +25,27 @@ #include "pathconfig.h" #include "interface.h" #include "configuration.h" +#include "mount.h" +#include "undo.h" #include "lib_internal/util.h" #include "lib_internal/errinfo.h" +#include "lib_internal/sys_clone.h" #include "lib/vserver.h" +#include "lib/internal.h" #include +#include +#include +#include +#include + +#define ENSC_WRAPPERS_VSERVER 1 +#define ENSC_WRAPPERS_SOCKET 1 +#define ENSC_WRAPPERS_UNISTD 1 +#define ENSC_WRAPPERS_FCNTL 1 +#define ENSC_WRAPPERS_STDLIB 1 +#include struct Options opts; struct Configuration cfg; @@ -112,6 +127,17 @@ checkConstraints() Vshelper_doSanityCheck(); } +static void +setCFlag(xid_t xid, uint_least64_t value) +{ + struct vc_ctx_flags flags = { + .flagword = value, + .mask = value + }; + + Evc_set_cflags(xid, &flags); +} + int main(int argc, char *argv[]) { Cfg_init(&cfg); @@ -120,9 +146,55 @@ int main(int argc, char *argv[]) initLock(); checkConstraints(); + int sync_fd[2]; + char c; + xid_t xid; + char buf[sizeof(xid)*3 + 2]; PathInfo cfgdir = { .d = opts.VSERVER_DIR, .l = strlen(opts.VSERVER_DIR) }; + Esocketpair(AF_UNIX, SOCK_STREAM, 0, sync_fd); + Efcntl(sync_fd[0], F_SETFD, FD_CLOEXEC); + Efcntl(sync_fd[1], F_SETFD, FD_CLOEXEC); + getConfiguration(&cfg, &cfgdir); - execScriptlets(&cfgdir, opts.VSERVER_NAME, "prepre-start"); - activateInterfaces(); + pid_t pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0); + FatalErrnoError(pid==-1, "sys_clone()"); + + switch (pid) { + case 0 : + Undo_init(); + execScriptlets(&cfgdir, opts.VSERVER_NAME, "prepre-start"); + activateInterfaces(&cfg.interfaces); + + xid = Evc_ctx_create(cfg.xid); + setCFlag(xid, VC_VXF_INFO_NAMESPACE); + + mountVserver(&cfg); + // prepareInit(&cfg, &cfgdir); + + Esend(sync_fd[0], &xid, sizeof xid, MSG_NOSIGNAL); + // 'pre-start.parent' will be executed now in the parent-context + Erecv(sync_fd[0], &c, 1, 0); + execScriptlets(&cfgdir, opts.VSERVER_NAME, "pre-start"); + + if (cfg.nice) + Enice(atoi(cfg.nice)); + if (opts.OPTION_DEFAULTTTY) + setDefaultTTY(&cfgdir, 0); + + + + Undo_detach(); + break; + + default : + Erecv(sync_fd[1], &xid, sizeof xid, 0); + utilvserver_fmt_uint(buf, xid); + Esetenv("CHILD_XID", buf, 1); + + execScriptlets(&cfgdir, opts.VSERVER_NAME, "pre-start.parent"); + Esend(sync_fd[1], ".", 1, MSG_NOSIGNAL); + + break; + } }