X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Frpm-fake-resolver.c;h=e076d8bc25cc2286a96af1dd492b15e46062cab8;hb=3d3bef62d063caeb506a404e89fdac929b249591;hp=f24a609c9ff3c69872ce065fb7d97532fac059cc;hpb=62a7cf84a840dd6f172eeb1a25741cb436dc4e04;p=util-vserver.git diff --git a/util-vserver/src/rpm-fake-resolver.c b/util-vserver/src/rpm-fake-resolver.c index f24a609..e076d8b 100644 --- a/util-vserver/src/rpm-fake-resolver.c +++ b/util-vserver/src/rpm-fake-resolver.c @@ -56,8 +56,11 @@ struct ArgInfo { uid_t uid; gid_t gid; bool do_fork; + bool in_ctx; char const * pid_file; char const * chroot; + uint32_t caps; + int flags; }; static struct option const @@ -73,7 +76,7 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [-c ] [-u ] [-g ] [-r ] [-n]\n" + " [-c ] [-u ] [-g ] [-r ] [-s] [-n]\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -94,18 +97,21 @@ inline static void parseArgs(struct ArgInfo *args, int argc, char *argv[]) { while (1) { - int c = getopt_long(argc, argv, "c:u:g:r:n", CMDLINE_OPTIONS, 0); + int c = getopt_long(argc, argv, "F:C:c:u:g:r:ns", CMDLINE_OPTIONS, 0); if (c==-1) break; switch (c) { case 'h' : showHelp(1, argv[0], 0); case 'v' : showVersion(); - case 'c' : args->ctx = atoi(optarg); break; - case 'u' : args->uid = atoi(optarg); break; - case 'g' : args->gid = atoi(optarg); break; + case 'c' : args->ctx = atoi(optarg); break; + case 'u' : args->uid = atoi(optarg); break; + case 'g' : args->gid = atoi(optarg); break; + case 'F' : args->flags = atoi(optarg); break; + case 'C' : args->caps = atoi(optarg); break; case 'r' : args->chroot = optarg; break; case 'n' : args->do_fork = false; break; + case 's' : args->in_ctx = true; break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); @@ -232,20 +238,32 @@ daemonize(struct ArgInfo const UNUSED * args, int pid_fd) _exit(0); } Eclose(p[1]); - read(p[0], &c, 1); + TEMP_FAILURE_RETRY(read(p[0], &c, 1)); Eclose(p[0]); } static void -activateContext(xid_t xid) +activateContext(xid_t xid, bool in_ctx, + uint32_t xid_caps, int xid_flags) { - if (vc_isSupported(vcFEATURE_MIGRATE)) { -#warning TODO: activate the context here or migrate to it - abort(); + if (in_ctx) { + struct vc_ctx_flags flags = { + .flagword = 0, + .mask = VC_VXF_STATE_SETUP, + }; + + Evc_set_cflags(xid, &flags); + } + else if (vc_isSupported(vcFEATURE_MIGRATE)) + Evc_ctx_migrate(xid); + else { +#ifdef VC_ENABLE_API_COMPAT + Evc_new_s_context(xid, xid_caps, xid_flags); +#else + WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "can not change context: migrate kernel feature missing and 'compat' API disabled\n"); + exit(wrapper_exit_code); +#endif } - else - Evc_new_s_context(xid, 0, S_CTX_INFO_LOCK); - //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK); } int main(int argc, char * argv[]) @@ -256,7 +274,9 @@ int main(int argc, char * argv[]) .gid = 99, .do_fork = true, .pid_file = 0, - .chroot = 0 + .chroot = 0, + .in_ctx = false, + .flags = S_CTX_INFO_LOCK, }; int pid_fd = -1; @@ -274,7 +294,7 @@ int main(int argc, char * argv[]) if (args.chroot) Echroot(args.chroot); Echdir("/"); - activateContext(args.ctx); + activateContext(args.ctx, args.in_ctx, args.caps, args.flags); Esetgroups(0, &args.gid); Esetgid(args.gid); Esetuid(args.uid);