Use logit() for _d() and _e() messages as well

The new logit() function takes care to print to stderr if syslogd has
not yet started.  The _d(), _e(), and _pe() macros have an additional
requirement: to always print on stderr.

After the boot we also want to see what happned during, so this patch
simply adds syslog() support to _d(), _e(), and _pe().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-08-18 01:48:41 +02:00
parent d670e7d3e8
commit c2ec25efd3
2 changed files with 19 additions and 8 deletions
+5 -4
View File
@@ -39,6 +39,8 @@
#include "private.h"
#include "utmp-api.h"
int _slup = 0; /* INTERNAL: Is syslog up yet? */
char *strip_line(char *line)
{
char *ptr;
@@ -183,18 +185,17 @@ int print_result(int fail)
void logit(int prio, const char *fmt, ...)
{
va_list ap;
static int active = 0;
va_start(ap, fmt);
if (!active && !fexist("/dev/log")) {
if (!_slup && !fexist("/dev/log")) {
vfprintf(stderr, fmt, ap);
va_end(ap);
return;
}
if (!active) {
if (!_slup) {
openlog("finit", LOG_PID, LOG_DAEMON);
active = 1;
_slup = 1;
}
vsyslog(prio, fmt, ap);
+14 -4
View File
@@ -25,15 +25,25 @@
#ifndef FINIT_HELPERS_H_
#define FINIT_HELPERS_H_
#include <err.h>
#include <stdio.h>
#include <string.h> /* strerror() */
#include <syslog.h>
#include <sys/types.h>
#define echo(fmt, args...) do { fprintf(stderr, fmt "\n", ##args); } while (0)
#define _d(fmt, args...) do { if (debug) { fprintf(stderr, "finit:%s:%s() - " fmt "\n", __FILE__, __func__, ##args); } } while (0)
#define _e(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt "\n", __FILE__, __func__, ##args); } while (0)
#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt ". Error %d: %s\n", __FILE__, __func__, ##args, errno, strerror(errno)); } while (0)
/*
* Error and debug messages
*
* Use of logit() is preferred, but these are guaranteed to display on
* /dev/console as well. Useful for critical errors and early debug.
*/
#define _l(prio, fmt, args...) do { if (_slup) warnx(fmt "\n", ##args); logit(prio, fmt, ##args); } while (0)
#define _m(prio, fmt, args...) do { _l(prio, "finit:%s:%s() - " fmt, __FILE__, __func__, ##args); } while (0)
#define _d(fmt, args...) do { if (debug) { _m(LOG_DEBUG, fmt, ##args); } } while (0)
#define _e(fmt, args...) do { _m(LOG_ERR, fmt, ##args); } while (0)
#define _pe(fmt, args...) do { _m(LOG_ERR, fmt ". Error %d: %s", ##args, errno, strerror(errno)); } while (0)
extern int _slup; /* INTERNAL: Is syslog up yet? */
char *strip_line (char *line);