mirror of
https://github.com/troglobit/finit.git
synced 2026-10-30 12:50:34 +00:00
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:
1 parent
d670e7d3e8
commit
c2ec25efd3
2 files changed
+19
-8
No files matched your search
@@ -39,6 +39,8 @@
|
|||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
|
|
||||||
|
int _slup = 0; /* INTERNAL: Is syslog up yet? */
|
||||||
|
|
||||||
char *strip_line(char *line)
|
char *strip_line(char *line)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
@@ -183,18 +185,17 @@ int print_result(int fail)
|
|||||||
void logit(int prio, const char *fmt, ...)
|
void logit(int prio, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
static int active = 0;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
if (!active && !fexist("/dev/log")) {
|
if (!_slup && !fexist("/dev/log")) {
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!active) {
|
if (!_slup) {
|
||||||
openlog("finit", LOG_PID, LOG_DAEMON);
|
openlog("finit", LOG_PID, LOG_DAEMON);
|
||||||
active = 1;
|
_slup = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vsyslog(prio, fmt, ap);
|
vsyslog(prio, fmt, ap);
|
||||||
|
|||||||
@@ -25,15 +25,25 @@
|
|||||||
#ifndef FINIT_HELPERS_H_
|
#ifndef FINIT_HELPERS_H_
|
||||||
#define FINIT_HELPERS_H_
|
#define FINIT_HELPERS_H_
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h> /* strerror() */
|
#include <string.h> /* strerror() */
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <sys/types.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)
|
* Error and debug messages
|
||||||
#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)
|
* 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);
|
char *strip_line (char *line);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user