Date: Fri, 20 Sep 2013 19:41:09 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257540 - soc2013/dpl/head/lib/libzcap Message-ID: <201309201941.r8KJf9N1044559@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Fri Sep 20 19:41:09 2013 New Revision: 257540 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257540 Log: Added debugging code. Modified: soc2013/dpl/head/lib/libzcap/capsicum.c soc2013/dpl/head/lib/libzcap/debug.h Modified: soc2013/dpl/head/lib/libzcap/capsicum.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.c Fri Sep 20 19:40:03 2013 (r257539) +++ soc2013/dpl/head/lib/libzcap/capsicum.c Fri Sep 20 19:41:09 2013 (r257540) @@ -13,6 +13,7 @@ #include <errno.h> #include <nv.h> #include <signal.h> +#include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> @@ -46,6 +47,17 @@ /* At "debug.h" */ extern int DEBUG_ZCAP; +static void +debug(const char *msg, ...) +{ + va_list ap; + + va_start(ap, msg); + if (DEBUG_ZCAP == 1) + vfprintf(stderr, msg, ap); + va_end(ap); +} + /* * This function should be called only by: * gzopen(), deflateInit(), inflateInit(), @@ -75,8 +87,7 @@ struct sandbox *box; box = findSandbox(ptr); - if (DEBUG_ZCAP) - printf("DEBUG: Stopping sandbox:%d\n",box->pd ); + debug("DEBUG: Stopping sandbox:%d\n",box->pd); pdkill(box->pd, SIGKILL); SLIST_REMOVE(&sandboxes, box, sandbox, next); @@ -111,8 +122,7 @@ { struct sandbox *sandbox; - if (DEBUG_ZCAP) - printf("DEBUG: findSandbox(%p)\n", ptr); + debug("DEBUG: findSandbox(%p)\n", ptr); if (ptr == NULL) return (SLIST_FIRST(&sandboxes)); @@ -176,10 +186,8 @@ newsandbox->dataptr = data; newsandbox->pd = procd; newsandbox->socket = sv[1]; - if (DEBUG_ZCAP) { - printf("DEBUG: We have started a new sandbox.\n"); - printf("\tdata: %p pd: %d, socket: %d\n", data, newsandbox->pd, newsandbox->socket); - } + debug("DEBUG: We have started a new sandbox.\n"); + debug("\tdata: %p pd: %d, socket: %d\n", data, newsandbox->pd, newsandbox->socket); } return (newsandbox); } @@ -204,14 +212,13 @@ box = findSandbox(ptr); - if (DEBUG_ZCAP) - printf("DEBUG: zcaplib: Entered sendCommand(%p, %p): box: %p\n", nvl, ptr, box); - if (DEBUG_ZCAP) - printf("DEBUG: zcaplib: About to send command\n"); + debug("DEBUG: zcaplib: Entered sendCommand(%p, %p): box: %p\n", nvl, ptr, box); + debug("DEBUG: zcaplib: About to send command\n"); + if( nvlist_send(box->socket, nvl) != 0 ) err(1, "zcaplib: nvlist_send Error"); - if (DEBUG_ZCAP) - printf("DEBUG: zcaplib: Awaiting answer\n"); + debug("DEBUG: zcaplib: Awaiting answer\n"); + if ((new = nvlist_recv(box->socket)) == NULL) err(1, "nvlist_recv(): nvlist_t is NULL"); return (new); Modified: soc2013/dpl/head/lib/libzcap/debug.h ============================================================================== --- soc2013/dpl/head/lib/libzcap/debug.h Fri Sep 20 19:40:03 2013 (r257539) +++ soc2013/dpl/head/lib/libzcap/debug.h Fri Sep 20 19:41:09 2013 (r257540) @@ -1 +1 @@ -int DEBUG_ZCAP = 0; +int DEBUG_ZCAP = 1;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309201941.r8KJf9N1044559>