From bcdcc64c373b5db66b8e07ab6529ede2d983e036 Mon Sep 17 00:00:00 2001 From: PA4WDH Date: Thu, 12 Sep 2024 13:58:56 +0200 Subject: Improve signal handling --- cpulist.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cpulist.c') diff --git a/cpulist.c b/cpulist.c index c8cc7a5..4496764 100644 --- a/cpulist.c +++ b/cpulist.c @@ -24,6 +24,7 @@ #include #include #include +#include #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) { -- cgit v1.2.3