From fb003f991ef18c86c920e3791b2421cad3f23cd6 Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 25 Mar 2001 18:25:01 +0000 Subject: added date and hostname printing to be more syslog-alike --- extensions/ulogd_LOGEMU.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/extensions/ulogd_LOGEMU.c b/extensions/ulogd_LOGEMU.c index 40b02fe..c9b1ac5 100644 --- a/extensions/ulogd_LOGEMU.c +++ b/extensions/ulogd_LOGEMU.c @@ -1,4 +1,4 @@ -/* ulogd_LOGEMU.c, Version $Revision: 1.2 $ +/* ulogd_LOGEMU.c, Version $Revision: 1.3 $ * * ulogd output target for syslog logging emulation * @@ -8,13 +8,16 @@ * (C) 2000 by Harald Welte * This software is released under the terms of GNU GPL * - * $Id: ulogd_LOGEMU.c,v 1.2 2000/11/20 11:43:22 laforge Exp $ + * $Id: ulogd_LOGEMU.c,v 1.3 2001/02/04 13:39:31 laforge Exp $ * */ #include #include +#include #include +#include +#include #include #include #include "ulogd.h" @@ -32,6 +35,8 @@ static FILE *of = NULL; +static char hostname[255]; + struct intr_id { char* name; unsigned int id; @@ -79,8 +84,29 @@ static struct intr_id intr_ids[INTR_IDS] = { int _output_logemu(ulog_iret_t *res) { - fprintf(of, "%sIN=%s OUT=%s ", - (char *) GET_VALUE(0).ptr, + char *timestr; + char *tmp; + time_t now; + + /* get time */ + time(&now); + timestr = ctime(&now) + 4; + + /* truncate time */ + if (tmp = strchr(timestr, '\n')) + *tmp = '\0'; + + /* truncate hostname */ + if (tmp = strchr(hostname, '.')) + *tmp = '\0'; + + /* print time and hostname */ + fprintf(of, "%.15s %s", timestr, hostname); + + if (*(char *) GET_VALUE(0).ptr) + fprintf(of, " %s", (char *) GET_VALUE(0).ptr); + + fprintf(of," IN=%s OUT=%s ", (char *) GET_VALUE(1).ptr, (char *) GET_VALUE(2).ptr); @@ -220,12 +246,19 @@ static void _logemu_reg_op(void) static config_entry_t syslogf_ce = { NULL, "syslogfile", CONFIG_TYPE_STRING, CONFIG_OPT_NONE, 0, { string: ULOGD_LOGEMU_DEFAULT } }; + void _init(void) { /* FIXME: error handling */ config_register_key(&syslogf_ce); config_parse_file(0); + if (gethostname(hostname, sizeof(hostname)) < 0) { + ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n", + strerror(errno)); + exit(2); + } + #ifdef DEBUG_LOGEMU of = stdout; #else -- cgit v1.2.3