home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / contrib / decwrl / hup-named.c < prev    next >
C/C++ Source or Header  |  1993-05-17  |  791b  |  52 lines

  1. /* hup-named -- cause the name server to reload its data files
  2.  * vix 16sep91 [written]
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <signal.h>
  7. #include <errno.h>
  8.  
  9. #define PIDFILE "/etc/named.pid"
  10. #define NAMED    "/etc/named"
  11.  
  12. main() {
  13.     int pid;
  14.  
  15.     if (-1 == (pid = read_pidfile(PIDFILE))) {
  16.         perror(PIDFILE);
  17.         exit(2);
  18.     }
  19.  
  20.     if (0 > kill(pid, SIGHUP)) {
  21.         int start_new = (errno == ESRCH);
  22.         perror("kill");
  23.         if (start_new) {
  24.             execl(NAMED, NAMED, NULL);
  25.             perror("execl");
  26.         }
  27.         exit(2);
  28.     }
  29.  
  30.     exit(0);
  31. }
  32.  
  33. int
  34. read_pidfile(filename)
  35.     char *filename;
  36. {
  37.     FILE *pidfile = fopen(filename, "r");
  38.     char line[10];
  39.     int pid, error;
  40.  
  41.     if (!pidfile)
  42.         return -1;
  43.     error = (!fgets(line, sizeof line, pidfile));
  44.     fclose(pidfile);
  45.     if (error)
  46.         return -1;
  47.     pid = atoi(line);
  48.     if (!pid)
  49.         return -1;
  50.     return pid;
  51. }
  52.