2
#include <sys/socket.h>
15
gboolean thread_exit = FALSE;
16
gboolean thread_started;
17
GCond *thread_startup;
19
pthread_t thread_handle;
22
sigusr1_handler(int signo)
31
memset(&sa, 0, sizeof(sa));
32
/* NOTE: this has to be a real signal handler as SIG_IGN will not interrupt the accept call below */
33
sa.sa_handler = sigusr1_handler;
35
sigaction(SIGUSR1, &sa, NULL);
41
thread_handle = pthread_self();
42
g_mutex_lock(thread_lock);
43
thread_started = TRUE;
44
g_cond_signal(thread_startup);
45
g_mutex_unlock(thread_lock);
49
create_test_thread(GThreadFunc thread_func, gpointer data)
52
struct timespec nsleep;
55
thread_started = FALSE;
56
t = g_thread_create(thread_func, data, TRUE, NULL);
57
g_mutex_lock(thread_lock);
58
while (!thread_started)
59
g_cond_wait(thread_startup, thread_lock);
60
g_mutex_unlock(thread_lock);
63
nanosleep(&nsleep, NULL);
65
pthread_kill(thread_handle, SIGUSR1);
66
return (g_thread_join(t) != NULL);
72
accept_thread_func(gpointer args)
74
struct sockaddr_un peer;
76
gpointer result = NULL;
83
socklen_t peer_size = sizeof(peer);
85
new_sock = accept(sock, (struct sockaddr *) &peer, &peer_size);
92
fprintf(stderr, "accept woken up, errno=%s\n", g_strerror(err));
93
result = (gpointer) 0x1;
104
struct sockaddr_un s;
107
sock = socket(PF_UNIX, SOCK_STREAM, 0);
108
s.sun_family = AF_UNIX;
109
strcpy(s.sun_path, "almafa");
110
if (bind(sock, (struct sockaddr *) &s, sizeof(s)) < 0)
112
perror("error binding socket");
115
if (listen(sock, 255) < 0)
117
perror("error in listen()");
120
return create_test_thread(accept_thread_func, NULL);
124
read_thread_func(gpointer args)
126
gint *pair = (gint *) args;
127
gpointer result = NULL;
137
count = read(pair[1], buf, sizeof(buf));
142
fprintf(stderr, "read woken up, errno=%s\n", g_strerror(err));
143
result = (gpointer) 0x1;
157
socketpair(PF_UNIX, SOCK_STREAM, 0, pair);
158
return create_test_thread(read_thread_func, pair);
162
main(int argc, char *argv[])
166
thread_lock = g_mutex_new();
167
thread_startup = g_cond_new();
169
if (!test_accept_wakeup() ||