aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile3
-rw-r--r--src/initlog.c59
-rw-r--r--src/process.c9
3 files changed, 27 insertions, 44 deletions
diff --git a/src/Makefile b/src/Makefile
index 1fcf1b6c..a93c2b48 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,6 +1,6 @@
CFLAGS+=-Wall -D_GNU_SOURCE
-PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd
+PROGS=usernetctl doexec netreport testd usleep ipcalc initlog minilogd loglevel
INITLOG_OBJS=initlog.o process.o
all: $(PROGS)
@@ -17,6 +17,7 @@ install:
install -s -m 755 ipcalc $(ROOT)/bin/ipcalc
install -s -m 755 initlog $(ROOT)/sbin/initlog
install -s -m 755 minilogd $(ROOT)/sbin/minilogd
+ install -s -m 755 loglevel $(ROOT)/sbin/loglevel
install -m 644 initlog.1 $(ROOT)/usr/man/man1
install -m 644 doexec.1 $(ROOT)/usr/man/man1
install -m 644 netreport.1 $(ROOT)/usr/man/man1
diff --git a/src/initlog.c b/src/initlog.c
index cd787fcf..6bc6fe10 100644
--- a/src/initlog.c
+++ b/src/initlog.c
@@ -11,6 +11,7 @@
#define SYSLOG_NAMES
#include <syslog.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#define _(String) gettext((String))
@@ -86,10 +87,10 @@ int startDaemon() {
if ( pid ) {
/* parent */
waitpid(pid,&rc,0);
- if (rc)
- return -1;
- else
- return 0;
+ if (WIFEXITED(rc))
+ return WEXITSTATUS(rc);
+ else
+ return -1;
} else {
int fd;
@@ -107,44 +108,28 @@ int startDaemon() {
int logLine(struct logInfo *logEnt) {
/* Logs a line... somewhere. */
int x;
+ struct stat statbuf;
/* Don't log empty or null lines */
if (!logEnt->line || !strcmp(logEnt->line,"\n")) return 0;
- if ((x=access(_PATH_LOG,W_OK))) {
- /* syslog isn't running, so start something... */
- if ( (x=startDaemon()) ==-1) {
- logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
- logData[logEntries]= (*logEnt);
- logEntries++;
- } else {
- if (logEntries>0) {
- for (x=0;x<logEntries;x++) {
- openlog(logData[x].cmd,0,logData[x].fac);
- syslog(logData[x].pri,"%s",logData[x].line);
- closelog();
- }
- free(logData);
- logEntries = 0;
- }
- openlog(logEnt->cmd,0,logEnt->fac);
- syslog(logEnt->pri,"%s",logEnt->line);
- closelog();
- }
+ if ( (stat(_PATH_LOG,&statbuf)==-1) && ((x=startDaemon())) ) {
+ logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
+ logData[logEntries]= (*logEnt);
+ logEntries++;
} else {
- if (logEntries>0) {
- for (x=0;x<logEntries;x++) {
- openlog(logData[x].cmd,0,logData[x].fac);
- printf("flushing %s\n",logData[x].line);
- syslog(logData[x].pri,"%s",logData[x].line);
- closelog();
- }
- free(logData);
- logEntries = 0;
- }
- openlog(logEnt->cmd,0,logEnt->fac);
- syslog(logEnt->pri,"%s",logEnt->line);
- closelog();
+ if (logEntries>0) {
+ for (x=0;x<logEntries;x++) {
+ openlog(logData[x].cmd,0,logData[x].fac);
+ syslog(logData[x].pri,"%s",logData[x].line);
+ closelog();
+ }
+ free(logData);
+ logEntries = 0;
+ }
+ openlog(logEnt->cmd,0,logEnt->fac);
+ syslog(logEnt->pri,"%s",logEnt->line);
+ closelog();
}
return 0;
}
diff --git a/src/process.c b/src/process.c
index 860d9452..739e8089 100644
--- a/src/process.c
+++ b/src/process.c
@@ -115,7 +115,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet)
}
while (!done) {
- if ((x=poll(pfds,numfds,500))==-1) {
+ if (((x=poll(pfds,numfds,500))==-1)&&errno!=EINTR) {
perror("poll");
return -1;
}
@@ -164,11 +164,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet)
y++;
}
}
- rc = rc>>8;
-
- if (!rc)
- return 0;
- else {
+ if ((!WIFEXITED(rc)) || (rc=WEXITSTATUS(rc))) {
/* If there was an error and we're quiet, be loud */
int x;
@@ -183,6 +179,7 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet)
}
return (rc);
}
+ return 0;
}
int runCommand(char *cmd, int reexec, int quiet) {