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