aboutsummaryrefslogtreecommitdiff
path: root/none/tests/coolo_sigaction.cpp
blob: 7baa4aef4289ed46bf5533a02c25d427365947ce (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static struct sigaction oldChildHandlerData;

void theHandler(int arg)
{
  printf("handled %d\n", arg);
}

void setupHandlers()
{
  struct sigaction act;
  act.sa_handler=theHandler;
  sigemptyset(&(act.sa_mask));
  sigaddset(&(act.sa_mask), SIGCHLD);
  // Make sure we don't block this signal. gdb tends to do that :-(
  sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0);

  act.sa_flags = SA_NOCLDSTOP;

  // CC: take care of SunOS which automatically restarts interrupted system
  // calls (and thus does not have SA_RESTART)

#ifdef SA_RESTART
  act.sa_flags |= SA_RESTART;
#endif

  sigaction( SIGCHLD, &act, &oldChildHandlerData );

  act.sa_handler=SIG_IGN;
  sigemptyset(&(act.sa_mask));
  sigaddset(&(act.sa_mask), SIGPIPE);
  act.sa_flags = 0;
  sigaction( SIGPIPE, &act, 0L);
}

int main()
{
    int i;
    char buffer[200];
    size_t dummy_size_t;
    setupHandlers();
    FILE *p = popen("echo Hallo World", "r");
    while (!feof(p)) {
        int n = fread(buffer, 200, 1, p);
        dummy_size_t = write(2, buffer, n);
    }
    fclose(p);
    for (i = 0; i < 1000000; i++) ;
    return 0;
}