mirror of
https://github.com/troglobit/finit.git
synced 2026-11-12 16:51:25 +00:00
Refactor, drop #ifdefs and logger fallback, probe for logit
Simplify log redirection, probe for logit early and fall back to use a while-loop of syslog() instead. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
549aeda1fd
commit
dda59503ac
2 files changed
+14
-18
No files matched your search
@@ -45,6 +45,8 @@
|
|||||||
#define _PATH_VARRUN "/var/run/"
|
#define _PATH_VARRUN "/var/run/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LOGIT_PATH FINIT_LIBPATH_ "/logit"
|
||||||
|
|
||||||
#define CMD_SIZE 256
|
#define CMD_SIZE 256
|
||||||
#define LINE_SIZE 1024
|
#define LINE_SIZE 1024
|
||||||
#define BUF_SIZE 4096
|
#define BUF_SIZE 4096
|
||||||
|
|||||||
+12
-18
@@ -27,6 +27,7 @@
|
|||||||
#include <ctype.h> /* isblank() */
|
#include <ctype.h> /* isblank() */
|
||||||
#include <sched.h> /* sched_yield() */
|
#include <sched.h> /* sched_yield() */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@@ -149,7 +150,6 @@ static int fredirect(const char *file)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef LOGIT_ENABLED
|
|
||||||
/*
|
/*
|
||||||
* Fallback in case we don't even have logger on the system.
|
* Fallback in case we don't even have logger on the system.
|
||||||
* XXX: we should parse 'prio' here to get facility.level
|
* XXX: we should parse 'prio' here to get facility.level
|
||||||
@@ -160,13 +160,13 @@ static void fallback_logger(char *ident, char *prio)
|
|||||||
int level = LOG_NOTICE;
|
int level = LOG_NOTICE;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
|
prctl(PR_SET_NAME, "finitlog", 0, 0, 0);
|
||||||
openlog(ident, LOG_NOWAIT | LOG_PID, facility);
|
openlog(ident, LOG_NOWAIT | LOG_PID, facility);
|
||||||
while ((fgets(buf, sizeof(buf), stdin)))
|
while ((fgets(buf, sizeof(buf), stdin)))
|
||||||
syslog(level, "%s", buf);
|
syslog(level, "%s", buf);
|
||||||
|
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Redirect output to syslog using the command line logit tool
|
* Redirect output to syslog using the command line logit tool
|
||||||
@@ -206,19 +206,20 @@ static int lredirect(svc_t *svc)
|
|||||||
/* Reset signals */
|
/* Reset signals */
|
||||||
sig_unblock();
|
sig_unblock();
|
||||||
|
|
||||||
|
if (!whichp(LOGIT_PATH)) {
|
||||||
|
logit(LOG_INFO, LOGIT_PATH " missing, using syslog for %s instead", svc->name);
|
||||||
|
fallback_logger(tag, prio);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (svc->log.file[0] == '/') {
|
if (svc->log.file[0] == '/') {
|
||||||
#ifdef LOGIT_ENABLED
|
|
||||||
char sz[20], num[3];
|
char sz[20], num[3];
|
||||||
|
|
||||||
snprintf(sz, sizeof(sz), "%d", logfile_size_max);
|
snprintf(sz, sizeof(sz), "%d", logfile_size_max);
|
||||||
snprintf(num, sizeof(num), "%d", logfile_count_max);
|
snprintf(num, sizeof(num), "%d", logfile_count_max);
|
||||||
|
|
||||||
execlp(FINIT_LIBPATH_ "/logit", "logit", "-f", svc->log.file, "-n", sz, "-r", num, NULL);
|
execlp(LOGIT_PATH, "logit", "-f", svc->log.file, "-n", sz, "-r", num, NULL);
|
||||||
#else
|
_exit(1);
|
||||||
logit(LOG_INFO, "logit disabled, logging %s to syslog instead", svc->name);
|
|
||||||
fallback_logger(tag, prio);
|
|
||||||
_exit(0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (svc->log.ident[0])
|
if (svc->log.ident[0])
|
||||||
@@ -226,15 +227,8 @@ static int lredirect(svc_t *svc)
|
|||||||
if (svc->log.prio[0])
|
if (svc->log.prio[0])
|
||||||
prio = svc->log.prio;
|
prio = svc->log.prio;
|
||||||
|
|
||||||
#ifdef LOGIT_ENABLED
|
execlp(LOGIT_PATH, "logit", "-t", tag, "-p", prio, NULL);
|
||||||
execlp(FINIT_LIBPATH_ "/logit", "logit", "-t", tag, "-p", prio, NULL);
|
_exit(1);
|
||||||
#else
|
|
||||||
if (whichp("logger"))
|
|
||||||
execlp("logger", "logger", "-t", tag, "-p", prio, NULL);
|
|
||||||
|
|
||||||
fallback_logger(tag, prio);
|
|
||||||
#endif
|
|
||||||
_exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dup2(fd, STDOUT_FILENO);
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
|||||||
Reference in new issue
Block a user