diff options
Diffstat (limited to 'usr.sbin/named')
-rw-r--r-- | usr.sbin/named/named/ns_main.c | 32 | ||||
-rw-r--r-- | usr.sbin/named/ndc/ndc.sh | 23 |
2 files changed, 42 insertions, 13 deletions
diff --git a/usr.sbin/named/named/ns_main.c b/usr.sbin/named/named/ns_main.c index 73051129323..af9c08baf39 100644 --- a/usr.sbin/named/named/ns_main.c +++ b/usr.sbin/named/named/ns_main.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_main.c,v 1.12 1998/05/22 07:09:16 millert Exp $ */ +/* $OpenBSD: ns_main.c,v 1.13 1998/05/22 19:34:44 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91"; static char rcsid[] = "$From: ns_main.c,v 8.26 1998/05/11 04:19:45 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: ns_main.c,v 1.12 1998/05/22 07:09:16 millert Exp $"; +static char rcsid[] = "$OpenBSD: ns_main.c,v 1.13 1998/05/22 19:34:44 millert Exp $"; #endif #endif /* not lint */ @@ -194,7 +194,7 @@ main(argc, argv, envp) fd_set *tmpmask; struct timeval t, *tp; struct qstream *candidate = QSTREAM_NULL; - char **argp; + char **argp, *p; char *chroot_dir = NULL; char *user_name = NULL; char *group_name = NULL; @@ -204,9 +204,11 @@ main(argc, argv, envp) struct passwd *pw; #ifdef PID_FIX char oldpid[10]; + char oldargs[BUFSIZ]; #endif #ifdef WANT_PIDFILE FILE *fp; /* file descriptor for pid file */ + char *nsargs; #endif #ifdef IP_OPTIONS struct ipoption ip_opts; @@ -281,7 +283,7 @@ main(argc, argv, envp) ns_port = htons((u_int16_t) atoi(*++argv)); { - char *p = strchr(*argv, '/'); + p = strchr(*argv, '/'); if (p) { local_ns_port = htons((u_int16_t) @@ -384,7 +386,6 @@ main(argc, argv, envp) */ if (chroot_dir != NULL) { struct stat sb; - char *p; if (chroot(chroot_dir) < 0) { fprintf(stderr, "chroot %s failed: %s\n", chroot_dir, @@ -421,19 +422,36 @@ main(argc, argv, envp) ns_udp(); #ifdef WANT_PIDFILE + /* build up argument string to stash in pid file */ + nsargs = malloc(LastArg - Argv[0] + 1); + if (nsargs == NULL) { + syslog(LOG_ERR, + "building argument string, malloc: %m - exiting"); + exit(1); + } + for (p=nsargs, argp=Argv; *argp; argp++) { + strcpy(p, *argp); + p += strlen(p); + *p++ = ' '; + } + *--p = '\0'; + /* tuck my process id away */ #ifdef PID_FIX fp = fopen(PidFile, "w"); if (fp != NULL) { (void) fgets(oldpid, sizeof(oldpid), fp); + (void) fgets(oldargs, sizeof(oldargs), fp); (void) rewind(fp); fprintf(fp, "%ld\n", (long)getpid()); + fprintf(fp, "%s\n", nsargs); (void) my_fclose(fp); } #else /*PID_FIX*/ fp = fopen(PidFile, "w"); if (fp != NULL) { fprintf(fp, "%d\n", getpid()); + fprintf(fp, "%s\n", nsargs); (void) my_fclose(fp); } #endif /*PID_FIX*/ @@ -492,7 +510,8 @@ main(argc, argv, envp) #if defined(WANT_PIDFILE) && defined(PID_FIX) /* put old pid back */ if (atoi(oldpid) && (fp = fopen(PidFile, "w"))) { - fprintf(fp, "%s", oldpid); + fputs(oldpid, fp); + fputs(oldargs, fp); (void) my_fclose(fp); _exit(1); } @@ -670,6 +689,7 @@ main(argc, argv, envp) fp = fopen(PidFile, "w"); if (fp != NULL) { fprintf(fp, "%ld\n", (long)getpid()); + fprintf(fp, "%s\n", nsargs); (void) my_fclose(fp); } #endif diff --git a/usr.sbin/named/ndc/ndc.sh b/usr.sbin/named/ndc/ndc.sh index 417ea5924c2..d77a44753d8 100644 --- a/usr.sbin/named/ndc/ndc.sh +++ b/usr.sbin/named/ndc/ndc.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: ndc.sh,v 1.5 1997/03/12 14:51:57 downsj Exp $ +# $OpenBSD: ndc.sh,v 1.6 1998/05/22 19:34:46 millert Exp $ USAGE='echo \ "usage: $0 \ @@ -9,15 +9,24 @@ USAGE='echo \ PATH=%DESTSBIN%:/bin:/usr/bin:/usr/ucb:$PATH PIDFILE=%PIDDIR%/named.pid +NAMED_CMD=named if [ -f $PIDFILE ] then - PID=`cat $PIDFILE` + PID=`sed 1q $PIDFILE` + NAMED_CMD=`tail -1 $PIDFILE` + if kill -0 $PID >/dev/null 2>&1; then + RUNNING=1 + else + RUNNING=0 + fi PS=`%PS% $PID | tail -1 | grep $PID` - RUNNING=1 [ `echo $PS | wc -w` -ne 0 ] || { - PS="named (pid $PID?) not running" - RUNNING=0 + if [ $RUNNING -eq 1 ]; then + PS="named (pid $PID) can't get name list" + else + PS="named (pid $PID?) not running" + fi } else PS="named (no pid file) not running" @@ -50,7 +59,7 @@ do continue } rm -f $PIDFILE - named && { + $NAMED_CMD && { sleep 5 echo Name Server Started } @@ -71,7 +80,7 @@ do kill $PID && sleep 5 } rm -f $PIDFILE - named && { + $NAMED_CMD && { sleep 5 echo Name Server Restarted } |