static int unionmount(struct init_ctx *ctx, void *data, size_t len) { char *s; char buf[40]; s = snewn(len+1, char); memcpy(s, data, len); s[len] = '\0'; sprintf(buf, "/tmp/u%d", ctx->nunions); if (mkdir(buf, 0666) < 0) { char err[512]; int elen = sprintf(err, "%.40s: mkdir: %.450s", buf, strerror(errno)); protowrite(ctx->control_wfd, CMD_FAILURE, err, elen, (void *)NULL); return 0; } else if (mount("none", buf, "hostfs", MS_MGC_VAL, s) < 0) { char err[512]; int elen = sprintf(err, "%.220s: mkdir: %.220s", s, strerror(errno)); protowrite(ctx->control_wfd, CMD_FAILURE, err, elen, (void *)NULL); rmdir(buf); return 0; } else { ctx->nunions++; return 1; } }
static void control_packet(void *vctx, int type, void *data, size_t len) { struct init_ctx *ctx = (struct init_ctx *)vctx; char buf[40], *s, *p; unsigned long mflags; long id; int i, ret; switch (type) { case CMD_UNION: printf("got CMD_UNION(%.*s)\n", (int)len, (char *)data); unionmount(ctx, data, len); break; case CMD_ROOTRW: printf("got CMD_ROOTRW\n"); ctx->rootrw = 1; break; case CMD_ROOT: printf("got CMD_ROOT(%.*s)\n", (int)len, (char *)data); sprintf(buf, "/tmp/r"); if (mkdir(buf, 0666) < 0) { char err[512]; int elen = sprintf(err, "%.40s: mkdir: %.450s", buf, strerror(errno)); protowrite(ctx->control_wfd, CMD_FAILURE, err, elen, (void *)NULL); break; } ctx->root = snewn(len+1, char); memcpy(ctx->root, data, len); ctx->root[len] = '\0'; mflags = MS_MGC_VAL; if (!ctx->rootrw) mflags |= MS_RDONLY; if (ctx->nunions > 0) { char *p; const char *sep; int i; if (!unionmount(ctx, data, len)) break; s = snewn(40 * ctx->nunions + 80, char); p = s; sep = "dirs="; for (i = 0; i < ctx->nunions; i++) { p += sprintf(p, "%s/tmp/u%d=r%c", sep, i, i==0?'w':'o'); sep = ":"; } assert(p - s < 40 * ctx->nunions + 80); ret = mount("none", buf, "aufs", mflags, s); } else {
static void signalpipe_readdata(sel_rfd *rfd, void *vdata, size_t len) { struct init_ctx *ctx = (struct init_ctx *)sel_rfd_get_ctx(rfd); int status; pid_t pid; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { if (pid == ctx->child_pid && (WIFEXITED(pid) || WIFSIGNALED(pid))) { /* * The main child process has terminated. Send its * exit code. */ unsigned char intbuf[4]; WRITEINT(intbuf, status); protowrite(ctx->control_wfd, CMD_EXITCODE, intbuf, 4, (void *)NULL); ctx->got_exitcode = 1; } } }
putentries(FILE *outfile) #endif /* put out wrappers for multiple entries */ { char base[IDENT_LEN]; struct Entrypoint *e; Namep *A, *Ae, *Ae1, **Alp, *a, **a1, np; chainp args, lengths; int i, k, mt, nL, type; extern char *dfltarg[], **dfltproc; e = entries; if (!e->enamep) /* only possible with erroneous input */ return; nL = (nallargs + nallchargs) * sizeof(Namep *); A = (Namep *)ckalloc(nL + nallargs*sizeof(Namep **)); Ae = A + nallargs; Alp = (Namep **)(Ae1 = Ae + nallchargs); i = k = 0; for(a1 = Alp, args = allargs; args; a1++, args = args->nextp) { np = (Namep)args->datap; if (np->vtype == TYCHAR && np->vclass != CLPROC) *a1 = &Ae[i++]; } mt = multitype; multitype = 0; sprintf(base, "%s0_", e->enamep->cvarname); do { np = e->enamep; lengths = length_comp(e, 0); proctype = type = np->vtype; if (protofile) protowrite(protofile, type, np->cvarname, e, lengths); nice_printf(outfile, "\n%s ", c_type_decl(type, 1)); nice_printf(outfile, "%s", np->cvarname); if (!Ansi) { listargs(outfile, e, 0, lengths); nice_printf(outfile, "\n"); } list_arg_types(outfile, e, lengths, 0, "\n"); nice_printf(outfile, "{\n"); frchain(&lengths); next_tab(outfile); if (mt) nice_printf(outfile, "Multitype ret_val;\n%s(%d, &ret_val", base, k); /*)*/ else if (ISCOMPLEX(type)) nice_printf(outfile, "%s(%d,%s", base, k, xretslot[type]->user.ident); /*)*/ else if (type == TYCHAR) nice_printf(outfile, "%s(%d, ret_val, ret_val_len", base, k); /*)*/ else nice_printf(outfile, "return %s(%d", base, k); /*)*/ k++; memset((char *)A, 0, nL); for(args = e->arglist; args; args = args->nextp) { np = (Namep)args->datap; A[np->argno] = np; if (np->vtype == TYCHAR && np->vclass != CLPROC) *Alp[np->argno] = np; } args = allargs; for(a = A; a < Ae; a++, args = args->nextp) nice_printf(outfile, ", %s", (np = *a) ? np->cvarname : ((Namep)args->datap)->vclass == CLPROC ? dfltproc[((Namep)args->datap)->vtype] : dfltarg[((Namep)args->datap)->vtype]); for(; a < Ae1; a++) if (np = *a) nice_printf(outfile, ", %s_len", np->fvarname); else nice_printf(outfile, ", (ftnint)0"); nice_printf(outfile, /*(*/ ");\n"); if (mt) { if (type == TYCOMPLEX) nice_printf(outfile, "r_v->r = ret_val.c.r; r_v->i = ret_val.c.i;\n"); else if (type == TYDCOMPLEX) nice_printf(outfile, "r_v->r = ret_val.z.r; r_v->i = ret_val.z.i;\n"); else if (type <= TYLOGICAL) nice_printf(outfile, "return ret_val.%s;\n", postfix[type-TYINT1]); } nice_printf(outfile, "}\n"); prev_tab(outfile); } while(e = e->entnextp); free((char *)A); }