X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvcontext.c;h=b0923d53cb56ec85510988b9508fdb6f592a898e;hb=da00467717303bf7c7f584af0572b5df6182e3a3;hp=57a45fe06fc7e1f7b51672fa2eccbdd5f2a08134;hpb=2fbc46a92318904f1414f1aeaf256970e80e845a;p=util-vserver.git diff --git a/src/vcontext.c b/src/vcontext.c index 57a45fe..b0923d5 100644 --- a/src/vcontext.c +++ b/src/vcontext.c @@ -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" @@ -69,6 +70,7 @@ #define CMD_PERSFLAG 0x400f #define CMD_VLOGIN 0x4010 #define CMD_PIVOT_ROOT 0x4011 +#define CMD_CLOSE_FD 0x4012 #ifndef MNT_DETACH @@ -99,6 +101,7 @@ CMDLINE_OPTIONS[] = { { "personality-flags", required_argument, 0, CMD_PERSFLAG }, { "vlogin", no_argument, 0, CMD_VLOGIN }, { "pivot-root", no_argument, 0, CMD_PIVOT_ROOT }, + { "closefd", no_argument, 0, CMD_CLOSE_FD }, #if 1 { "fakeinit", no_argument, 0, CMD_INITPID }, // compatibility #endif @@ -120,6 +123,7 @@ struct Arguments { int verbosity; bool do_chroot; bool do_pivot_root; + bool do_close_fd; char const * uid; xid_t xid; char const * sync_sock; @@ -164,6 +168,7 @@ showHelp(int fd, char const *cmd, int res) " ... use as synchronization message; by\n" " default, 'ok' will be used\n" " --vlogin ... enable terminal proxy\n" + " --closefd ... close all open file descriptors >2\n" "\n" "'vcontext --create' exits with code 254 iff the context exists already.\n" "\n" @@ -263,6 +268,15 @@ doit(struct Arguments const *args, int argc, char *argv[]) doSyncStage0(p, args->do_disconnect); + if (args->do_close_fd) { + int fd; + for (fd = 3; fd < sysconf(_SC_OPEN_MAX); fd++) { + if (fd == ext_sync_fd) + continue; + close(fd); + } + } + if (args->do_create) { xid = vc_ctx_create(args->xid, NULL); if (xid==VC_NOCTX) { @@ -367,6 +381,7 @@ 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_vlogin) execvp (argv[optind],argv+optind); else @@ -420,6 +435,7 @@ int main (int argc, char *argv[]) .do_disconnect = false, .do_endsetup = false, .do_vlogin = false, + .do_close_fd = false, .is_initpid = false, .is_silentexist = false, .set_namespace = false, @@ -448,6 +464,7 @@ int main (int argc, char *argv[]) case CMD_PIVOT_ROOT : args.do_pivot_root = true; break; case CMD_NAMESPACE : args.set_namespace = true; break; case CMD_SILENTEXIST : args.is_silentexist = true; break; + case CMD_CLOSE_FD : args.do_close_fd = true; break; case CMD_SYNCSOCK : args.sync_sock = optarg; break; case CMD_SYNCMSG : args.sync_msg = optarg; break; case CMD_UID : args.uid = optarg; break;