Solaris - fix a couple of warnings for message formatting
[valgrind.git] / none / tests / coolo_sigaction.cpp
blob395690a802d0647067addb9e430655915b5b2a5c
2 #include <signal.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 static struct sigaction oldChildHandlerData;
9 void theHandler(int arg)
11 printf("handled %s\n", arg == SIGCHLD ? "SIGCHLD" : "?!unexpected signal?!" );
14 void setupHandlers()
16 struct sigaction act;
17 act.sa_handler=theHandler;
18 sigemptyset(&(act.sa_mask));
19 sigaddset(&(act.sa_mask), SIGCHLD);
20 // Make sure we don't block this signal. gdb tends to do that :-(
21 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0);
23 act.sa_flags = SA_NOCLDSTOP;
25 // CC: take care of SunOS which automatically restarts interrupted system
26 // calls (and thus does not have SA_RESTART)
28 #ifdef SA_RESTART
29 act.sa_flags |= SA_RESTART;
30 #endif
32 sigaction( SIGCHLD, &act, &oldChildHandlerData );
34 act.sa_handler=SIG_IGN;
35 sigemptyset(&(act.sa_mask));
36 sigaddset(&(act.sa_mask), SIGPIPE);
37 act.sa_flags = 0;
38 sigaction( SIGPIPE, &act, 0L);
41 int main()
43 char buffer[200];
44 setupHandlers();
45 FILE *p = popen("echo Hallo World", "r");
46 while (!feof(p)) {
47 int n = fread(buffer, 200, 1, p);
48 __attribute__((unused)) ssize_t nw = write(2, buffer, n);
50 pclose(p);
51 return 0;