summaryrefslogtreecommitdiff
path: root/xc/test/xsuite/port/signals.c
blob: f69f7381ad18fc1d206d378157e69fac4da926d4 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* $XConsortium$ */
#include <signal.h>
#include <errno.h>

extern int errno;

sigemptyset(set)
sigset_t *set;
{
	*set = 0;
	return 0;
}

sigfillset(set)
sigset_t *set;
{
	*set = 0xffffffff;
	return 0;
}

sigaddset(set, sig)
sigset_t *set;
int sig;
{
	if (sig < 1 || sig >= NSIG)
	{
		errno = EINVAL;
		return -1;
	}
	*set |= (1 << (sig-1));
	return 0;
}

sigdelset(set, sig)
sigset_t *set;
int sig;
{
	if (sig < 1 || sig >= NSIG)
	{
		errno = EINVAL;
		return -1;
	}
	*set &= ~(1 << (sig-1));
	return 0;
}

sigismember(set, sig)
sigset_t *set;
int sig;
{
	if (sig < 1 || sig >= NSIG)
	{
		errno = EINVAL;
		return -1;
	}
	return ((*set & (1 << (sig-1))) != 0);
}

sigaction(sig, act, oact)
int sig;
struct sigaction *act, *oact;
{
	int ret;

	/*
	 * This is what we do for now: zero sa_flags so that the sigaction
	 * structures can be passed to th BSD sigvec() as if they
	 * were sigvec structures.
	 */

#if 1
	/* Put in a trap so we know when assumption becomes wrong */
	if (act && act->sa_flags != 0) {
		printf("sa_flags != 0\n");
		exit(123);
	}
#endif

	if (act)
		act->sa_flags = 0;
	ret = sigvec(sig, act, oact);
	if (oact)
		oact->sa_flags = 0;

	return ret;
}

sigprocmask(how, set, oset)
int how;
sigset_t *set, *oset;
{
	sigset_t omask;

	if (set != 0)
		switch (how) {
		case SIG_BLOCK :
			omask = sigblock(*set);
			break;
		case SIG_UNBLOCK :
			omask = sigblock((sigset_t)0);
			omask = sigsetmask(omask & ~*set);
			break;
		case SIG_SETMASK :
			omask = sigsetmask(*set);
			break;
		default :
			errno = EINVAL;
			return -1;
		}
	else
		omask = sigblock((sigset_t)0);

	if (oset != 0)
		*oset = omask;
	
	return 0;
}

/* ARGSUSED */
sigpending(set)
sigset_t *set;
{
#ifdef ENOSYS
	errno = ENOSYS;
#else
	/*
	 * BSD4.2 doesn't have a suitable eqivalent to ENOSYS.
	 */
	errno = EINVAL;
#endif
	return -1;
}

sigsuspend(mask)
sigset_t *mask;
{
	(void) sigpause(*mask);
	return -1;
}