Skip to content

Commit 746d64e

Browse files
Whoopieevgeni
authored andcommitted
use sigaction(2) instead of signal(2) for handling SIGUSR1/SIGTERM
Debian-Bug: https://bugs.debian.org/770069
1 parent ded5869 commit 746d64e

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/hdapsd.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
# endif
5858
#endif
5959

60+
static volatile int pause_now = 0;
61+
static volatile int running = 1;
6062
static int verbose = 0;
61-
static int pause_now = 0;
6263
static int dry_run = 0;
6364
static int poll_sysfs = 0;
6465
static int hardware_logic = 0;
6566
static int force_software_logic = 0;
6667
static int sampling_rate = 0;
67-
static int running = 1;
6868
static int background = 0;
6969
static int dosyslog = 0;
7070
static int forcerotational = 0;
@@ -367,17 +367,19 @@ double get_utime (void)
367367
*/
368368
void SIGUSR1_handler (int sig)
369369
{
370-
signal(SIGUSR1, SIGUSR1_handler);
371370
pause_now = 1;
371+
if (verbose)
372+
printlog(stdout, "SIGUSR1 called, pause_now is %d", pause_now);
372373
}
373374

374375
/*
375376
* SIGTERM_handler - Handler for SIGTERM, deletes the pidfile and exits.
376377
*/
377378
void SIGTERM_handler (int sig)
378379
{
379-
signal(SIGTERM, SIGTERM_handler);
380380
running = 0;
381+
if (verbose)
382+
printlog(stdout, "SIGTERM called, running is %d", running);
381383
}
382384

383385
/*
@@ -1206,9 +1208,17 @@ int main (int argc, char** argv)
12061208
if (verbose)
12071209
printf("sampling_rate: %d\n", sampling_rate);
12081210

1209-
signal(SIGUSR1, SIGUSR1_handler);
1211+
struct sigaction sa;
1212+
sigemptyset (&sa.sa_mask);
1213+
sa.sa_flags = 0;
1214+
1215+
/* Register the handler for SIGUSR1. */
1216+
sa.sa_handler = SIGUSR1_handler;
1217+
sigaction (SIGUSR1, &sa, NULL);
12101218

1211-
signal(SIGTERM, SIGTERM_handler);
1219+
/* Register the handler for SIGTERM. */
1220+
sa.sa_handler = SIGTERM_handler;
1221+
sigaction (SIGTERM, &sa, NULL);
12121222

12131223
while (running) {
12141224
if (!hardware_logic) { /* The decision is made by the software */

0 commit comments

Comments
 (0)