void log_set_name(const char *name);
void log_set_namef(const char *fmt, ...);
+void log_activate_stderr(void);
void log_free_name(void);
void log_error(const char *file, int line, const char *errstr,
const char *fmt, ...);
-/* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
- *
- * $Id$
+/*
+ * Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
+ * Copyright (C) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* IN THE SOFTWARE.
*/
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#endif
static char *log_name = NULL;
+static bool syslog_is_open = false;
+#ifdef HAVE_SYSLOG
+static int syslog_logopt = LOG_PID|LOG_CONS;
+#endif
+
+static void
+_openlog(bool reopen)
+{
+#ifdef HAVE_SYSLOG
+ if (!reopen) {
+ if (syslog_is_open)
+ return;
+ } else {
+ if (!syslog_is_open)
+ closelog();
+ }
+ openlog(log_name, syslog_logopt, LOG_MAIL);
+ syslog_is_open = true;
+#endif
+}
void log_set_name(const char* name)
{
free(log_name);
log_name = xstrdup(name);
+
+ _openlog(true);
+}
+
+void
+log_activate_stderr(void)
+{
+#ifdef HAVE_SYSLOG
+ syslog_logopt |= LOG_PERROR;
+#endif
}
void
free(log_name);
log_name = buf;
+
+ _openlog(true);
}
void log_free_name()
void log_error(const char *file, int line, const char *errstr,
const char *fmt, ...)
{
- static int syslog_is_open = 0;
- char buf[1024];
+ char *buf;
va_list ap;
+ int i;
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ i = vasprintf(&buf, fmt, ap);
va_end(ap);
+ if (i < 0 || buf == NULL)
+ abort();
+
if (!log_name) log_name = "mlmmj-UNKNOWN";
#ifdef HAVE_SYSLOG
- if(!syslog_is_open) {
- openlog(log_name, LOG_PID|LOG_CONS, LOG_MAIL);
- syslog_is_open = 1;
- }
+ _openlog(true);
syslog(LOG_ERR, "%s:%d: %s: %s", file, line, buf, errstr);
#else
fprintf(stderr, "%s[%d]: %s:%d: %s: %s\n", log_name, (int)getpid(),
file, line, buf, errstr);
#endif
+ free(buf);
}
daemonize = false;
}
+ if (!daemonize)
+ log_activate_stderr();
+
while(1) {
if(listdir) {
log_set_namef("%s(%s)", argv[0], listdir);
EOF
atf_check -o inline:"bla\n" cat list/queue/discarded/*
# the discarded file is too new, do not drop it yet
- atf_check -s exit:0 $mlmmjmaint -F -L ${here}/list
+ atf_check -s exit:0 -e ignore $mlmmjmaint -F -L ${here}/list
atf_check -o inline:"bla\n" cat list/queue/discarded/*
atf_check touch -m -t 197001010101 list/queue/discarded/*
- atf_check -s exit:0 $mlmmjmaint -F -L ${here}/list
+ atf_check -s exit:0 -e ignore $mlmmjmaint -F -L ${here}/list
atf_check -o inline:"list/queue/discarded\n" find list/queue/discarded -type d -empty
#now with relative path
bla
EOF
atf_check -o inline:"bla\n" cat list/queue/discarded/*
- atf_check -s exit:0 $mlmmjmaint -F -L list
+ atf_check -s exit:0 -e ignore $mlmmjmaint -F -L list
atf_check -o inline:"bla\n" cat list/queue/discarded/*
atf_check touch -m -t 197001010101 list/queue/discarded/*
- atf_check -s exit:0 $mlmmjmaint -F -L list
+ atf_check -s exit:0 -e ignore $mlmmjmaint -F -L list
atf_check -o inline:"list/queue/discarded\n" find list/queue/discarded -type d -empty
}
echo "$now" > ${f2}-probe
touch ${f2}
touch ${f2}.lastmsg
- atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F
+ atf_check -s exit:0 -o empty -e ignore $mlmmjmaintd -L lists/ml -F
atf_check -s exit:1 -o empty -e empty test -f $f1
atf_check -s exit:1 -o empty -e empty test -f $f1-probe
atf_check -s exit:1 -o empty -e empty test -f $f1.lastmsg
f2=lists/ml/queue/discarded/notsoold
atf_check touch -t "197001020000" $f1
atf_check touch $f2
- atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F
+ atf_check -s exit:0 -o empty -e ignore $mlmmjmaintd -L lists/ml -F
atf_check -s exit:1 -o empty -e empty test -f $f1
atf_check -s exit:0 -o empty -e empty test -f $f2
}
atf_check -s exit:0 -o "inline:mlmmj-maintd version 1.3.0\n" $mlmmjmaintd -V
atf_check -s exit:0 -o "inline:$helptxt" $mlmmjmaintd -h
echo test@mlmmjtest > lists/ml/control/listaddress
- atf_check -s exit:0 -o empty -e empty $mlmmjmaintd -L lists/ml -F
+ atf_check -s exit:0 -o empty -e ignore $mlmmjmaintd -L lists/ml -F
output="Starting maintenance run at
clean_moderation