Skip to content

Commit

Permalink
Define NULL and avoid clobbering built-in log()
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Feb 18, 2024
1 parent b2b2f7c commit 14fd5a4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "config.h"

#define SYSLOG_NAMES
#include <stddef.h>
#include <syslog/syslog.h> /* libsyslog from sysklogd project */
#include <libite/lite.h>

Expand All @@ -10,7 +11,7 @@
#include <stdlib.h>
#include "log.h"

struct syslog_data log = SYSLOG_DATA_INIT;
struct syslog_data sd = SYSLOG_DATA_INIT;

/* Dumpster dive in container for process ID */
static void dumpster_dive(const char *ident, int *log_pid)
Expand Down Expand Up @@ -57,23 +58,23 @@ static void dumpster_dive(const char *ident, int *log_pid)

void log_open(const char *ident, int option, int facility)
{
openlog_r(ident, LOG_PID, facility, &log);
openlog_r(ident, LOG_PID, facility, &sd);
}

void log_close(void)
{
closelog_r(&log);
closelog_r(&sd);
}

void logit(int severity, const char *fmt, ...)
{
va_list ap;

if (log.log_pid == -1)
dumpster_dive(ident, &log.log_pid);
if (sd.log_pid == -1)
dumpster_dive(ident, &sd.log_pid);

va_start(ap, fmt);
vsyslogp_r(severity, &log, msgid, NULL, fmt, ap);
vsyslogp_r(severity, &sd, msgid, NULL, fmt, ap);
va_end(ap);
}

Expand Down

0 comments on commit 14fd5a4

Please sign in to comment.