summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-08-24 19:04:21 +0000
committerpjd <pjd@FreeBSD.org>2005-08-24 19:04:21 +0000
commitda18f6ae6cb11507a5f6ae3b411b195917f3858b (patch)
tree70c660a43439b63a2ab0a5c7a29ce448abd48369 /usr.sbin
parent45a889ae7cd87575cfb3c61357c03b5aa38a495b (diff)
downloadFreeBSD-src-da18f6ae6cb11507a5f6ae3b411b195917f3858b.zip
FreeBSD-src-da18f6ae6cb11507a5f6ae3b411b195917f3858b.tar.gz
Use pidfile(3) in inetd(8).
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/inetd/inetd.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c
index 62929d5..4d41e81 100644
--- a/usr.sbin/inetd/inetd.c
+++ b/usr.sbin/inetd/inetd.c
@@ -275,6 +275,7 @@ extern struct biltin biltins[];
const char *CONFIG = _PATH_INETDCONF;
const char *pid_file = _PATH_INETDPID;
+struct pidfh *pfh = NULL;
struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
@@ -464,7 +465,18 @@ main(int argc, char **argv)
if (access(CONFIG, R_OK) < 0)
syslog(LOG_ERR, "Accessing %s: %m, continuing anyway.", CONFIG);
if (debug == 0) {
- FILE *fp;
+ pid_t otherpid;
+
+ pfh = pidfile_open(pid_file, 0644, &otherpid);
+ if (pfh == NULL) {
+ if (errno == EEXIST) {
+ syslog(LOG_ERR, "%s already running, pid: %d",
+ getprogname(), otherpid);
+ exit(EX_OSERR);
+ }
+ syslog(LOG_WARNING, "pidfile_open() failed: %m");
+ }
+
if (daemon(0, 0) < 0) {
syslog(LOG_WARNING, "daemon(0,0) failed: %m");
}
@@ -480,13 +492,8 @@ main(int argc, char **argv)
syslog(LOG_WARNING, "cannot clear logname: %m");
/* no big deal if it fails.. */
}
- pid = getpid();
- fp = fopen(pid_file, "w");
- if (fp) {
- fprintf(fp, "%ld\n", (long)pid);
- fclose(fp);
- } else {
- syslog(LOG_WARNING, "%s: %m", pid_file);
+ if (pfh != NULL && pidfile_write(pfh) == -1) {
+ syslog(LOG_WARNING, "pidfile_write(): %m");
}
}
@@ -721,6 +728,7 @@ main(int argc, char **argv)
}
sigsetmask(0L);
if (pid == 0) {
+ pidfile_close(pfh);
if (dofork) {
sigaction(SIGALRM, &saalrm, (struct sigaction *)0);
sigaction(SIGCHLD, &sachld, (struct sigaction *)0);
OpenPOWER on IntegriCloud