diff options
author | PA4WDH | 2024-09-12 13:58:56 +0200 |
---|---|---|
committer | PA4WDH | 2024-09-12 13:58:56 +0200 |
commit | bcdcc64c373b5db66b8e07ab6529ede2d983e036 (patch) | |
tree | d5fd68c7059b46b643abc23dfa3270086ad1afd4 /cpulist.c | |
parent | Add cpufreq_get_long_int as generic function to get cpufreq data (diff) | |
download | cputemp2maxfreq-bcdcc64c373b5db66b8e07ab6529ede2d983e036.tar.gz cputemp2maxfreq-bcdcc64c373b5db66b8e07ab6529ede2d983e036.tar.bz2 cputemp2maxfreq-bcdcc64c373b5db66b8e07ab6529ede2d983e036.zip |
Improve signal handling
Diffstat (limited to 'cpulist.c')
-rw-r--r-- | cpulist.c | 12 |
1 files changed, 12 insertions, 0 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) { |