- struct vc_rlimit limits;
- struct vc_ctx_caps caps;
- struct vc_ctx_flags flags;
- int ctx;
- int cpu = VC_LIM_KEEP;
- int mem = VC_LIM_KEEP;
- int task = VC_LIM_KEEP;
- get_limits(context,&cpu, &mem, &task);
- (void) (sandbox_chroot(xid));
-
- caps.ccaps = ~vc_get_insecureccaps();
- caps.cmask = ~0ull;
- caps.bcaps = ~vc_get_insecurebcaps();
- caps.bmask = ~0ull;
-
- flags.flagword = VC_VXF_INFO_LOCK;
- flags.mask = VC_VXF_STATE_SETUP | VC_VXF_INFO_LOCK;
-
- ctx = vc_ctx_create(xid);
- if (ctx == VC_NOCTX && errno != EEXIST) {
- PERROR("vc_ctx_create(%d)", xid);
- exit(1);
- }
-
- /* (re)set the various limits on the (possibly new) context */
-
- /* CPU */
- /* not yet */
-
- /* MEM */
- limits.min = VC_LIM_KEEP;
- limits.soft = VC_LIM_KEEP;
- limits.hard = mem;
- if (vc_set_rlimit(xid, RLIMIT_RSS, &limits)) {
- PERROR("vc_set_rlimit(%d, %d, %d/%d/%d)",
- xid, RLIMIT_RSS, limits.min, limits.soft, limits.hard);
- exit(1);
- }
-
- /* TASK */
- limits.min = VC_LIM_KEEP;
- limits.soft = VC_LIM_KEEP;
- limits.hard = task;
- if (vc_set_rlimit(xid, RLIMIT_NPROC, &limits)) {
- PERROR("vc_set_rlimit(%d, %d, %d/%d/%d)",
- xid, RLIMIT_NPROC, limits.min, limits.soft, limits.hard);
- exit(1);
- }
-
- if (vc_set_ccaps(xid, &caps) == -1) {
- PERROR("vc_set_ccaps(%d, 0x%16ullx/0x%16ullx, 0x%16ullx/0x%16ullx)",
- xid, caps.ccaps, caps.cmask, caps.bcaps, caps.bmask);
- exit(1);
- }
-
- if (vc_set_cflags(xid, &flags) == -1) {
- PERROR("vc_set_cflags(%d, 0x%16llx/0x%16llx)",
- xid, flags.flagword, flags.mask);
- exit(1);
- }
-
- /* context already exists, migrate to it */
- if (ctx == VC_NOCTX && vc_ctx_migrate(xid) == -1) {
- PERROR("vc_ctx_migrate(%d)", xid);
- exit(1);
- }
+ int ctx_is_new;
+ struct sliver_resources slr;
+ char hostname[HOST_NAME_MAX+1];
+ pl_get_limits(context,&slr);
+
+ if (gethostname(hostname, sizeof hostname) == -1)
+ {
+ PERROR("gethostname(...)");
+ exit(1);
+ }
+
+ /* check whether the slice has been suspended */
+ if (slr.vs_cpu==0)
+ {
+ fprintf(stderr, "*** %s: %s has zero cpu resources and presumably it has been disabled/suspended ***\n", hostname, context);
+ exit(0);
+ }
+
+ (void) (sandbox_chroot(pwd));
+
+ if ((ctx_is_new = pl_chcontext(ctx, ~vc_get_insecurebcaps(),&slr)) < 0)
+ {
+ PERROR("pl_chcontext(%u)", ctx);
+ exit(1);
+ }
+ if (ctx_is_new)
+ {
+ fprintf(stderr, " *** %s: %s has not been started yet, please check back later ***\n", hostname, context);
+ exit(1);
+ }