Show
Ignore:
Timestamp:
05/13/09 18:11:57 (4 years ago)
Author:
andy
Message:

Replace the deprecated signal() function by sigaction().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/sensord/sensord.c

    r5722 r5723  
    6666static void signalHandler(int sig) 
    6767{ 
    68         signal(sig, signalHandler); 
    6968        switch (sig) { 
    7069        case SIGTERM: 
     
    148147} 
    149148 
     149static void install_sighandler(void) 
     150{ 
     151        struct sigaction new; 
     152        int ret; 
     153 
     154        memset(&new, 0, sizeof(struct sigaction)); 
     155        new.sa_handler = signalHandler; 
     156        sigemptyset(&new.sa_mask); 
     157        new.sa_flags = SA_RESTART; 
     158 
     159        ret = sigaction(SIGTERM, &new, NULL); 
     160        if (ret == -1) { 
     161                fprintf(stderr, "Could not set sighandler for SIGTERM: %s\n", 
     162                        strerror(errno)); 
     163                exit(EXIT_FAILURE); 
     164        } 
     165 
     166        ret = sigaction(SIGHUP, &new, NULL); 
     167        if (ret == -1) { 
     168                fprintf(stderr, "Could not set sighandler for SIGHUP: %s\n", 
     169                        strerror(errno)); 
     170                exit(EXIT_FAILURE); 
     171        } 
     172} 
     173 
    150174static void daemonize(void) 
    151175{ 
     
    173197        } 
    174198 
    175         /* I should use sigaction but... */ 
    176         if (signal(SIGTERM, signalHandler) == SIG_ERR || 
    177             signal (SIGHUP, signalHandler) == SIG_ERR) { 
    178                 perror("signal"); 
    179                 exit(EXIT_FAILURE); 
    180         } 
     199        install_sighandler(); 
    181200 
    182201        if ((pid = fork()) == -1) {