summaryrefslogtreecommitdiff
path: root/utils/testsignal.cc
blob: eda5bb5151851a366139d218160e957d49deca30 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#include "Signal.h"

#if 0
extern "C" {
	int write (int, const void*, unsigned int);
	int strlen (const char*);
}
#endif

const char* signal_strings [32] = {
	"SIGHUP\n",
	"SIGINT\n",
	"SIGQUIT\n",
	"SIGILL\n",
	"SIGTRAP\n",
	"SIGABRT\n",
	"SIGEMT\n",
	"SIGFPE\n",
	"SIGKILL\n",
	"SIGBUS\n",
	"SIGSEGV\n",
	"SIGSYS\n",
	"SIGPIPE\n",
	"SIGALRM\n",
	"SIGTERM\n",
	"SIGUSR1\n",
	"SIGUSR2\n",
	"SIGCHLD\n",
	"SIGPWR\n",
	"SIGVTALRM\n",
	"SIGPROF\n",
	"SIGIO\n",
	"SIGWINDOW\n",
	"SIGSTOP\n",
	"SIGTSTP\n",
	"SIGCONT\n",
	"SIGTTIN\n",
	"SIGTTOU\n",
	"SIGURG\n",
	"SIGLOST\n",
	"SIGRESERVE\n",
	"SIGDIL\n"
};

void
outputsig (int sig)
{
	write (1, signal_strings [sig-1], strlen (signal_strings [sig-1]));
}

void
ignoresig (int)
{
}

main ()
{
	{
		printf ("block signal 2\n");
		IvlSignalBlocker b (2);
		getchar ();
	}
	printf ("print signals 1 and 2\n");
	IvlSignalHandler s1 (1, outputsig);
	IvlSignalHandler s3 (2, outputsig);
	getchar ();
	{
		printf ("ignore signal 1\n");
		IvlSignalHandler s2 (1, ignoresig);
		getchar ();
	}
	printf ("print again signal 1\n");
	while (1);
}