Date: Thu, 5 Sep 2013 11:15:58 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256942 - soc2013/dpl/head/lib/libzcap Message-ID: <201309051115.r85BFwRw013331@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Thu Sep 5 11:15:58 2013 New Revision: 256942 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256942 Log: Made capsicum files fully compilable. Also, all the interface with sys/queue.h has been cleared up. Modified: soc2013/dpl/head/lib/libzcap/capsicum.c soc2013/dpl/head/lib/libzcap/capsicum.h Modified: soc2013/dpl/head/lib/libzcap/capsicum.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.c Thu Sep 5 10:24:09 2013 (r256941) +++ soc2013/dpl/head/lib/libzcap/capsicum.c Thu Sep 5 11:15:58 2013 (r256942) @@ -15,11 +15,15 @@ #include <stdio.h> #include <err.h> +/* + * The only function allocating space + * for struct sandbox is startChild(). + */ struct sandbox; struct slisthead sandboxes; struct sandbox * startSandbox(void *data); -int stopSandbox(struct sandbox *sandbox); +void stopSandbox(struct sandbox *sandbox); void startNullSandbox(void); struct sandbox * findSandbox(void *ptr); struct sandbox *startChild(void *data); @@ -45,7 +49,7 @@ /* Create and add the real sandbox */ newsandbox = startChild(data); - SLIST_INSERT_HEAD(&sandboxes, newsandbox, entries); + SLIST_INSERT_HEAD(&sandboxes, newsandbox, next); return (newsandbox); } @@ -55,34 +59,33 @@ * struct sandbox. Should be called by: gzclose, * deflateEnd, inflateEnd (inflateBackEnd). */ -int -stopSandbox(struct sandbox *sandbox) +void +stopSandbox(struct sandbox *sandboxToStop) { int pid; - if (pdgetpid(sandbox->pd, &pid) < 0) + if (pdgetpid(sandboxToStop->pd, &pid) < 0) err(1, "Couldn't get child PID"); if (kill(SIGKILL, pid) < 0) err(1, "Couldn't kill child"); - SLIST_REMOVE(&sandboxes, sandbox, entry, entries); - free(sandbox); + SLIST_REMOVE(&sandboxes, sandboxToStop, sandbox, next); + free(sandboxToStop); } /* Starts the default sandbox. */ void startNullSandbox(void) { - struct sandbox newsandbox; + struct sandbox *newsandbox; if (!slist_initiated) { - sandboxes = SLIST_HEAD_INITIALIZER(head); SLIST_INIT(&sandboxes); /* Here we add a sandbox used for non-structure related stuff */ /* This will be the first sandbox always */ if (SLIST_EMPTY(&sandboxes)) { newsandbox = startChild(NULL); - SLIST_INSERT_HEAD(sandboxes, newsandbox, entries); + SLIST_INSERT_HEAD(&sandboxes, newsandbox, next); } } slist_initiated = 1; @@ -101,7 +104,7 @@ if (ptr == NULL) return (SLIST_FIRST(&sandboxes)); - SLIST_FOREACH(sandbox, &sandboxes, entries) + SLIST_FOREACH(sandbox, &sandboxes, next) if (sandbox->dataptr == ptr) return (sandbox); @@ -116,13 +119,13 @@ struct sandbox *newsandbox; if ((newsandbox = malloc(sizeof (struct sandbox))) == NULL) - err(1, "Couldn't allocate memory for sandboxes"); + err(1, "Couldn't allocate memory for sandbox"); sv[0] = sv[1] = 0; if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 ) perror("zcaplib: socketpair()"); - procd = pdfork(); + procd = pdfork(&procd, 0); if (procd == 0 ){ if (cap_rights_limit(STDIN_FILENO, CAP_READ) < 0) err(1, "Couldn't limit rights"); @@ -150,13 +153,15 @@ newsandbox->pd = procd; newsandbox->socket = sv[0]; } + return (newsandbox); } void killChild(void) { int pid; - SLIST_FOREACH(sandbox, &sandboxes, entries) - if (pdgetpid(sandbox->pd, &pid) > 0) - kill(SIGKILL, pid) + struct sandbox *box; + SLIST_FOREACH(box, &sandboxes, next) + if (pdgetpid(box->pd, &pid) > 0) + kill(SIGKILL, pid); } void suicide(int signal) { kill(getpid(), SIGKILL); Modified: soc2013/dpl/head/lib/libzcap/capsicum.h ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.h Thu Sep 5 10:24:09 2013 (r256941) +++ soc2013/dpl/head/lib/libzcap/capsicum.h Thu Sep 5 11:15:58 2013 (r256942) @@ -11,7 +11,7 @@ #define MAXLEN (5*1024) struct sandbox * startSandbox(void *data); -int stopSandbox(struct sandbox *sandbox); +void stopSandbox(struct sandbox *sandbox); void startNullSandbox(void); struct sandbox * findSandbox(void *ptr); struct sandbox *startChild(void *data); @@ -20,8 +20,7 @@ nvlist_t * sendCommand(nvlist_t *nvl, int socket); /* head of singly-linked list. */ -struct slisthead sandboxes; -SLIST_HEAD(slisthead, sandbox) sandboxes; +SLIST_HEAD(slisthead, sandbox) sandboxes = SLIST_HEAD_INITIALIZER(sandboxes); /* * This structure holds a relation of structs of data structs, @@ -31,7 +30,7 @@ void * dataptr; /* Pointer to the data structure of the lib */ int pd; /* Process descriptor */ int socket; /* Socket we have to pass the data through */ - SLIST_ENTRY(entry) entries; /* Singly-linked list. */ + SLIST_ENTRY(sandbox) next; /* Singly-linked list. */ }; #endif /* CAPSICUM_H */ \ No newline at end of file
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309051115.r85BFwRw013331>