diff options
-rw-r--r-- | cpulist.c | 12 | ||||
-rw-r--r-- | cputemp2maxfreq.c | 12 |
2 files changed, 21 insertions, 3 deletions
@@ -24,6 +24,7 @@ #include <dirent.h> #include <sys/types.h> #include <stdlib.h> +#include <signal.h> #include "debug.h" #include "sysfs.h" #include "cputemp2maxfreq.h" @@ -68,6 +69,7 @@ int cpulist_find_cpus() struct dirent *cpu_dirent; char sysfs_file[309]; int package; + sigset_t newset, oldset; DEBUG1_CPULIST("Started\n") @@ -78,6 +80,13 @@ int cpulist_find_cpus() } cpudata.cpulist_len=0; +// Block signals to prevent malloc/free race conditions + sigemptyset(&newset); + sigaddset(&newset,SIGTERM); + sigaddset(&newset,SIGINT); + sigaddset(&newset,SIGQUIT); + sigprocmask(SIG_BLOCK,&newset,&oldset); + // Open the CPU directory in sysfs cpudir=opendir("/sys/devices/system/cpu"); if (cpudir==NULL) @@ -110,6 +119,9 @@ int cpulist_find_cpus() } closedir(cpudir); +// Restore signal mask + sigprocmask(SIG_SETMASK,&oldset,NULL); + DEBUG1_CPULIST("Found %d CPU's\n",config.cpulist_len); if (cpudata.cpulist_len==0) { diff --git a/cputemp2maxfreq.c b/cputemp2maxfreq.c index d146158..212fb39 100644 --- a/cputemp2maxfreq.c +++ b/cputemp2maxfreq.c @@ -92,6 +92,7 @@ int main(int argc,char **argv) struct s_sensor sensor; char *transition_latency_remark; char sensor_string[20]; + struct sigaction sigact={0}; argparse(argc,argv); config.logger("%s version %s, buildtime %s %s",config.name,version(),__DATE__,__TIME__); @@ -263,9 +264,14 @@ int main(int argc,char **argv) if (config.csvlog[0]!=0) csvlog_init(); // Set signal handlers - signal(SIGTERM,signal_handler); - signal(SIGINT,signal_handler); - signal(SIGQUIT,signal_handler); + sigact.sa_handler=&signal_handler; + sigemptyset(&sigact.sa_mask); + sigaddset(&sigact.sa_mask,SIGTERM); + sigaddset(&sigact.sa_mask,SIGINT); + sigaddset(&sigact.sa_mask,SIGQUIT); + sigaction(SIGTERM,&sigact,NULL); + sigaction(SIGINT,&sigact,NULL); + sigaction(SIGQUIT,&sigact,NULL); while(1) { |