From owner-svn-soc-all@FreeBSD.ORG Thu Sep 5 11:15:58 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 642551C2 for ; Thu, 5 Sep 2013 11:15:58 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 429EC250E for ; Thu, 5 Sep 2013 11:15:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r85BFwXn013334 for ; Thu, 5 Sep 2013 11:15:58 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r85BFwRw013331 for svn-soc-all@FreeBSD.org; Thu, 5 Sep 2013 11:15:58 GMT (envelope-from dpl@FreeBSD.org) Date: Thu, 5 Sep 2013 11:15:58 GMT Message-Id: <201309051115.r85BFwRw013331@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256942 - soc2013/dpl/head/lib/libzcap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Sep 2013 11:15:58 -0000 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 #include +/* + * 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