Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / solaris / door_kill.c
blob06874c07571645b48aa694f1af0e2153af46fda4
1 /* Test cancellation of a door_return call. */
3 #include <assert.h>
4 #include <door.h>
5 #include <errno.h>
6 #include <pthread.h>
7 #include <signal.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <sys/lwp.h>
12 #include <unistd.h>
14 static volatile lwpid_t server_lwpid = 0;
16 static void server_procedure(void *cookie, char *argp, size_t arg_size,
17 door_desc_t *dp, uint_t n_desc)
19 assert(0);
22 static void *my_server_thread(void *arg)
24 server_lwpid = _lwp_self();
25 door_return(NULL, 0, NULL, 0);
26 return NULL;
29 static void create_door_thread(door_info_t *info)
31 static int called = 0;
32 pthread_t thread;
33 int res;
35 /* Allow to create only one server door thread. */
36 assert(!called);
37 called = 1;
39 res = pthread_create(&thread, NULL, my_server_thread, NULL);
40 if (res) {
41 errno = res;
42 perror("pthread_create");
43 exit(1);
47 static void signal_handler(int signo, siginfo_t *info, void *uc)
49 const char str[] = "Signal caught.\n";
50 size_t len = sizeof(str) - 1;
51 ssize_t res;
53 res = write(STDOUT_FILENO, str, len);
54 assert(res == len);
57 int main(void)
59 int res = 1;
60 int did = -1;
61 struct sigaction sa;
63 sa.sa_sigaction = signal_handler;
64 sa.sa_flags = SA_RESTART;
65 if (sigfillset(&sa.sa_mask)) {
66 perror("sigfillset");
67 return 1;
69 if (sigaction(SIGINT, &sa, NULL)) {
70 perror("sigaction");
71 return 1;
74 door_server_create(create_door_thread);
76 if ((did = door_create(server_procedure, NULL, 0)) < 0) {
77 perror("door_create");
78 return 1;
81 /* Let the server thread to run. */
82 sleep(2);
84 /* Send a signal to the server thread that should be already created and
85 blocked in door_return. */
86 if (_lwp_kill(server_lwpid, SIGINT)) {
87 perror("_lwp_kill");
88 goto out;
91 /* Let the other thread to run. */
92 sleep(2);
94 res = 0;
96 out:
97 if (did >= 0 && door_revoke(did))
98 perror("door_revoke");
100 return res;