Date: Mon, 25 Feb 2008 06:06:53 GMT From: Aaron Meihm <alm@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 136149 for review Message-ID: <200802250606.m1P66rf2035019@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/types.h> #include <sys/queue.h> #include <sys/select.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/time.h> + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -40,7 +40,9 @@ #include <fcntl.h> #include <netdb.h> #include <signal.h> + #include <bsm/libbsm.h> + #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; };
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802250606.m1P66rf2035019>