diff options
author | pjd <pjd@FreeBSD.org> | 2005-08-24 17:26:26 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2005-08-24 17:26:26 +0000 |
commit | ce60c894bcc7375ceea501411db3dfd995362b51 (patch) | |
tree | 82b1fbe476916c266aeca6c23e6fbb359fb804e5 /usr.sbin | |
parent | e8bb52f26ca47a74c30d88599fd1eb6a1a50cb92 (diff) | |
download | FreeBSD-src-ce60c894bcc7375ceea501411db3dfd995362b51.zip FreeBSD-src-ce60c894bcc7375ceea501411db3dfd995362b51.tar.gz |
Use pidfile(3) in syslogd(8).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index e506174..ead508a 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -297,6 +297,7 @@ static int LogFacPri; /* Put facility and priority in log message: */ /* 0=no, 1=numeric, 2=names */ static int KeepKernFac; /* Keep remotely logged kernel facility */ static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */ +static struct pidfh *pfh; volatile sig_atomic_t MarkSet, WantDie; @@ -339,14 +340,13 @@ main(int argc, char *argv[]) struct sockaddr_un sunx, fromunix; struct sockaddr_storage frominet; fd_set *fdsr = NULL; - FILE *fp; char line[MAXLINE + 1]; const char *bindhostname, *hname; struct timeval tv, *tvp; struct sigaction sact; struct funix *fx, *fx1; sigset_t mask; - pid_t ppid = 1; + pid_t ppid = 1, spid; socklen_t len; bindhostname = NULL; @@ -456,10 +456,20 @@ main(int argc, char *argv[]) if ((argc -= optind) != 0) usage(); + pfh = pidfile_open(PidFile, 0600, &spid); + if (pfh == NULL) { + if (errno == EEXIST) + errx(1, "syslogd already running, pid: %d", spid); + warn("cannot open pid file"); + } + if (!Debug) { ppid = waitdaemon(0, 0, 30); - if (ppid < 0) - err(1, "could not become daemon"); + if (ppid < 0) { + warn("could not become daemon"); + pidfile_remove(pfh); + exit(1); + } } else { setlinebuf(stdout); } @@ -542,11 +552,7 @@ main(int argc, char *argv[]) dprintf("can't open %s (%d)\n", _PATH_KLOG, errno); /* tuck my process id away */ - fp = fopen(PidFile, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", getpid()); - (void)fclose(fp); - } + pidfile_write(pfh); dprintf("off & running....\n"); @@ -1476,6 +1482,7 @@ die(int signo) } STAILQ_FOREACH(fx, &funixes, next) (void)unlink(fx->name); + pidfile_remove(pfh); exit(1); } |