diff options
author | Kenjiro Cho <kjc@cvs.openbsd.org> | 2001-12-03 08:40:44 +0000 |
---|---|---|
committer | Kenjiro Cho <kjc@cvs.openbsd.org> | 2001-12-03 08:40:44 +0000 |
commit | d5d811cf68ce1d1dfad58107ecf539b6b1bedcf5 (patch) | |
tree | ace94851bbce21bb04e9b9f063fa4916aec28e3a /usr.sbin/altq/altqd | |
parent | b57632cd9976c363ea1512a745d936bc6dd348a6 (diff) |
cleanup submitted by by Miod Vallat <miod@online.fr>
- use pidfile()
- simplifies some perror() + exit() constructs to use err() instead
- fixes a warn() call instead of a LOG() after daemon() has been called
ok millert@
Diffstat (limited to 'usr.sbin/altq/altqd')
-rw-r--r-- | usr.sbin/altq/altqd/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/altq/altqd/altqd.c | 47 |
2 files changed, 14 insertions, 39 deletions
diff --git a/usr.sbin/altq/altqd/Makefile b/usr.sbin/altq/altqd/Makefile index 7dee175ebe1..d435b2164d6 100644 --- a/usr.sbin/altq/altqd/Makefile +++ b/usr.sbin/altq/altqd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 2001/08/03 18:32:40 fgsch Exp $ +# $OpenBSD: Makefile,v 1.4 2001/12/03 08:40:43 kjc Exp $ # $NetBSD: Makefile,v 1.3 2001/01/11 13:15:06 enami Exp $ .include <bsd.own.mk> @@ -19,7 +19,7 @@ LDADD+= -L${.CURDIR}/../libaltq -laltq DPADD+= ${.CURDIR}/../libaltq/libaltq.a .endif -LDADD+= -lm -DPADD+= ${LIBM} +LDADD+= -lm -lutil +DPADD+= ${LIBM} ${LIBUTIL} .include <bsd.prog.mk> diff --git a/usr.sbin/altq/altqd/altqd.c b/usr.sbin/altq/altqd/altqd.c index 866b28ef732..48a15889d6a 100644 --- a/usr.sbin/altq/altqd/altqd.c +++ b/usr.sbin/altq/altqd/altqd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: altqd.c,v 1.5 2001/11/19 04:20:42 deraadt Exp $ */ +/* $OpenBSD: altqd.c,v 1.6 2001/12/03 08:40:43 kjc Exp $ */ /* $KAME: altqd.c,v 1.5 2001/08/16 10:39:16 kjc Exp $ */ /* * Copyright (c) 2001 Theo de Raadt @@ -73,7 +73,6 @@ #include "altq_qop.h" #include "quip_server.h" -#define ALTQD_PID_FILE "/var/run/altqd.pid" #define MAX_CLIENT 10 int altqd_socket = -1; @@ -133,7 +132,6 @@ main(int argc, char **argv) { int c; int i, maxfd; - extern char *optarg; m_debug = DEFAULT_DEBUG_MASK; l_debug = DEFAULT_LOGGING_LEVEL; @@ -204,24 +202,16 @@ main(int argc, char **argv) } if (daemonize) { - FILE *fp; - daemon(0, 0); /* save pid to the pid file (/var/tmp/altqd.pid) */ - if ((fp = fopen(ALTQD_PID_FILE, "w")) != NULL) { - fprintf(fp, "%d\n", getpid()); - fclose(fp); - } else - warn("can't open pid file: %s: %s", - ALTQD_PID_FILE, strerror(errno)); + if (pidfile(NULL)) + LOG(LOG_WARNING, errno, "can't open pid file"); } else { /* interactive mode */ if (infile) { - if ((infp = fopen(infile, "r")) == NULL) { - perror("Cannot open input file"); - exit(1); - } + if ((infp = fopen(infile, "r")) == NULL) + err(1, "Cannot open input file"); } else { infp = stdin; printf("\nEnter ? or command:\n"); @@ -253,37 +243,22 @@ main(int argc, char **argv) printf("reinitializing altqd...\n"); qcmd_init(); } - if (gotsig_term) { - fprintf(stderr, "Exiting on signal %d\n", SIGTERM); + if (gotsig_term || gotsig_int) { + fprintf(stderr, "Exiting on signal %d\n", + gotsig_term ? SIGTERM : SIGINT); qcmd_destroyall(); - /* if we have a pid file, remove it */ - if (daemonize) { - unlink(ALTQD_PID_FILE); - closelog(); - } - exit(0); - } - if (gotsig_int) { - fprintf(stderr, "Exiting on signal %d\n", SIGINT); - qcmd_destroyall(); - - /* if we have a pid file, remove it */ - if (daemonize) { - unlink(ALTQD_PID_FILE); + if (daemonize) closelog(); - } exit(0); } FD_COPY(&fds, &t_fds); rc = select(maxfd, &t_fds, NULL, NULL, NULL); if (rc < 0) { - if (errno != EINTR) { - perror("select"); - exit(1); - } + if (errno != EINTR) + err(1, "select"); continue; } |