mirror of
https://github.com/troglobit/finit.git
synced 2026-11-29 21:08:21 +00:00
Extend .conf syntax for 'log' option, issue #21
This is the first patch in a series to add support for
log:/path/to/logfile,priority:facility.level,tag:ident
In this patch support for 'priority:' and 'tag:', log file support
coming later.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
44591c6e51
commit
cbd4cc8d34
2 files changed
+50
-14
No files matched your search
+44
-13
@@ -213,7 +213,7 @@ static int service_start(svc_t *svc)
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (svc->log) {
|
if (svc->log.enabled) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -222,12 +222,12 @@ static int service_start(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
fd = posix_openpt(O_RDWR);
|
fd = posix_openpt(O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
svc->log = 0;
|
svc->log.enabled = 0;
|
||||||
goto logger_err;
|
goto logger_err;
|
||||||
}
|
}
|
||||||
if (grantpt(fd) == -1 || unlockpt(fd) == -1) {
|
if (grantpt(fd) == -1 || unlockpt(fd) == -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
svc->log = 0;
|
svc->log.enabled = 0;
|
||||||
goto logger_err;
|
goto logger_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +235,11 @@ static int service_start(svc_t *svc)
|
|||||||
sigprocmask(SIG_BLOCK, &nmask, NULL);
|
sigprocmask(SIG_BLOCK, &nmask, NULL);
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
int fds = open(ptsname(fd), O_RDONLY);
|
int fds;
|
||||||
|
char *tag = basename(svc->cmd);
|
||||||
|
char *prio = "daemon.info";
|
||||||
|
|
||||||
|
fds = open(ptsname(fd), O_RDONLY);
|
||||||
close(fd);
|
close(fd);
|
||||||
if (fds == -1)
|
if (fds == -1)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
@@ -245,7 +248,12 @@ static int service_start(svc_t *svc)
|
|||||||
/* Reset signals */
|
/* Reset signals */
|
||||||
sig_unblock();
|
sig_unblock();
|
||||||
|
|
||||||
execlp("logger", "logger", "-t", svc->cmd, "-p", "daemon.info", NULL);
|
if (svc->log.ident[0])
|
||||||
|
tag = svc->log.ident;
|
||||||
|
if (svc->log.prio[0])
|
||||||
|
prio = svc->log.prio;
|
||||||
|
|
||||||
|
execlp("logger", "logger", "-t", tag, "-p", prio, NULL);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +302,7 @@ static int service_start(svc_t *svc)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (svc->log)
|
if (svc->log.enabled)
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
exit(status);
|
exit(status);
|
||||||
} else if (log_is_debug()) {
|
} else if (log_is_debug()) {
|
||||||
@@ -495,6 +503,28 @@ void service_runlevel(int newlevel)
|
|||||||
networking(0);
|
networking(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* log:/path/to/logfile,priority:facility.level,tag:ident
|
||||||
|
*/
|
||||||
|
static void parse_log(svc_t *svc, char *arg)
|
||||||
|
{
|
||||||
|
char *tok;
|
||||||
|
|
||||||
|
tok = strtok(arg, ":, ");
|
||||||
|
while (tok) {
|
||||||
|
if (!strcmp(tok, "log"))
|
||||||
|
svc->log.enabled = 1;
|
||||||
|
else if (tok[0] == '/')
|
||||||
|
strlcpy(svc->log.file, tok, sizeof(svc->log.file));
|
||||||
|
else if (!strcmp(tok, "priority") || !strcmp(tok, "prio"))
|
||||||
|
strlcpy(svc->log.prio, strtok(NULL, ","), sizeof(svc->log.prio));
|
||||||
|
else if (!strcmp(tok, "tag") || !strcmp(tok, "identity") || !strcmp(tok, "ident"))
|
||||||
|
strlcpy(svc->log.ident, strtok(NULL, ","), sizeof(svc->log.ident));
|
||||||
|
|
||||||
|
tok = strtok(NULL, ":=, ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* service_register - Register service, task or run commands
|
* service_register - Register service, task or run commands
|
||||||
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
||||||
@@ -554,9 +584,9 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
#ifdef INETD_ENABLED
|
#ifdef INETD_ENABLED
|
||||||
int forking = 0;
|
int forking = 0;
|
||||||
#endif
|
#endif
|
||||||
int log = 0, levels = 0;
|
int levels = 0;
|
||||||
char *line;
|
char *line;
|
||||||
char *username = NULL, *pid = NULL;
|
char *username = NULL, *log = NULL, *pid = NULL;
|
||||||
char *service = NULL, *proto = NULL, *ifaces = NULL;
|
char *service = NULL, *proto = NULL, *ifaces = NULL;
|
||||||
char *cmd, *desc, *runlevels = NULL, *cond = NULL;
|
char *cmd, *desc, *runlevels = NULL, *cond = NULL;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
@@ -604,7 +634,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
forking = 0;
|
forking = 0;
|
||||||
#endif
|
#endif
|
||||||
else if (!strncasecmp(cmd, "log", 3))
|
else if (!strncasecmp(cmd, "log", 3))
|
||||||
log = 1;
|
log = cmd;
|
||||||
else if (!strncasecmp(cmd, "pid", 3))
|
else if (!strncasecmp(cmd, "pid", 3))
|
||||||
pid = cmd;
|
pid = cmd;
|
||||||
else if (cmd[0] != '/' && strchr(cmd, '/'))
|
else if (cmd[0] != '/' && strchr(cmd, '/'))
|
||||||
@@ -693,10 +723,6 @@ recreate:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
svc->log = log;
|
|
||||||
if (desc)
|
|
||||||
strlcpy(svc->desc, desc, sizeof(svc->desc));
|
|
||||||
|
|
||||||
/* Always clear svc PID file, for now. See TODO */
|
/* Always clear svc PID file, for now. See TODO */
|
||||||
svc->pidfile[0] = 0;
|
svc->pidfile[0] = 0;
|
||||||
/* Decode any optional pid:/optional/path/to/file.pid */
|
/* Decode any optional pid:/optional/path/to/file.pid */
|
||||||
@@ -729,6 +755,11 @@ recreate:
|
|||||||
|
|
||||||
conf_parse_cond(svc, cond);
|
conf_parse_cond(svc, cond);
|
||||||
|
|
||||||
|
if (log)
|
||||||
|
parse_log(svc, log);
|
||||||
|
if (desc)
|
||||||
|
strlcpy(svc->desc, desc, sizeof(svc->desc));
|
||||||
|
|
||||||
#ifdef INETD_ENABLED
|
#ifdef INETD_ENABLED
|
||||||
if (svc_is_inetd(svc)) {
|
if (svc_is_inetd(svc)) {
|
||||||
char *iface, *name = service;
|
char *iface, *name = service;
|
||||||
|
|||||||
@@ -111,7 +111,12 @@ typedef struct svc {
|
|||||||
int stdin_fd;
|
int stdin_fd;
|
||||||
|
|
||||||
/* Set for services we need to redirect stdout/stderr to syslog */
|
/* Set for services we need to redirect stdout/stderr to syslog */
|
||||||
int log;
|
struct {
|
||||||
|
int enabled;
|
||||||
|
char file[64];
|
||||||
|
char prio[20];
|
||||||
|
char ident[20];
|
||||||
|
} log;
|
||||||
|
|
||||||
/* Identity */
|
/* Identity */
|
||||||
char username[MAX_USER_LEN];
|
char username[MAX_USER_LEN];
|
||||||
|
|||||||
Reference in new issue
Block a user