From owner-svn-soc-all@FreeBSD.ORG Fri Sep 20 19:41:10 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 5654E8F for ; Fri, 20 Sep 2013 19:41:10 +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 3546C2D2C for ; Fri, 20 Sep 2013 19:41:10 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8KJfAdM044567 for ; Fri, 20 Sep 2013 19:41:10 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r8KJf9N1044559 for svn-soc-all@FreeBSD.org; Fri, 20 Sep 2013 19:41:09 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 20 Sep 2013 19:41:09 GMT Message-Id: <201309201941.r8KJf9N1044559@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: r257540 - 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: Fri, 20 Sep 2013 19:41:10 -0000 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 #include #include +#include #include #include #include @@ -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;