daemon.c
changeset 131 b5ad49852adc
parent 79 1499176750b9
child 138 dff18d1ac2af
equal deleted inserted replaced
130:f4b424b93e45 131:b5ad49852adc
    30 
    30 
    31     t = time (NULL);
    31     t = time (NULL);
    32     strftime (time_stamp, sizeof (time_stamp), "%a %d %T", localtime (&t));
    32     strftime (time_stamp, sizeof (time_stamp), "%a %d %T", localtime (&t));
    33     len = snprintf (response, sizeof (response), "%s %s", time_stamp, buffer);
    33     len = snprintf (response, sizeof (response), "%s %s", time_stamp, buffer);
    34 
    34 
    35     write (fd, response, len);
    35     if (write (fd, response, len) == -1)
       
    36         perror ("write");
    36 }
    37 }
    37 
    38 
    38 void sigproc ()
    39 void sigproc ()
    39 {
    40 {
    40     if (unlink (LOCK_FILE) == 0)
    41     if (unlink (LOCK_FILE) == 0)
    78     static char buffer[MAXLEN];
    79     static char buffer[MAXLEN];
    79     int fd;
    80     int fd;
    80 
    81 
    81     sanity_check (argc, argv);
    82     sanity_check (argc, argv);
    82 
    83 
    83     daemon (0, 0);
    84     if (daemon (0, 0) == -1) {
       
    85         perror ("daemon");
       
    86         return EXIT_FAILURE;
       
    87     }
    84     signal (SIGTERM, sigproc);
    88     signal (SIGTERM, sigproc);
    85 
    89 
    86     for (;;) {
    90     for (;;) {
    87         if ((fd = open (OUTPUT_FILE, O_WRONLY | O_CREAT, 0644)) < 0)
    91         if ((fd = open (OUTPUT_FILE, O_WRONLY | O_CREAT, 0644)) < 0)
    88             return EXIT_FAILURE;
    92             return EXIT_FAILURE;