From owner-p4-projects@FreeBSD.ORG Mon Feb 25 06:06:55 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6326A16A407; Mon, 25 Feb 2008 06:06:55 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1A22E16A400 for ; Mon, 25 Feb 2008 06:06:55 +0000 (UTC) (envelope-from alm@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 0540513C4EA for ; Mon, 25 Feb 2008 06:06:55 +0000 (UTC) (envelope-from alm@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m1P66sCa035036 for ; Mon, 25 Feb 2008 06:06:54 GMT (envelope-from alm@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m1P66rf2035019 for perforce@freebsd.org; Mon, 25 Feb 2008 06:06:53 GMT (envelope-from alm@freebsd.org) Date: Mon, 25 Feb 2008 06:06:53 GMT Message-Id: <200802250606.m1P66rf2035019@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to alm@freebsd.org using -f From: Aaron Meihm To: Perforce Change Reviews Cc: Subject: PERFORCE change 136149 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Feb 2008 06:06:55 -0000 http://perforce.freebsd.org/chv.cgi?CH=136149 Change 136149 by alm@alm_praetorian on 2008/02/25 06:06:46 basic daemonize various style changes use component_destroy() instead of free() Affected files ... .. //depot/projects/trustedbsd/netauditd/component.c#3 edit .. //depot/projects/trustedbsd/netauditd/conf.c#3 edit .. //depot/projects/trustedbsd/netauditd/netauditd.c#10 edit .. //depot/projects/trustedbsd/netauditd/netauditd.h#7 edit Differences ... ==== //depot/projects/trustedbsd/netauditd/component.c#3 (text+ko) ==== @@ -23,13 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include #include #include #include #include #include + #include #include #include @@ -40,7 +40,9 @@ #include #include #include + #include + #include "netauditd.h" au_cmpnt_head_t au_srclist; ==== //depot/projects/trustedbsd/netauditd/conf.c#3 (text+ko) ==== @@ -84,7 +84,7 @@ else new->ac_type = NETAUDIT_DST_NET; if (getaddrinfo(host, svc, &hints, &new->ac_ainfo) != 0) { - free(new); + component_destroy(new); return (-1); } if (is_src) ==== //depot/projects/trustedbsd/netauditd/netauditd.c#10 (text+ko) ==== @@ -49,8 +49,11 @@ #include "netauditd.h" +#define FLAG_DEBUG 1 +#define FLAG_FOREGROUND (1 << 1) + char *conf_path = "/usr/local/etc/netauditd.conf"; -int debug_flag; +int netaudit_flags; void dprintf(char *fmt, ...) @@ -58,7 +61,7 @@ char buf[2048]; va_list ap; - if (!debug_flag) + if (!(netaudit_flags & FLAG_DEBUG)) return; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); @@ -71,10 +74,13 @@ { char ch; - while ((ch = getopt(argc, argv, "df:h")) != -1) { + while ((ch = getopt(argc, argv, "Ddf:h")) != -1) { switch (ch) { + case 'D': + netaudit_flags |= FLAG_FOREGROUND; + break; case 'd': - debug_flag = 1; + netaudit_flags |= FLAG_DEBUG; break; case 'f': conf_path = optarg; @@ -177,6 +183,13 @@ exit(2); } } + if (!(netaudit_flags & FLAG_FOREGROUND)) { + ret = fork(); + if (ret == -1) + err(1, "fork"); + if (ret != 0) + exit(0); + } netaudit_establish(); memset(&tv, 0, sizeof(tv)); tv.tv_usec = 100000; @@ -361,10 +374,10 @@ if (listen(au->ac_fd, 16) == -1) err(1, "listen"); if ((flags = fcntl(au->ac_fd, F_GETFL)) == -1) - exit(2); + err(1, "fcntl"); flags |= O_NONBLOCK; if (fcntl(au->ac_fd, F_SETFL, flags) == -1) - exit(2); + err(1, "fcntl"); } int @@ -446,6 +459,6 @@ void usage() { - fputs("usage: netauditd [-dh] [-f path]\n", stderr); + fputs("usage: netauditd [-Ddh] [-f path]\n", stderr); exit(1); } ==== //depot/projects/trustedbsd/netauditd/netauditd.h#7 (text+ko) ==== @@ -27,7 +27,6 @@ #define MAX_ARGUMENTS 256 #define NETAUDIT_PIPE_BUFSIZE 1024 -#define NETAUDIT_DELAY_TIMER 100000 #define NETAUDIT_SRC_PIPE 1 #define NETAUDIT_SRC_NET 2 @@ -37,12 +36,12 @@ struct au_recbuf { void *ar_rec; u_int32_t ar_reclen; - u_int32_t ar_refcount; + int ar_refcount; }; struct au_queue_ent { struct au_recbuf *aq_ptr; - int aq_remain; + u_int32_t aq_remain; TAILQ_ENTRY(au_queue_ent) aq_glue; };