1 /* ulogd_LOGEMU.c, Version $Revision: 5252 $
3 * ulogd output target for syslog logging emulation
5 * This target produces a file which looks the same like the syslog-entries
8 * (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * $Id: ulogd_LOGEMU.c 5252 2005-02-14 16:12:49Z laforge $
31 #include <ulogd/ulogd.h>
32 #include <ulogd/conffile.h>
35 #ifndef ULOGD_LOGEMU_DEFAULT
36 #define ULOGD_LOGEMU_DEFAULT "/var/log/ulogd.syslogemu"
39 #ifndef ULOGD_LOGEMU_SYNC_DEFAULT
40 #define ULOGD_LOGEMU_SYNC_DEFAULT 0
43 #define NIPQUAD(addr) \
44 ((unsigned char *)&addr)[0], \
45 ((unsigned char *)&addr)[1], \
46 ((unsigned char *)&addr)[2], \
47 ((unsigned char *)&addr)[3]
49 static config_entry_t syslogf_ce = {
51 .type = CONFIG_TYPE_STRING,
52 .options = CONFIG_OPT_NONE,
53 .u = { .string = ULOGD_LOGEMU_DEFAULT }
56 static config_entry_t syslsync_ce = {
59 .type = CONFIG_TYPE_INT,
60 .options = CONFIG_OPT_NONE,
61 .u = { .value = ULOGD_LOGEMU_SYNC_DEFAULT }
64 static FILE *of = NULL;
66 static int _output_logemu(ulog_iret_t *res)
68 static char buf[4096];
70 printpkt_print(res, buf, 1);
72 fprintf(of, "%s", buf);
74 if (syslsync_ce.u.value)
80 static void signal_handler_logemu(int signal)
84 ulogd_log(ULOGD_NOTICE, "syslogemu: reopening logfile\n");
86 of = fopen(syslogf_ce.u.string, "a");
88 ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
99 static int init_logemu(void) {
100 /* FIXME: error handling */
101 config_parse_file("LOGEMU", &syslsync_ce);
106 of = fopen(syslogf_ce.u.string, "a");
108 ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
113 if (printpkt_init()) {
114 ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n");
120 static void fini_logemu(void) {
125 static ulog_output_t logemu_op = {
127 .init = &init_logemu,
128 .fini = &fini_logemu,
129 .output = &_output_logemu,
130 .signal = &signal_handler_logemu,
135 register_output(&logemu_op);