1 |
|
|
/* $OpenBSD: rthread_sig.c,v 1.18 2016/05/07 19:05:22 guenther Exp $ */ |
2 |
|
|
/* |
3 |
|
|
* Copyright (c) 2005 Ted Unangst <tedu@openbsd.org> |
4 |
|
|
* All Rights Reserved. |
5 |
|
|
* |
6 |
|
|
* Permission to use, copy, modify, and distribute this software for any |
7 |
|
|
* purpose with or without fee is hereby granted, provided that the above |
8 |
|
|
* copyright notice and this permission notice appear in all copies. |
9 |
|
|
* |
10 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 |
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 |
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 |
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 |
|
|
*/ |
18 |
|
|
/* |
19 |
|
|
* signals |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <signal.h> |
23 |
|
|
#include <errno.h> |
24 |
|
|
|
25 |
|
|
#include <pthread.h> |
26 |
|
|
|
27 |
|
|
#include "rthread.h" |
28 |
|
|
#include "cancel.h" /* in libc/include */ |
29 |
|
|
|
30 |
|
|
int |
31 |
|
|
sigwait(const sigset_t *set, int *sig) |
32 |
|
|
{ |
33 |
|
88 |
sigset_t s = *set; |
34 |
|
|
int ret; |
35 |
|
|
|
36 |
|
44 |
sigdelset(&s, SIGTHR); |
37 |
|
44 |
do { |
38 |
✓✗✗✓
|
88 |
ENTER_CANCEL_POINT(1); |
39 |
|
40 |
ret = __thrsigdivert(s, NULL, NULL); |
40 |
✓✗✗✓ ✗✗ |
80 |
LEAVE_CANCEL_POINT(ret == -1); |
41 |
✗✓✗✗
|
40 |
} while (ret == -1 && errno == EINTR); |
42 |
✗✓ |
40 |
if (ret == -1) |
43 |
|
|
return (errno); |
44 |
|
40 |
*sig = ret; |
45 |
|
40 |
return (0); |
46 |
|
40 |
} |
47 |
|
|
|
48 |
|
|
#if 0 /* need kernel to fill in more siginfo_t bits first */ |
49 |
|
|
int |
50 |
|
|
sigwaitinfo(const sigset_t *set, siginfo_t *info) |
51 |
|
|
{ |
52 |
|
|
sigset_t s = *set; |
53 |
|
|
int ret; |
54 |
|
|
|
55 |
|
|
sigdelset(&s, SIGTHR); |
56 |
|
|
ENTER_CANCEL_POINT(1); |
57 |
|
|
ret = __thrsigdivert(s, info, NULL); |
58 |
|
|
LEAVE_CANCEL_POINT(ret == -1); |
59 |
|
|
return (ret); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
int |
63 |
|
|
sigtimedwait(const sigset_t *set, siginfo_t *info, |
64 |
|
|
const struct timespec *timeout) |
65 |
|
|
{ |
66 |
|
|
sigset_t s = *set; |
67 |
|
|
int ret; |
68 |
|
|
|
69 |
|
|
sigdelset(&s, SIGTHR); |
70 |
|
|
ENTER_CANCEL_POINT(1); |
71 |
|
|
ret = __thrsigdivert(s, info, timeout); |
72 |
|
|
LEAVE_CANCEL_POINT(ret == -1); |
73 |
|
|
return (ret); |
74 |
|
|
} |
75 |
|
|
#endif |