File: dmtcp4.c

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (42 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SA_ONSTACK and SA_RESETHAND are _XOPEN_SOURCE according to POSIX OpenGroup
// But gcc-4.8 -std=c11 seems to require _GNU_SOURCE for these two macros.
#define _GNU_SOURCE
// sigaction() needs _XOPEN_SOURCE or _POSIX_SOURCE
#define _XOPEN_SOURCE
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>

void myGroovyHandler(int i){
  printf("yay signals!!!\n");
}

int main(int argc, char* argv[]){
  alarm(1);
  while (1){
    signal(SIGUSR1, &myGroovyHandler);
    signal(SIGUSR2, &myGroovyHandler);
    signal(SIGALRM, &myGroovyHandler);

    sigset_t set;
    sigfillset(&set);
    sigdelset(&set, SIGALRM);
    sigdelset(&set, SIGTERM);
    sigdelset(&set, SIGSTOP);
    sigdelset(&set, SIGSEGV);
    sigdelset(&set, SIGINT);  // Let user and autotest.py kill it.
    sigprocmask(SIG_BLOCK, &set, NULL);
    pthread_sigmask(SIG_BLOCK, &set, NULL);

    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_handler = &myGroovyHandler;
    sigfillset(&act.sa_mask);
    act.sa_flags = SA_ONSTACK | SA_RESETHAND;
    sigaction(SIGUSR1, &act, NULL);
    sigaction(SIGUSR2, &act, NULL);
    sigaction(SIGALRM, &act, NULL);
  }
  return 0;
}