Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include <pthread.h>
4 : #include <stdlib.h>
5 :
6 : #include "sd-bus.h"
7 :
8 : #include "alloc-util.h"
9 : #include "bus-dump.h"
10 : #include "bus-internal.h"
11 : #include "bus-message.h"
12 : #include "bus-util.h"
13 : #include "log.h"
14 : #include "macro.h"
15 : #include "strv.h"
16 : #include "util.h"
17 :
18 : struct context {
19 : int fds[2];
20 : bool quit;
21 : char *something;
22 : char *automatic_string_property;
23 : uint32_t automatic_integer_property;
24 : };
25 :
26 1 : static int something_handler(sd_bus_message *m, void *userdata, sd_bus_error *error) {
27 1 : struct context *c = userdata;
28 : const char *s;
29 1 : char *n = NULL;
30 : int r;
31 :
32 1 : r = sd_bus_message_read(m, "s", &s);
33 1 : assert_se(r > 0);
34 :
35 1 : n = strjoin("<<<", s, ">>>");
36 1 : assert_se(n);
37 :
38 1 : free(c->something);
39 1 : c->something = n;
40 :
41 1 : log_info("AlterSomething() called, got %s, returning %s", s, n);
42 :
43 : /* This should fail, since the return type doesn't match */
44 1 : assert_se(sd_bus_reply_method_return(m, "u", 4711) == -ENOMSG);
45 :
46 1 : r = sd_bus_reply_method_return(m, "s", n);
47 1 : assert_se(r >= 0);
48 :
49 1 : return 1;
50 : }
51 :
52 1 : static int exit_handler(sd_bus_message *m, void *userdata, sd_bus_error *error) {
53 1 : struct context *c = userdata;
54 : int r;
55 :
56 1 : c->quit = true;
57 :
58 1 : log_info("Exit called");
59 :
60 1 : r = sd_bus_reply_method_return(m, "");
61 1 : assert_se(r >= 0);
62 :
63 1 : return 1;
64 : }
65 :
66 4 : static int get_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
67 4 : struct context *c = userdata;
68 : int r;
69 :
70 4 : log_info("property get for %s called, returning \"%s\".", property, c->something);
71 :
72 4 : r = sd_bus_message_append(reply, "s", c->something);
73 4 : assert_se(r >= 0);
74 :
75 4 : return 1;
76 : }
77 :
78 1 : static int set_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error) {
79 1 : struct context *c = userdata;
80 : const char *s;
81 : char *n;
82 : int r;
83 :
84 1 : log_info("property set for %s called", property);
85 :
86 1 : r = sd_bus_message_read(value, "s", &s);
87 1 : assert_se(r >= 0);
88 :
89 1 : n = strdup(s);
90 1 : assert_se(n);
91 :
92 1 : free(c->something);
93 1 : c->something = n;
94 :
95 1 : return 1;
96 : }
97 :
98 23 : static int value_handler(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
99 46 : _cleanup_free_ char *s = NULL;
100 : const char *x;
101 : int r;
102 :
103 23 : assert_se(asprintf(&s, "object %p, path %s", userdata, path) >= 0);
104 23 : r = sd_bus_message_append(reply, "s", s);
105 23 : assert_se(r >= 0);
106 :
107 23 : assert_se(x = startswith(path, "/value/"));
108 :
109 23 : assert_se(PTR_TO_UINT(userdata) == 30);
110 :
111 23 : return 1;
112 : }
113 :
114 1 : static int notify_test(sd_bus_message *m, void *userdata, sd_bus_error *error) {
115 : int r;
116 :
117 1 : assert_se(sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), m->path, "org.freedesktop.systemd.ValueTest", "Value", NULL) >= 0);
118 :
119 1 : r = sd_bus_reply_method_return(m, NULL);
120 1 : assert_se(r >= 0);
121 :
122 1 : return 1;
123 : }
124 :
125 1 : static int notify_test2(sd_bus_message *m, void *userdata, sd_bus_error *error) {
126 : int r;
127 :
128 1 : assert_se(sd_bus_emit_properties_changed_strv(sd_bus_message_get_bus(m), m->path, "org.freedesktop.systemd.ValueTest", NULL) >= 0);
129 :
130 1 : r = sd_bus_reply_method_return(m, NULL);
131 1 : assert_se(r >= 0);
132 :
133 1 : return 1;
134 : }
135 :
136 1 : static int emit_interfaces_added(sd_bus_message *m, void *userdata, sd_bus_error *error) {
137 : int r;
138 :
139 1 : assert_se(sd_bus_emit_interfaces_added(sd_bus_message_get_bus(m), "/value/a/x", "org.freedesktop.systemd.ValueTest", NULL) >= 0);
140 :
141 1 : r = sd_bus_reply_method_return(m, NULL);
142 1 : assert_se(r >= 0);
143 :
144 1 : return 1;
145 : }
146 :
147 1 : static int emit_interfaces_removed(sd_bus_message *m, void *userdata, sd_bus_error *error) {
148 : int r;
149 :
150 1 : assert_se(sd_bus_emit_interfaces_removed(sd_bus_message_get_bus(m), "/value/a/x", "org.freedesktop.systemd.ValueTest", NULL) >= 0);
151 :
152 1 : r = sd_bus_reply_method_return(m, NULL);
153 1 : assert_se(r >= 0);
154 :
155 1 : return 1;
156 : }
157 :
158 1 : static int emit_object_added(sd_bus_message *m, void *userdata, sd_bus_error *error) {
159 : int r;
160 :
161 1 : assert_se(sd_bus_emit_object_added(sd_bus_message_get_bus(m), "/value/a/x") >= 0);
162 :
163 1 : r = sd_bus_reply_method_return(m, NULL);
164 1 : assert_se(r >= 0);
165 :
166 1 : return 1;
167 : }
168 :
169 1 : static int emit_object_removed(sd_bus_message *m, void *userdata, sd_bus_error *error) {
170 : int r;
171 :
172 1 : assert_se(sd_bus_emit_object_removed(sd_bus_message_get_bus(m), "/value/a/x") >= 0);
173 :
174 1 : r = sd_bus_reply_method_return(m, NULL);
175 1 : assert_se(r >= 0);
176 :
177 1 : return 1;
178 : }
179 :
180 : static const sd_bus_vtable vtable[] = {
181 : SD_BUS_VTABLE_START(0),
182 : SD_BUS_METHOD("AlterSomething", "s", "s", something_handler, 0),
183 : SD_BUS_METHOD("Exit", "", "", exit_handler, 0),
184 : SD_BUS_WRITABLE_PROPERTY("Something", "s", get_handler, set_handler, 0, 0),
185 : SD_BUS_WRITABLE_PROPERTY("AutomaticStringProperty", "s", NULL, NULL, offsetof(struct context, automatic_string_property), 0),
186 : SD_BUS_WRITABLE_PROPERTY("AutomaticIntegerProperty", "u", NULL, NULL, offsetof(struct context, automatic_integer_property), 0),
187 : SD_BUS_METHOD("NoOperation", NULL, NULL, NULL, 0),
188 : SD_BUS_METHOD("EmitInterfacesAdded", NULL, NULL, emit_interfaces_added, 0),
189 : SD_BUS_METHOD("EmitInterfacesRemoved", NULL, NULL, emit_interfaces_removed, 0),
190 : SD_BUS_METHOD("EmitObjectAdded", NULL, NULL, emit_object_added, 0),
191 : SD_BUS_METHOD("EmitObjectRemoved", NULL, NULL, emit_object_removed, 0),
192 : SD_BUS_VTABLE_END
193 : };
194 :
195 : static const sd_bus_vtable vtable2[] = {
196 : SD_BUS_VTABLE_START(0),
197 : SD_BUS_METHOD("NotifyTest", "", "", notify_test, 0),
198 : SD_BUS_METHOD("NotifyTest2", "", "", notify_test2, 0),
199 : SD_BUS_PROPERTY("Value", "s", value_handler, 10, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
200 : SD_BUS_PROPERTY("Value2", "s", value_handler, 10, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
201 : SD_BUS_PROPERTY("Value3", "s", value_handler, 10, SD_BUS_VTABLE_PROPERTY_CONST),
202 : SD_BUS_PROPERTY("Value4", "s", value_handler, 10, 0),
203 : SD_BUS_PROPERTY("AnExplicitProperty", "s", NULL, offsetof(struct context, something), SD_BUS_VTABLE_PROPERTY_EXPLICIT|SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
204 : SD_BUS_VTABLE_END
205 : };
206 :
207 2 : static int enumerator_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
208 :
209 2 : if (object_path_startswith("/value", path))
210 2 : assert_se(*nodes = strv_new("/value/a", "/value/b", "/value/c"));
211 :
212 2 : return 1;
213 : }
214 :
215 1 : static int enumerator2_callback(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
216 :
217 1 : if (object_path_startswith("/value/a", path))
218 1 : assert_se(*nodes = strv_new("/value/a/x", "/value/a/y", "/value/a/z"));
219 :
220 1 : return 1;
221 : }
222 :
223 1 : static void *server(void *p) {
224 1 : struct context *c = p;
225 1 : sd_bus *bus = NULL;
226 : sd_id128_t id;
227 : int r;
228 :
229 1 : c->quit = false;
230 :
231 1 : assert_se(sd_id128_randomize(&id) >= 0);
232 :
233 1 : assert_se(sd_bus_new(&bus) >= 0);
234 1 : assert_se(sd_bus_set_fd(bus, c->fds[0], c->fds[0]) >= 0);
235 1 : assert_se(sd_bus_set_server(bus, 1, id) >= 0);
236 :
237 1 : assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test", vtable, c) >= 0);
238 1 : assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test2", vtable, c) >= 0);
239 1 : assert_se(sd_bus_add_fallback_vtable(bus, NULL, "/value", "org.freedesktop.systemd.ValueTest", vtable2, NULL, UINT_TO_PTR(20)) >= 0);
240 1 : assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value", enumerator_callback, NULL) >= 0);
241 1 : assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value/a", enumerator2_callback, NULL) >= 0);
242 1 : assert_se(sd_bus_add_object_manager(bus, NULL, "/value") >= 0);
243 1 : assert_se(sd_bus_add_object_manager(bus, NULL, "/value/a") >= 0);
244 :
245 1 : assert_se(sd_bus_start(bus) >= 0);
246 :
247 1 : log_error("Entering event loop on server");
248 :
249 53 : while (!c->quit) {
250 52 : log_error("Loop!");
251 :
252 52 : r = sd_bus_process(bus, NULL);
253 52 : if (r < 0) {
254 0 : log_error_errno(r, "Failed to process requests: %m");
255 0 : goto fail;
256 : }
257 :
258 52 : if (r == 0) {
259 25 : r = sd_bus_wait(bus, (uint64_t) -1);
260 25 : if (r < 0) {
261 0 : log_error_errno(r, "Failed to wait: %m");
262 0 : goto fail;
263 : }
264 :
265 25 : continue;
266 : }
267 : }
268 :
269 1 : r = 0;
270 :
271 1 : fail:
272 1 : if (bus) {
273 1 : sd_bus_flush(bus);
274 1 : sd_bus_unref(bus);
275 : }
276 :
277 1 : return INT_TO_PTR(r);
278 : }
279 :
280 1 : static int client(struct context *c) {
281 1 : _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
282 1 : _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
283 2 : _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
284 : const char *s;
285 : int r;
286 :
287 1 : assert_se(sd_bus_new(&bus) >= 0);
288 1 : assert_se(sd_bus_set_fd(bus, c->fds[1], c->fds[1]) >= 0);
289 1 : assert_se(sd_bus_start(bus) >= 0);
290 :
291 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "NoOperation", &error, NULL, NULL);
292 1 : assert_se(r >= 0);
293 :
294 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "AlterSomething", &error, &reply, "s", "hallo");
295 1 : assert_se(r >= 0);
296 :
297 1 : r = sd_bus_message_read(reply, "s", &s);
298 1 : assert_se(r >= 0);
299 1 : assert_se(streq(s, "<<<hallo>>>"));
300 :
301 1 : sd_bus_message_unref(reply);
302 1 : reply = NULL;
303 :
304 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Doesntexist", &error, &reply, "");
305 1 : assert_se(r < 0);
306 1 : assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD));
307 :
308 1 : sd_bus_error_free(&error);
309 :
310 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "AlterSomething", &error, &reply, "as", 1, "hallo");
311 1 : assert_se(r < 0);
312 1 : assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_INVALID_ARGS));
313 :
314 1 : sd_bus_error_free(&error);
315 :
316 1 : r = sd_bus_get_property(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Something", &error, &reply, "s");
317 1 : assert_se(r >= 0);
318 :
319 1 : r = sd_bus_message_read(reply, "s", &s);
320 1 : assert_se(r >= 0);
321 1 : assert_se(streq(s, "<<<hallo>>>"));
322 :
323 1 : sd_bus_message_unref(reply);
324 1 : reply = NULL;
325 :
326 1 : r = sd_bus_set_property(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Something", &error, "s", "test");
327 1 : assert_se(r >= 0);
328 :
329 1 : r = sd_bus_get_property(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Something", &error, &reply, "s");
330 1 : assert_se(r >= 0);
331 :
332 1 : r = sd_bus_message_read(reply, "s", &s);
333 1 : assert_se(r >= 0);
334 1 : assert_se(streq(s, "test"));
335 :
336 1 : sd_bus_message_unref(reply);
337 1 : reply = NULL;
338 :
339 1 : r = sd_bus_set_property(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "AutomaticIntegerProperty", &error, "u", 815);
340 1 : assert_se(r >= 0);
341 :
342 1 : assert_se(c->automatic_integer_property == 815);
343 :
344 1 : r = sd_bus_set_property(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "AutomaticStringProperty", &error, "s", "Du Dödel, Du!");
345 1 : assert_se(r >= 0);
346 :
347 1 : assert_se(streq(c->automatic_string_property, "Du Dödel, Du!"));
348 :
349 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
350 1 : assert_se(r >= 0);
351 :
352 1 : r = sd_bus_message_read(reply, "s", &s);
353 1 : assert_se(r >= 0);
354 1 : fputs(s, stdout);
355 :
356 1 : sd_bus_message_unref(reply);
357 1 : reply = NULL;
358 :
359 1 : r = sd_bus_get_property(bus, "org.freedesktop.systemd.test", "/value/xuzz", "org.freedesktop.systemd.ValueTest", "Value", &error, &reply, "s");
360 1 : assert_se(r >= 0);
361 :
362 1 : r = sd_bus_message_read(reply, "s", &s);
363 1 : assert_se(r >= 0);
364 1 : log_info("read %s", s);
365 :
366 1 : sd_bus_message_unref(reply);
367 1 : reply = NULL;
368 :
369 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
370 1 : assert_se(r >= 0);
371 :
372 1 : r = sd_bus_message_read(reply, "s", &s);
373 1 : assert_se(r >= 0);
374 1 : fputs(s, stdout);
375 :
376 1 : sd_bus_message_unref(reply);
377 1 : reply = NULL;
378 :
379 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
380 1 : assert_se(r >= 0);
381 :
382 1 : r = sd_bus_message_read(reply, "s", &s);
383 1 : assert_se(r >= 0);
384 1 : fputs(s, stdout);
385 :
386 1 : sd_bus_message_unref(reply);
387 1 : reply = NULL;
388 :
389 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
390 1 : assert_se(r >= 0);
391 :
392 1 : r = sd_bus_message_read(reply, "s", &s);
393 1 : assert_se(r >= 0);
394 1 : fputs(s, stdout);
395 :
396 1 : sd_bus_message_unref(reply);
397 1 : reply = NULL;
398 :
399 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", "");
400 1 : assert_se(r >= 0);
401 :
402 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
403 :
404 1 : sd_bus_message_unref(reply);
405 1 : reply = NULL;
406 :
407 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", "org.freedesktop.systemd.ValueTest2");
408 1 : assert_se(r < 0);
409 1 : assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_INTERFACE));
410 1 : sd_bus_error_free(&error);
411 :
412 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
413 1 : assert_se(r < 0);
414 1 : assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD));
415 1 : sd_bus_error_free(&error);
416 :
417 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
418 1 : assert_se(r >= 0);
419 :
420 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
421 :
422 1 : sd_bus_message_unref(reply);
423 1 : reply = NULL;
424 :
425 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.systemd.ValueTest", "NotifyTest", &error, NULL, "");
426 1 : assert_se(r >= 0);
427 :
428 1 : r = sd_bus_process(bus, &reply);
429 1 : assert_se(r > 0);
430 :
431 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.Properties", "PropertiesChanged"));
432 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
433 :
434 1 : sd_bus_message_unref(reply);
435 1 : reply = NULL;
436 :
437 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.systemd.ValueTest", "NotifyTest2", &error, NULL, "");
438 1 : assert_se(r >= 0);
439 :
440 1 : r = sd_bus_process(bus, &reply);
441 1 : assert_se(r > 0);
442 :
443 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.Properties", "PropertiesChanged"));
444 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
445 :
446 1 : sd_bus_message_unref(reply);
447 1 : reply = NULL;
448 :
449 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "EmitInterfacesAdded", &error, NULL, "");
450 1 : assert_se(r >= 0);
451 :
452 1 : r = sd_bus_process(bus, &reply);
453 1 : assert_se(r > 0);
454 :
455 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded"));
456 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
457 :
458 1 : sd_bus_message_unref(reply);
459 1 : reply = NULL;
460 :
461 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "EmitInterfacesRemoved", &error, NULL, "");
462 1 : assert_se(r >= 0);
463 :
464 1 : r = sd_bus_process(bus, &reply);
465 1 : assert_se(r > 0);
466 :
467 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved"));
468 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
469 :
470 1 : sd_bus_message_unref(reply);
471 1 : reply = NULL;
472 :
473 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "EmitObjectAdded", &error, NULL, "");
474 1 : assert_se(r >= 0);
475 :
476 1 : r = sd_bus_process(bus, &reply);
477 1 : assert_se(r > 0);
478 :
479 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded"));
480 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
481 :
482 1 : sd_bus_message_unref(reply);
483 1 : reply = NULL;
484 :
485 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "EmitObjectRemoved", &error, NULL, "");
486 1 : assert_se(r >= 0);
487 :
488 1 : r = sd_bus_process(bus, &reply);
489 1 : assert_se(r > 0);
490 :
491 1 : assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved"));
492 1 : bus_message_dump(reply, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
493 :
494 1 : sd_bus_message_unref(reply);
495 1 : reply = NULL;
496 :
497 1 : r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Exit", &error, NULL, "");
498 1 : assert_se(r >= 0);
499 :
500 1 : sd_bus_flush(bus);
501 :
502 1 : return 0;
503 : }
504 :
505 1 : int main(int argc, char *argv[]) {
506 1 : struct context c = {};
507 : pthread_t s;
508 : void *p;
509 : int r, q;
510 :
511 1 : c.automatic_integer_property = 4711;
512 1 : assert_se(c.automatic_string_property = strdup("dudeldu"));
513 :
514 1 : assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, c.fds) >= 0);
515 :
516 1 : r = pthread_create(&s, NULL, server, &c);
517 1 : if (r != 0)
518 0 : return -r;
519 :
520 1 : r = client(&c);
521 :
522 1 : q = pthread_join(s, &p);
523 1 : if (q != 0)
524 0 : return -q;
525 :
526 1 : if (r < 0)
527 0 : return r;
528 :
529 1 : if (PTR_TO_INT(p) < 0)
530 0 : return PTR_TO_INT(p);
531 :
532 1 : free(c.something);
533 1 : free(c.automatic_string_property);
534 :
535 1 : return EXIT_SUCCESS;
536 : }
|