]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
89ffcd2a | 2 | /*** |
89ffcd2a LP |
3 | ***/ |
4 | ||
cf0fbc49 | 5 | #include <fcntl.h> |
89ffcd2a | 6 | #include <pthread.h> |
cf0fbc49 | 7 | #include <stdlib.h> |
e3017af9 | 8 | #include <unistd.h> |
89ffcd2a | 9 | |
89ffcd2a | 10 | #include "sd-bus.h" |
07630cea | 11 | |
b5efdb8a | 12 | #include "alloc-util.h" |
e3017af9 | 13 | #include "bus-error.h" |
392d5b37 | 14 | #include "bus-internal.h" |
07630cea | 15 | #include "bus-match.h" |
057171ef | 16 | #include "bus-util.h" |
cf0fbc49 | 17 | #include "fd-util.h" |
f97b34a6 | 18 | #include "format-util.h" |
07630cea LP |
19 | #include "log.h" |
20 | #include "macro.h" | |
21 | #include "util.h" | |
392d5b37 | 22 | |
19070062 | 23 | static int match_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
392d5b37 LP |
24 | log_info("Match triggered! interface=%s member=%s", strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member(m))); |
25 | return 0; | |
26 | } | |
89ffcd2a | 27 | |
19070062 | 28 | static int object_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
a652755d LP |
29 | int r; |
30 | ||
eb01ba5d | 31 | if (sd_bus_message_is_method_error(m, NULL)) |
a652755d LP |
32 | return 0; |
33 | ||
34 | if (sd_bus_message_is_method_call(m, "org.object.test", "Foobar")) { | |
a652755d LP |
35 | log_info("Invoked Foobar() on %s", sd_bus_message_get_path(m)); |
36 | ||
df2d202e | 37 | r = sd_bus_reply_method_return(m, NULL); |
f647962d MS |
38 | if (r < 0) |
39 | return log_error_errno(r, "Failed to send reply: %m"); | |
a652755d LP |
40 | |
41 | return 1; | |
42 | } | |
43 | ||
44 | return 0; | |
45 | } | |
46 | ||
89ffcd2a LP |
47 | static int server_init(sd_bus **_bus) { |
48 | sd_bus *bus = NULL; | |
d728d708 | 49 | sd_id128_t id; |
89ffcd2a | 50 | int r; |
56fbd718 | 51 | const char *unique, *desc; |
89ffcd2a | 52 | |
0c0cdb06 | 53 | assert_se(_bus); |
89ffcd2a | 54 | |
56fbd718 | 55 | r = sd_bus_open_user_with_description(&bus, "my bus!"); |
89ffcd2a | 56 | if (r < 0) { |
da927ba9 | 57 | log_error_errno(r, "Failed to connect to user bus: %m"); |
89ffcd2a LP |
58 | goto fail; |
59 | } | |
60 | ||
5c302692 | 61 | r = sd_bus_get_bus_id(bus, &id); |
d728d708 | 62 | if (r < 0) { |
da927ba9 | 63 | log_error_errno(r, "Failed to get server ID: %m"); |
d728d708 LP |
64 | goto fail; |
65 | } | |
66 | ||
20902f3e LP |
67 | r = sd_bus_get_unique_name(bus, &unique); |
68 | if (r < 0) { | |
da927ba9 | 69 | log_error_errno(r, "Failed to get unique name: %m"); |
20902f3e LP |
70 | goto fail; |
71 | } | |
72 | ||
56fbd718 ZJS |
73 | r = sd_bus_get_description(bus, &desc); |
74 | assert_se(streq(desc, "my bus!")); | |
75 | ||
d728d708 | 76 | log_info("Peer ID is " SD_ID128_FORMAT_STR ".", SD_ID128_FORMAT_VAL(id)); |
20902f3e | 77 | log_info("Unique ID: %s", unique); |
d728d708 | 78 | log_info("Can send file handles: %i", sd_bus_can_send(bus, 'h')); |
d728d708 | 79 | |
89ffcd2a LP |
80 | r = sd_bus_request_name(bus, "org.freedesktop.systemd.test", 0); |
81 | if (r < 0) { | |
da927ba9 | 82 | log_error_errno(r, "Failed to acquire name: %m"); |
89ffcd2a LP |
83 | goto fail; |
84 | } | |
85 | ||
19befb2d | 86 | r = sd_bus_add_fallback(bus, NULL, "/foo/bar", object_callback, NULL); |
a652755d | 87 | if (r < 0) { |
da927ba9 | 88 | log_error_errno(r, "Failed to add object: %m"); |
a652755d LP |
89 | goto fail; |
90 | } | |
91 | ||
75152a4d | 92 | r = sd_bus_match_signal(bus, NULL, NULL, NULL, "foo.bar", "Notify", match_callback, NULL); |
392d5b37 | 93 | if (r < 0) { |
75152a4d | 94 | log_error_errno(r, "Failed to request match: %m"); |
392d5b37 LP |
95 | goto fail; |
96 | } | |
97 | ||
19befb2d | 98 | r = sd_bus_add_match(bus, NULL, "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged'", match_callback, NULL); |
392d5b37 | 99 | if (r < 0) { |
da927ba9 | 100 | log_error_errno(r, "Failed to add match: %m"); |
392d5b37 LP |
101 | goto fail; |
102 | } | |
103 | ||
104 | bus_match_dump(&bus->match_callbacks, 0); | |
105 | ||
89ffcd2a LP |
106 | *_bus = bus; |
107 | return 0; | |
108 | ||
109 | fail: | |
3e044c49 | 110 | sd_bus_unref(bus); |
89ffcd2a LP |
111 | return r; |
112 | } | |
113 | ||
e3017af9 | 114 | static int server(sd_bus *bus) { |
89ffcd2a | 115 | int r; |
e3017af9 | 116 | bool client1_gone = false, client2_gone = false; |
89ffcd2a | 117 | |
e3017af9 | 118 | while (!client1_gone || !client2_gone) { |
4afd3348 | 119 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; |
2571ead1 | 120 | pid_t pid = 0; |
4a875b61 | 121 | const char *label = NULL; |
89ffcd2a LP |
122 | |
123 | r = sd_bus_process(bus, &m); | |
124 | if (r < 0) { | |
da927ba9 | 125 | log_error_errno(r, "Failed to process requests: %m"); |
89ffcd2a LP |
126 | goto fail; |
127 | } | |
e3017af9 | 128 | |
89ffcd2a LP |
129 | if (r == 0) { |
130 | r = sd_bus_wait(bus, (uint64_t) -1); | |
131 | if (r < 0) { | |
da927ba9 | 132 | log_error_errno(r, "Failed to wait: %m"); |
89ffcd2a LP |
133 | goto fail; |
134 | } | |
135 | ||
136 | continue; | |
137 | } | |
138 | ||
e3017af9 LP |
139 | if (!m) |
140 | continue; | |
141 | ||
5b12334d LP |
142 | sd_bus_creds_get_pid(sd_bus_message_get_creds(m), &pid); |
143 | sd_bus_creds_get_selinux_context(sd_bus_message_get_creds(m), &label); | |
de0671ee | 144 | log_info("Got message! member=%s pid="PID_FMT" label=%s", |
4a875b61 | 145 | strna(sd_bus_message_get_member(m)), |
de0671ee | 146 | pid, |
4a875b61 | 147 | strna(label)); |
89ffcd2a LP |
148 | /* bus_message_dump(m); */ |
149 | /* sd_bus_message_rewind(m, true); */ | |
150 | ||
151 | if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "LowerCase")) { | |
152 | const char *hello; | |
153 | _cleanup_free_ char *lowercase = NULL; | |
154 | ||
155 | r = sd_bus_message_read(m, "s", &hello); | |
156 | if (r < 0) { | |
da927ba9 | 157 | log_error_errno(r, "Failed to get parameter: %m"); |
89ffcd2a LP |
158 | goto fail; |
159 | } | |
160 | ||
89ffcd2a LP |
161 | lowercase = strdup(hello); |
162 | if (!lowercase) { | |
163 | r = log_oom(); | |
164 | goto fail; | |
165 | } | |
166 | ||
167 | ascii_strlower(lowercase); | |
168 | ||
df2d202e | 169 | r = sd_bus_reply_method_return(m, "s", lowercase); |
89ffcd2a | 170 | if (r < 0) { |
da927ba9 | 171 | log_error_errno(r, "Failed to send reply: %m"); |
89ffcd2a LP |
172 | goto fail; |
173 | } | |
e3017af9 LP |
174 | } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "ExitClient1")) { |
175 | ||
df2d202e | 176 | r = sd_bus_reply_method_return(m, NULL); |
e3017af9 | 177 | if (r < 0) { |
da927ba9 | 178 | log_error_errno(r, "Failed to send reply: %m"); |
e3017af9 LP |
179 | goto fail; |
180 | } | |
181 | ||
182 | client1_gone = true; | |
183 | } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "ExitClient2")) { | |
184 | ||
df2d202e | 185 | r = sd_bus_reply_method_return(m, NULL); |
e3017af9 | 186 | if (r < 0) { |
da927ba9 | 187 | log_error_errno(r, "Failed to send reply: %m"); |
e3017af9 LP |
188 | goto fail; |
189 | } | |
190 | ||
191 | client2_gone = true; | |
192 | } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "Slow")) { | |
193 | ||
b7f247e0 LP |
194 | sleep(1); |
195 | ||
df2d202e | 196 | r = sd_bus_reply_method_return(m, NULL); |
e3017af9 | 197 | if (r < 0) { |
da927ba9 | 198 | log_error_errno(r, "Failed to send reply: %m"); |
e3017af9 LP |
199 | goto fail; |
200 | } | |
201 | ||
2c93b4ef LP |
202 | } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "FileDescriptor")) { |
203 | int fd; | |
204 | static const char x = 'X'; | |
205 | ||
206 | r = sd_bus_message_read(m, "h", &fd); | |
207 | if (r < 0) { | |
da927ba9 | 208 | log_error_errno(r, "Failed to get parameter: %m"); |
2c93b4ef LP |
209 | goto fail; |
210 | } | |
211 | ||
5a330cda ZJS |
212 | log_info("Received fd=%d", fd); |
213 | ||
2c93b4ef | 214 | if (write(fd, &x, 1) < 0) { |
56f64d95 | 215 | log_error_errno(errno, "Failed to write to fd: %m"); |
03e334a1 | 216 | safe_close(fd); |
2c93b4ef LP |
217 | goto fail; |
218 | } | |
219 | ||
df2d202e | 220 | r = sd_bus_reply_method_return(m, NULL); |
2c93b4ef | 221 | if (r < 0) { |
da927ba9 | 222 | log_error_errno(r, "Failed to send reply: %m"); |
2c93b4ef LP |
223 | goto fail; |
224 | } | |
225 | ||
e3017af9 | 226 | } else if (sd_bus_message_is_method_call(m, NULL, NULL)) { |
89ffcd2a | 227 | |
d4100e24 | 228 | r = sd_bus_reply_method_error( |
df2d202e | 229 | m, |
14c24659 | 230 | &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_UNKNOWN_METHOD, "Unknown method.")); |
89ffcd2a | 231 | if (r < 0) { |
da927ba9 | 232 | log_error_errno(r, "Failed to send reply: %m"); |
89ffcd2a LP |
233 | goto fail; |
234 | } | |
235 | } | |
236 | } | |
237 | ||
238 | r = 0; | |
239 | ||
240 | fail: | |
e3017af9 LP |
241 | if (bus) { |
242 | sd_bus_flush(bus); | |
89ffcd2a | 243 | sd_bus_unref(bus); |
e3017af9 | 244 | } |
89ffcd2a | 245 | |
e3017af9 | 246 | return r; |
89ffcd2a LP |
247 | } |
248 | ||
e3017af9 | 249 | static void* client1(void*p) { |
4afd3348 LP |
250 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
251 | _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; | |
252 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; | |
89ffcd2a LP |
253 | const char *hello; |
254 | int r; | |
0e851143 | 255 | _cleanup_close_pair_ int pp[2] = { -1, -1 }; |
2c93b4ef | 256 | char x; |
89ffcd2a LP |
257 | |
258 | r = sd_bus_open_user(&bus); | |
259 | if (r < 0) { | |
da927ba9 | 260 | log_error_errno(r, "Failed to connect to user bus: %m"); |
89ffcd2a LP |
261 | goto finish; |
262 | } | |
263 | ||
d4100e24 | 264 | r = sd_bus_call_method( |
89ffcd2a LP |
265 | bus, |
266 | "org.freedesktop.systemd.test", | |
267 | "/", | |
268 | "org.freedesktop.systemd.test", | |
269 | "LowerCase", | |
d4100e24 LP |
270 | &error, |
271 | &reply, | |
272 | "s", | |
273 | "HELLO"); | |
89ffcd2a | 274 | if (r < 0) { |
da927ba9 | 275 | log_error_errno(r, "Failed to issue method call: %m"); |
89ffcd2a LP |
276 | goto finish; |
277 | } | |
278 | ||
279 | r = sd_bus_message_read(reply, "s", &hello); | |
280 | if (r < 0) { | |
da927ba9 | 281 | log_error_errno(r, "Failed to get string: %m"); |
89ffcd2a LP |
282 | goto finish; |
283 | } | |
284 | ||
0c0cdb06 | 285 | assert_se(streq(hello, "hello")); |
89ffcd2a | 286 | |
2c93b4ef | 287 | if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) { |
56f64d95 | 288 | log_error_errno(errno, "Failed to allocate pipe: %m"); |
2c93b4ef LP |
289 | r = -errno; |
290 | goto finish; | |
291 | } | |
292 | ||
5a330cda ZJS |
293 | log_info("Sending fd=%d", pp[1]); |
294 | ||
b7f247e0 | 295 | r = sd_bus_call_method( |
2c93b4ef LP |
296 | bus, |
297 | "org.freedesktop.systemd.test", | |
298 | "/", | |
299 | "org.freedesktop.systemd.test", | |
300 | "FileDescriptor", | |
b7f247e0 LP |
301 | &error, |
302 | NULL, | |
303 | "h", | |
304 | pp[1]); | |
2c93b4ef | 305 | if (r < 0) { |
da927ba9 | 306 | log_error_errno(r, "Failed to issue method call: %m"); |
2c93b4ef LP |
307 | goto finish; |
308 | } | |
309 | ||
310 | errno = 0; | |
311 | if (read(pp[0], &x, 1) <= 0) { | |
312 | log_error("Failed to read from pipe: %s", errno ? strerror(errno) : "early read"); | |
313 | goto finish; | |
314 | } | |
315 | ||
89ffcd2a LP |
316 | r = 0; |
317 | ||
318 | finish: | |
319 | if (bus) { | |
4afd3348 | 320 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *q; |
89ffcd2a LP |
321 | |
322 | r = sd_bus_message_new_method_call( | |
323 | bus, | |
151b9b96 | 324 | &q, |
89ffcd2a LP |
325 | "org.freedesktop.systemd.test", |
326 | "/", | |
327 | "org.freedesktop.systemd.test", | |
151b9b96 | 328 | "ExitClient1"); |
b7f247e0 | 329 | if (r < 0) |
da927ba9 | 330 | log_error_errno(r, "Failed to allocate method call: %m"); |
b7f247e0 LP |
331 | else |
332 | sd_bus_send(bus, q, NULL); | |
89ffcd2a | 333 | |
89ffcd2a LP |
334 | } |
335 | ||
e3017af9 LP |
336 | return INT_TO_PTR(r); |
337 | } | |
338 | ||
19070062 | 339 | static int quit_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
e3017af9 LP |
340 | bool *x = userdata; |
341 | ||
9eec7d12 | 342 | log_error_errno(sd_bus_message_get_errno(m), "Quit callback: %m"); |
e3017af9 LP |
343 | |
344 | *x = 1; | |
345 | return 1; | |
346 | } | |
347 | ||
348 | static void* client2(void*p) { | |
4afd3348 LP |
349 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; |
350 | _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; | |
351 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; | |
e3017af9 | 352 | bool quit = false; |
b9bf7e2b LP |
353 | const char *mid; |
354 | int r; | |
e3017af9 LP |
355 | |
356 | r = sd_bus_open_user(&bus); | |
357 | if (r < 0) { | |
da927ba9 | 358 | log_error_errno(r, "Failed to connect to user bus: %m"); |
e3017af9 LP |
359 | goto finish; |
360 | } | |
361 | ||
a652755d LP |
362 | r = sd_bus_message_new_method_call( |
363 | bus, | |
151b9b96 | 364 | &m, |
a652755d LP |
365 | "org.freedesktop.systemd.test", |
366 | "/foo/bar/waldo/piep", | |
367 | "org.object.test", | |
151b9b96 | 368 | "Foobar"); |
a652755d | 369 | if (r < 0) { |
da927ba9 | 370 | log_error_errno(r, "Failed to allocate method call: %m"); |
a652755d LP |
371 | goto finish; |
372 | } | |
373 | ||
374 | r = sd_bus_send(bus, m, NULL); | |
375 | if (r < 0) { | |
376 | log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); | |
377 | goto finish; | |
378 | } | |
379 | ||
0e851143 | 380 | m = sd_bus_message_unref(m); |
a652755d | 381 | |
392d5b37 LP |
382 | r = sd_bus_message_new_signal( |
383 | bus, | |
151b9b96 | 384 | &m, |
392d5b37 LP |
385 | "/foobar", |
386 | "foo.bar", | |
151b9b96 | 387 | "Notify"); |
392d5b37 | 388 | if (r < 0) { |
da927ba9 | 389 | log_error_errno(r, "Failed to allocate signal: %m"); |
392d5b37 LP |
390 | goto finish; |
391 | } | |
392 | ||
393 | r = sd_bus_send(bus, m, NULL); | |
394 | if (r < 0) { | |
395 | log_error("Failed to issue signal: %s", bus_error_message(&error, -r)); | |
396 | goto finish; | |
397 | } | |
398 | ||
0e851143 | 399 | m = sd_bus_message_unref(m); |
392d5b37 | 400 | |
b9bf7e2b LP |
401 | r = sd_bus_message_new_method_call( |
402 | bus, | |
151b9b96 | 403 | &m, |
b9bf7e2b LP |
404 | "org.freedesktop.systemd.test", |
405 | "/", | |
406 | "org.freedesktop.DBus.Peer", | |
151b9b96 | 407 | "GetMachineId"); |
b9bf7e2b | 408 | if (r < 0) { |
da927ba9 | 409 | log_error_errno(r, "Failed to allocate method call: %m"); |
b9bf7e2b LP |
410 | goto finish; |
411 | } | |
412 | ||
c49b30a2 | 413 | r = sd_bus_call(bus, m, 0, &error, &reply); |
b9bf7e2b LP |
414 | if (r < 0) { |
415 | log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); | |
416 | goto finish; | |
417 | } | |
418 | ||
419 | r = sd_bus_message_read(reply, "s", &mid); | |
420 | if (r < 0) { | |
da927ba9 | 421 | log_error_errno(r, "Failed to parse machine ID: %m"); |
b9bf7e2b LP |
422 | goto finish; |
423 | } | |
424 | ||
425 | log_info("Machine ID is %s.", mid); | |
426 | ||
0e851143 | 427 | m = sd_bus_message_unref(m); |
b9bf7e2b | 428 | |
e3017af9 LP |
429 | r = sd_bus_message_new_method_call( |
430 | bus, | |
151b9b96 | 431 | &m, |
e3017af9 LP |
432 | "org.freedesktop.systemd.test", |
433 | "/", | |
434 | "org.freedesktop.systemd.test", | |
151b9b96 | 435 | "Slow"); |
e3017af9 | 436 | if (r < 0) { |
da927ba9 | 437 | log_error_errno(r, "Failed to allocate method call: %m"); |
e3017af9 LP |
438 | goto finish; |
439 | } | |
440 | ||
0e851143 | 441 | reply = sd_bus_message_unref(reply); |
b9bf7e2b | 442 | |
c49b30a2 | 443 | r = sd_bus_call(bus, m, 200 * USEC_PER_MSEC, &error, &reply); |
e3017af9 LP |
444 | if (r < 0) |
445 | log_info("Failed to issue method call: %s", bus_error_message(&error, -r)); | |
446 | else | |
447 | log_info("Slow call succeed."); | |
448 | ||
0e851143 | 449 | m = sd_bus_message_unref(m); |
e3017af9 LP |
450 | |
451 | r = sd_bus_message_new_method_call( | |
452 | bus, | |
151b9b96 | 453 | &m, |
e3017af9 LP |
454 | "org.freedesktop.systemd.test", |
455 | "/", | |
456 | "org.freedesktop.systemd.test", | |
151b9b96 | 457 | "Slow"); |
e3017af9 | 458 | if (r < 0) { |
da927ba9 | 459 | log_error_errno(r, "Failed to allocate method call: %m"); |
e3017af9 LP |
460 | goto finish; |
461 | } | |
462 | ||
19befb2d | 463 | r = sd_bus_call_async(bus, NULL, m, quit_callback, &quit, 200 * USEC_PER_MSEC); |
e3017af9 LP |
464 | if (r < 0) { |
465 | log_info("Failed to issue method call: %s", bus_error_message(&error, -r)); | |
466 | goto finish; | |
467 | } | |
468 | ||
469 | while (!quit) { | |
470 | r = sd_bus_process(bus, NULL); | |
471 | if (r < 0) { | |
da927ba9 | 472 | log_error_errno(r, "Failed to process requests: %m"); |
e3017af9 LP |
473 | goto finish; |
474 | } | |
475 | if (r == 0) { | |
476 | r = sd_bus_wait(bus, (uint64_t) -1); | |
477 | if (r < 0) { | |
da927ba9 | 478 | log_error_errno(r, "Failed to wait: %m"); |
e3017af9 LP |
479 | goto finish; |
480 | } | |
481 | } | |
482 | } | |
483 | ||
484 | r = 0; | |
485 | ||
486 | finish: | |
487 | if (bus) { | |
4afd3348 | 488 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *q; |
e3017af9 LP |
489 | |
490 | r = sd_bus_message_new_method_call( | |
491 | bus, | |
151b9b96 | 492 | &q, |
e3017af9 LP |
493 | "org.freedesktop.systemd.test", |
494 | "/", | |
495 | "org.freedesktop.systemd.test", | |
151b9b96 | 496 | "ExitClient2"); |
e3017af9 | 497 | if (r < 0) { |
da927ba9 | 498 | log_error_errno(r, "Failed to allocate method call: %m"); |
e3017af9 LP |
499 | goto finish; |
500 | } | |
501 | ||
0e851143 | 502 | (void) sd_bus_send(bus, q, NULL); |
e3017af9 LP |
503 | } |
504 | ||
e3017af9 | 505 | return INT_TO_PTR(r); |
89ffcd2a LP |
506 | } |
507 | ||
508 | int main(int argc, char *argv[]) { | |
e3017af9 | 509 | pthread_t c1, c2; |
89ffcd2a LP |
510 | sd_bus *bus; |
511 | void *p; | |
512 | int q, r; | |
513 | ||
514 | r = server_init(&bus); | |
49e5de64 ZJS |
515 | if (r < 0) { |
516 | log_info("Failed to connect to bus, skipping tests."); | |
517 | return EXIT_TEST_SKIP; | |
518 | } | |
89ffcd2a | 519 | |
e3017af9 LP |
520 | log_info("Initialized..."); |
521 | ||
522 | r = pthread_create(&c1, NULL, client1, bus); | |
523 | if (r != 0) | |
89ffcd2a | 524 | return EXIT_FAILURE; |
89ffcd2a | 525 | |
e3017af9 LP |
526 | r = pthread_create(&c2, NULL, client2, bus); |
527 | if (r != 0) | |
528 | return EXIT_FAILURE; | |
89ffcd2a | 529 | |
e3017af9 LP |
530 | r = server(bus); |
531 | ||
532 | q = pthread_join(c1, &p); | |
533 | if (q != 0) | |
534 | return EXIT_FAILURE; | |
2181a7f5 LP |
535 | if (PTR_TO_INT(p) < 0) |
536 | return EXIT_FAILURE; | |
537 | ||
e3017af9 | 538 | q = pthread_join(c2, &p); |
89ffcd2a LP |
539 | if (q != 0) |
540 | return EXIT_FAILURE; | |
2181a7f5 LP |
541 | if (PTR_TO_INT(p) < 0) |
542 | return EXIT_FAILURE; | |
543 | ||
89ffcd2a LP |
544 | if (r < 0) |
545 | return EXIT_FAILURE; | |
546 | ||
547 | return EXIT_SUCCESS; | |
548 | } |