aboutsummaryrefslogtreecommitdiffstats
path: root/src/initlog.c
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>1999-02-04 19:11:11 +0000
committerBill Nottingham <notting@redhat.com>1999-02-04 19:11:11 +0000
commitae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c (patch)
tree3c12193fed2a085b512af8cc30d7865adfb10186 /src/initlog.c
parente8d2f95c03d1df94ca6ab9bab11f0f1d8e8c5893 (diff)
downloadinitscripts-ae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c.tar
initscripts-ae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c.tar.gz
initscripts-ae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c.tar.bz2
initscripts-ae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c.tar.xz
initscripts-ae6c4e57c4eda13956a9e5efe0956fd5c90e3a7c.zip
fixes
Diffstat (limited to 'src/initlog.c')
-rw-r--r--src/initlog.c59
1 files changed, 22 insertions, 37 deletions
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;
}