BSD 4_4 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Sun, 16 May 1993 18:57:59 +0000 (10:57 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Sun, 16 May 1993 18:57:59 +0000 (10:57 -0800)
Work on file usr/src/contrib/bind-4.9/contrib/decwrl/hup-named.c

Synthesized-from: CSRG/cd3/4.4

usr/src/contrib/bind-4.9/contrib/decwrl/hup-named.c [new file with mode: 0644]

diff --git a/usr/src/contrib/bind-4.9/contrib/decwrl/hup-named.c b/usr/src/contrib/bind-4.9/contrib/decwrl/hup-named.c
new file mode 100644 (file)
index 0000000..54f3f03
--- /dev/null
@@ -0,0 +1,51 @@
+/* hup-named -- cause the name server to reload its data files
+ * vix 16sep91 [written]
+ */
+
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+
+#define PIDFILE "/etc/named.pid"
+#define NAMED  "/etc/named"
+
+main() {
+       int pid;
+
+       if (-1 == (pid = read_pidfile(PIDFILE))) {
+               perror(PIDFILE);
+               exit(2);
+       }
+
+       if (0 > kill(pid, SIGHUP)) {
+               int start_new = (errno == ESRCH);
+               perror("kill");
+               if (start_new) {
+                       execl(NAMED, NAMED, NULL);
+                       perror("execl");
+               }
+               exit(2);
+       }
+
+       exit(0);
+}
+
+int
+read_pidfile(filename)
+       char *filename;
+{
+       FILE *pidfile = fopen(filename, "r");
+       char line[10];
+       int pid, error;
+
+       if (!pidfile)
+               return -1;
+       error = (!fgets(line, sizeof line, pidfile));
+       fclose(pidfile);
+       if (error)
+               return -1;
+       pid = atoi(line);
+       if (!pid)
+               return -1;
+       return pid;
+}