#include "lib/internal.h"
#include "lib_internal/jail.h"
-#include "linuxcaps.h"
-
#include <vserver.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <assert.h>
+#include <signal.h>
#define ENSC_WRAPPERS_PREFIX "vcontext: "
#define ENSC_WRAPPERS_UNISTD 1
#define CMD_XID 0x4000
#define CMD_CREATE 0x4001
#define CMD_MIGRATE 0x4003
-#define CMD_FAKEINIT 0x4002
+#define CMD_INITPID 0x4002
#define CMD_DISCONNECT 0x4004
#define CMD_UID 0x4005
#define CMD_CHROOT 0x4006
#define CMD_MIGRATESELF 0x400a
#define CMD_ENDSETUP 0x400b
#define CMD_SILENTEXIST 0x400c
+#define CMD_NAMESPACE 0x400d
+
struct option const
CMDLINE_OPTIONS[] = {
{ "create", no_argument, 0, CMD_CREATE },
{ "migrate", no_argument, 0, CMD_MIGRATE },
{ "migrate-self", no_argument, 0, CMD_MIGRATESELF },
- { "fakeinit", no_argument, 0, CMD_FAKEINIT },
+ { "initpid", no_argument, 0, CMD_INITPID },
{ "endsetup", no_argument, 0, CMD_ENDSETUP },
{ "disconnect", no_argument, 0, CMD_DISCONNECT },
{ "silent", no_argument, 0, CMD_SILENT },
{ "silentexist", no_argument, 0, CMD_SILENTEXIST },
{ "uid", required_argument, 0, CMD_UID },
{ "chroot", no_argument, 0, CMD_CHROOT },
+ { "namespace", no_argument, 0, CMD_NAMESPACE },
{ "syncsock", required_argument, 0, CMD_SYNCSOCK },
{ "syncmsg", required_argument, 0, CMD_SYNCMSG },
+#if 1
+ { "fakeinit", no_argument, 0, CMD_INITPID }, // compatibility
+#endif
{ 0,0,0,0 },
};
bool do_migrateself;
bool do_disconnect;
bool do_endsetup;
- bool is_fakeinit;
+ bool is_initpid;
bool is_silentexist;
+ bool set_namespace;
int verbosity;
bool do_chroot;
uid_t uid;
"\n"
"<opts> can be:\n"
" --chroot ... chroot into current directory\n"
+ " --namespace ... execute namespace management operations\n"
" --uid <uid> ... change uid\n"
- " --fakeinit ... set current process as general process reaper\n"
+ " --initpid ... set current process as general process reaper\n"
" for ctx (possible for --migrate only)\n"
" --endsetup ... clear the setup flag; usefully for migrate only\n"
" --disconnect ... start program in background\n"
{
struct vc_ctx_flags flags = { 0,0 };
- if (args->is_fakeinit)
- flags.mask |= VC_VXF_STATE_INIT;
+ if (args->is_initpid)
+ flags.mask |= VC_VXF_STATE_INIT;
if (args->do_endsetup)
- flags.mask |= VC_VXF_STATE_SETUP;
+ flags.mask |= VC_VXF_STATE_SETUP;
- if (flags.mask!=0)
- Evc_set_flags(xid, &flags);
+ if (flags.mask!=0) {
+ DPRINTF("set_flags: mask=%08llx, flag=%08llx\n", flags.mask, flags.flagword);
+ Evc_set_cflags(xid, &flags);
+ }
}
static void
doSyncStage0(p, args->do_disconnect);
if (args->do_create) {
- xid = vc_create_context(args->xid);
+ xid = vc_ctx_create(args->xid);
if (xid==VC_NOCTX) {
switch (errno) {
case EEXIST :
else
xid = args->xid;
- if (args->do_chroot)
+ if (args->do_chroot) {
Echroot(".");
+ if (args->set_namespace) {
+ if (args->do_migrateself) Evc_set_namespace();
+ else if (args->do_migrate) Evc_enter_namespace(xid);
+ }
+ }
setFlags(args, xid);
if (args->do_migrate && !args->do_migrateself)
- Evc_migrate_context(xid);
+ Evc_ctx_migrate(xid);
if (args->uid!=(uid_t)(-1) && getuid()!=args->uid) {
Esetuid(args->uid);
doExternalSync(ext_sync_fd, args->sync_msg);
doSyncStage1(p, args->do_disconnect);
+ DPRINTF("doit: pid=%u, ppid=%u\n", getpid(), getppid());
execvp (argv[optind],argv+optind);
doSyncStage2(p, args->do_disconnect);
.do_migrateself = false,
.do_disconnect = false,
.do_endsetup = false,
- .is_fakeinit = false,
+ .is_initpid = false,
.is_silentexist = false,
+ .set_namespace = false,
.verbosity = 1,
.uid = -1,
.xid = VC_DYNAMIC_XID,
case CMD_MIGRATE : args.do_migrate = true; break;
case CMD_DISCONNECT : args.do_disconnect = true; break;
case CMD_ENDSETUP : args.do_endsetup = true; break;
- case CMD_FAKEINIT : args.is_fakeinit = true; break;
+ case CMD_INITPID : args.is_initpid = true; break;
case CMD_CHROOT : args.do_chroot = true; break;
+ case CMD_NAMESPACE : args.set_namespace = true; break;
case CMD_SILENTEXIST : args.is_silentexist = true; break;
case CMD_SYNCSOCK : args.sync_sock = optarg; break;
case CMD_SYNCMSG : args.sync_msg = optarg; break;
}
}
+ signal(SIGCHLD, SIG_DFL);
+
if (args.do_migrateself)
args.xid = Evc_get_task_xid(0);
WRITE_MSG(2, "Neither '--create' nor '--migrate specified; try '--help' for more information\n");
else if (args.do_create && args.do_migrate)
WRITE_MSG(2, "Can not specify '--create' and '--migrate' at the same time; try '--help' for more information\n");
- else if (!args.do_migrate && args.is_fakeinit)
- WRITE_MSG(2, "'--fakeinit' is possible in combination with '--migrate' only\n");
+ else if (!args.do_migrate && args.is_initpid)
+ WRITE_MSG(2, "'--initpid' is possible in combination with '--migrate' only\n");
else if (!args.do_create && args.xid==VC_DYNAMIC_XID)
WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "Can not migrate to an unknown context\n");
else if (optind>=argc)