Bug Summary

File:build-scan/../src/libsystemd/sd-bus/test-bus-chat.c
Warning:line 73, column 9
Value stored to 'r' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test-bus-chat.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I test-bus-chat.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/libsystemd/sd-bus/test-bus-chat.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2/***
3***/
4
5#include <fcntl.h>
6#include <pthread.h>
7#include <stdlib.h>
8#include <unistd.h>
9
10#include "sd-bus.h"
11
12#include "alloc-util.h"
13#include "bus-error.h"
14#include "bus-internal.h"
15#include "bus-match.h"
16#include "bus-util.h"
17#include "fd-util.h"
18#include "format-util.h"
19#include "log.h"
20#include "macro.h"
21#include "util.h"
22
23static int match_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
24 log_info("Match triggered! interface=%s member=%s", strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member(m)))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 24, __func__, "Match triggered! interface=%s member=%s"
, strna(sd_bus_message_get_interface(m)), strna(sd_bus_message_get_member
(m))) : -abs(_e); })
;
25 return 0;
26}
27
28static int object_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
29 int r;
30
31 if (sd_bus_message_is_method_error(m, NULL((void*)0)))
32 return 0;
33
34 if (sd_bus_message_is_method_call(m, "org.object.test", "Foobar")) {
35 log_info("Invoked Foobar() on %s", sd_bus_message_get_path(m))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 35, __func__, "Invoked Foobar() on %s"
, sd_bus_message_get_path(m)) : -abs(_e); })
;
36
37 r = sd_bus_reply_method_return(m, NULL((void*)0));
38 if (r < 0)
39 return log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 39, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
40
41 return 1;
42 }
43
44 return 0;
45}
46
47static int server_init(sd_bus **_bus) {
48 sd_bus *bus = NULL((void*)0);
49 sd_id128_t id;
50 int r;
51 const char *unique, *desc;
52
53 assert_se(_bus)do { if ((__builtin_expect(!!(!(_bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("_bus"), "../src/libsystemd/sd-bus/test-bus-chat.c"
, 53, __PRETTY_FUNCTION__); } while (0)
;
54
55 r = sd_bus_open_user_with_description(&bus, "my bus!");
56 if (r < 0) {
57 log_error_errno(r, "Failed to connect to user bus: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 57, __func__, "Failed to connect to user bus: %m"
) : -abs(_e); })
;
58 goto fail;
59 }
60
61 r = sd_bus_get_bus_id(bus, &id);
62 if (r < 0) {
63 log_error_errno(r, "Failed to get server ID: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 63, __func__, "Failed to get server ID: %m"
) : -abs(_e); })
;
64 goto fail;
65 }
66
67 r = sd_bus_get_unique_name(bus, &unique);
68 if (r < 0) {
69 log_error_errno(r, "Failed to get unique name: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 69, __func__, "Failed to get unique name: %m"
) : -abs(_e); })
;
70 goto fail;
71 }
72
73 r = sd_bus_get_description(bus, &desc);
Value stored to 'r' is never read
74 assert_se(streq(desc, "my bus!"))do { if ((__builtin_expect(!!(!((strcmp((desc),("my bus!")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(desc, \"my bus!\")"
), "../src/libsystemd/sd-bus/test-bus-chat.c", 74, __PRETTY_FUNCTION__
); } while (0)
;
75
76 log_info("Peer ID is " SD_ID128_FORMAT_STR ".", SD_ID128_FORMAT_VAL(id))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 76, __func__, "Peer ID is "
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
".", (id).bytes[0], (id).bytes[1], (id).bytes[2], (id).bytes
[3], (id).bytes[4], (id).bytes[5], (id).bytes[6], (id).bytes[
7], (id).bytes[8], (id).bytes[9], (id).bytes[10], (id).bytes[
11], (id).bytes[12], (id).bytes[13], (id).bytes[14], (id).bytes
[15]) : -abs(_e); })
;
77 log_info("Unique ID: %s", unique)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 77, __func__, "Unique ID: %s"
, unique) : -abs(_e); })
;
78 log_info("Can send file handles: %i", sd_bus_can_send(bus, 'h'))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 78, __func__, "Can send file handles: %i"
, sd_bus_can_send(bus, 'h')) : -abs(_e); })
;
79
80 r = sd_bus_request_name(bus, "org.freedesktop.systemd.test", 0);
81 if (r < 0) {
82 log_error_errno(r, "Failed to acquire name: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 82, __func__, "Failed to acquire name: %m"
) : -abs(_e); })
;
83 goto fail;
84 }
85
86 r = sd_bus_add_fallback(bus, NULL((void*)0), "/foo/bar", object_callback, NULL((void*)0));
87 if (r < 0) {
88 log_error_errno(r, "Failed to add object: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 88, __func__, "Failed to add object: %m"
) : -abs(_e); })
;
89 goto fail;
90 }
91
92 r = sd_bus_match_signal(bus, NULL((void*)0), NULL((void*)0), NULL((void*)0), "foo.bar", "Notify", match_callback, NULL((void*)0));
93 if (r < 0) {
94 log_error_errno(r, "Failed to request match: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 94, __func__, "Failed to request match: %m"
) : -abs(_e); })
;
95 goto fail;
96 }
97
98 r = sd_bus_add_match(bus, NULL((void*)0), "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged'", match_callback, NULL((void*)0));
99 if (r < 0) {
100 log_error_errno(r, "Failed to add match: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 100, __func__, "Failed to add match: %m"
) : -abs(_e); })
;
101 goto fail;
102 }
103
104 bus_match_dump(&bus->match_callbacks, 0);
105
106 *_bus = bus;
107 return 0;
108
109fail:
110 sd_bus_unref(bus);
111 return r;
112}
113
114static int server(sd_bus *bus) {
115 int r;
116 bool_Bool client1_gone = false0, client2_gone = false0;
117
118 while (!client1_gone || !client2_gone) {
119 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0);
120 pid_t pid = 0;
121 const char *label = NULL((void*)0);
122
123 r = sd_bus_process(bus, &m);
124 if (r < 0) {
125 log_error_errno(r, "Failed to process requests: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 125, __func__, "Failed to process requests: %m"
) : -abs(_e); })
;
126 goto fail;
127 }
128
129 if (r == 0) {
130 r = sd_bus_wait(bus, (uint64_t) -1);
131 if (r < 0) {
132 log_error_errno(r, "Failed to wait: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 132, __func__, "Failed to wait: %m"
) : -abs(_e); })
;
133 goto fail;
134 }
135
136 continue;
137 }
138
139 if (!m)
140 continue;
141
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);
144 log_info("Got message! member=%s pid="PID_FMT" label=%s",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 147, __func__, "Got message! member=%s pid="
"%" "i"" label=%s", strna(sd_bus_message_get_member(m)), pid,
strna(label)) : -abs(_e); })
145 strna(sd_bus_message_get_member(m)),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 147, __func__, "Got message! member=%s pid="
"%" "i"" label=%s", strna(sd_bus_message_get_member(m)), pid,
strna(label)) : -abs(_e); })
146 pid,({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 147, __func__, "Got message! member=%s pid="
"%" "i"" label=%s", strna(sd_bus_message_get_member(m)), pid,
strna(label)) : -abs(_e); })
147 strna(label))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 147, __func__, "Got message! member=%s pid="
"%" "i"" label=%s", strna(sd_bus_message_get_member(m)), pid,
strna(label)) : -abs(_e); })
;
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___attribute__((cleanup(freep))) char *lowercase = NULL((void*)0);
154
155 r = sd_bus_message_read(m, "s", &hello);
156 if (r < 0) {
157 log_error_errno(r, "Failed to get parameter: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 157, __func__, "Failed to get parameter: %m"
) : -abs(_e); })
;
158 goto fail;
159 }
160
161 lowercase = strdup(hello);
162 if (!lowercase) {
163 r = log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/libsystemd/sd-bus/test-bus-chat.c"
, 163, __func__)
;
164 goto fail;
165 }
166
167 ascii_strlower(lowercase);
168
169 r = sd_bus_reply_method_return(m, "s", lowercase);
170 if (r < 0) {
171 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 171, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
172 goto fail;
173 }
174 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "ExitClient1")) {
175
176 r = sd_bus_reply_method_return(m, NULL((void*)0));
177 if (r < 0) {
178 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 178, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
179 goto fail;
180 }
181
182 client1_gone = true1;
183 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "ExitClient2")) {
184
185 r = sd_bus_reply_method_return(m, NULL((void*)0));
186 if (r < 0) {
187 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 187, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
188 goto fail;
189 }
190
191 client2_gone = true1;
192 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.systemd.test", "Slow")) {
193
194 sleep(1);
195
196 r = sd_bus_reply_method_return(m, NULL((void*)0));
197 if (r < 0) {
198 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 198, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
199 goto fail;
200 }
201
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) {
208 log_error_errno(r, "Failed to get parameter: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 208, __func__, "Failed to get parameter: %m"
) : -abs(_e); })
;
209 goto fail;
210 }
211
212 log_info("Received fd=%d", fd)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 212, __func__, "Received fd=%d"
, fd) : -abs(_e); })
;
213
214 if (write(fd, &x, 1) < 0) {
215 log_error_errno(errno, "Failed to write to fd: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/libsystemd/sd-bus/test-bus-chat.c"
, 215, __func__, "Failed to write to fd: %m") : -abs(_e); })
;
216 safe_close(fd);
217 goto fail;
218 }
219
220 r = sd_bus_reply_method_return(m, NULL((void*)0));
221 if (r < 0) {
222 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 222, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
223 goto fail;
224 }
225
226 } else if (sd_bus_message_is_method_call(m, NULL((void*)0), NULL((void*)0))) {
227
228 r = sd_bus_reply_method_error(
229 m,
230 &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_UNKNOWN_METHOD, "Unknown method.")((const sd_bus_error) {("org.freedesktop.DBus.Error.UnknownMethod"
), ("Unknown method."), 0})
);
231 if (r < 0) {
232 log_error_errno(r, "Failed to send reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 232, __func__, "Failed to send reply: %m"
) : -abs(_e); })
;
233 goto fail;
234 }
235 }
236 }
237
238 r = 0;
239
240fail:
241 if (bus) {
242 sd_bus_flush(bus);
243 sd_bus_unref(bus);
244 }
245
246 return r;
247}
248
249static void* client1(void*p) {
250 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
251 _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0);
252 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
253 const char *hello;
254 int r;
255 _cleanup_close_pair___attribute__((cleanup(close_pairp))) int pp[2] = { -1, -1 };
256 char x;
257
258 r = sd_bus_open_user(&bus);
259 if (r < 0) {
260 log_error_errno(r, "Failed to connect to user bus: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 260, __func__, "Failed to connect to user bus: %m"
) : -abs(_e); })
;
261 goto finish;
262 }
263
264 r = sd_bus_call_method(
265 bus,
266 "org.freedesktop.systemd.test",
267 "/",
268 "org.freedesktop.systemd.test",
269 "LowerCase",
270 &error,
271 &reply,
272 "s",
273 "HELLO");
274 if (r < 0) {
275 log_error_errno(r, "Failed to issue method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 275, __func__, "Failed to issue method call: %m"
) : -abs(_e); })
;
276 goto finish;
277 }
278
279 r = sd_bus_message_read(reply, "s", &hello);
280 if (r < 0) {
281 log_error_errno(r, "Failed to get string: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 281, __func__, "Failed to get string: %m"
) : -abs(_e); })
;
282 goto finish;
283 }
284
285 assert_se(streq(hello, "hello"))do { if ((__builtin_expect(!!(!((strcmp((hello),("hello")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(hello, \"hello\")"
), "../src/libsystemd/sd-bus/test-bus-chat.c", 285, __PRETTY_FUNCTION__
); } while (0)
;
286
287 if (pipe2(pp, O_CLOEXEC02000000|O_NONBLOCK04000) < 0) {
288 log_error_errno(errno, "Failed to allocate pipe: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/libsystemd/sd-bus/test-bus-chat.c"
, 288, __func__, "Failed to allocate pipe: %m") : -abs(_e); }
)
;
289 r = -errno(*__errno_location ());
290 goto finish;
291 }
292
293 log_info("Sending fd=%d", pp[1])({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 293, __func__, "Sending fd=%d"
, pp[1]) : -abs(_e); })
;
294
295 r = sd_bus_call_method(
296 bus,
297 "org.freedesktop.systemd.test",
298 "/",
299 "org.freedesktop.systemd.test",
300 "FileDescriptor",
301 &error,
302 NULL((void*)0),
303 "h",
304 pp[1]);
305 if (r < 0) {
306 log_error_errno(r, "Failed to issue method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 306, __func__, "Failed to issue method call: %m"
) : -abs(_e); })
;
307 goto finish;
308 }
309
310 errno(*__errno_location ()) = 0;
311 if (read(pp[0], &x, 1) <= 0) {
312 log_error("Failed to read from pipe: %s", errno ? strerror(errno) : "early read")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 312, __func__, "Failed to read from pipe: %s"
, (*__errno_location ()) ? strerror((*__errno_location ())) :
"early read") : -abs(_e); })
;
313 goto finish;
314 }
315
316 r = 0;
317
318finish:
319 if (bus) {
320 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *q;
321
322 r = sd_bus_message_new_method_call(
323 bus,
324 &q,
325 "org.freedesktop.systemd.test",
326 "/",
327 "org.freedesktop.systemd.test",
328 "ExitClient1");
329 if (r < 0)
330 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 330, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
331 else
332 sd_bus_send(bus, q, NULL((void*)0));
333
334 }
335
336 return INT_TO_PTR(r)((void *) ((intptr_t) (r)));
337}
338
339static int quit_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
340 bool_Bool *x = userdata;
341
342 log_error_errno(sd_bus_message_get_errno(m), "Quit callback: %m")({ int _level = ((3)), _e = ((sd_bus_message_get_errno(m))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/libsystemd/sd-bus/test-bus-chat.c"
, 342, __func__, "Quit callback: %m") : -abs(_e); })
;
343
344 *x = 1;
345 return 1;
346}
347
348static void* client2(void*p) {
349 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0), *reply = NULL((void*)0);
350 _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0);
351 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
352 bool_Bool quit = false0;
353 const char *mid;
354 int r;
355
356 r = sd_bus_open_user(&bus);
357 if (r < 0) {
358 log_error_errno(r, "Failed to connect to user bus: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 358, __func__, "Failed to connect to user bus: %m"
) : -abs(_e); })
;
359 goto finish;
360 }
361
362 r = sd_bus_message_new_method_call(
363 bus,
364 &m,
365 "org.freedesktop.systemd.test",
366 "/foo/bar/waldo/piep",
367 "org.object.test",
368 "Foobar");
369 if (r < 0) {
370 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 370, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
371 goto finish;
372 }
373
374 r = sd_bus_send(bus, m, NULL((void*)0));
375 if (r < 0) {
376 log_error("Failed to issue method call: %s", bus_error_message(&error, -r))({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 376, __func__, "Failed to issue method call: %s"
, bus_error_message(&error, -r)) : -abs(_e); })
;
377 goto finish;
378 }
379
380 m = sd_bus_message_unref(m);
381
382 r = sd_bus_message_new_signal(
383 bus,
384 &m,
385 "/foobar",
386 "foo.bar",
387 "Notify");
388 if (r < 0) {
389 log_error_errno(r, "Failed to allocate signal: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 389, __func__, "Failed to allocate signal: %m"
) : -abs(_e); })
;
390 goto finish;
391 }
392
393 r = sd_bus_send(bus, m, NULL((void*)0));
394 if (r < 0) {
395 log_error("Failed to issue signal: %s", bus_error_message(&error, -r))({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 395, __func__, "Failed to issue signal: %s"
, bus_error_message(&error, -r)) : -abs(_e); })
;
396 goto finish;
397 }
398
399 m = sd_bus_message_unref(m);
400
401 r = sd_bus_message_new_method_call(
402 bus,
403 &m,
404 "org.freedesktop.systemd.test",
405 "/",
406 "org.freedesktop.DBus.Peer",
407 "GetMachineId");
408 if (r < 0) {
409 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 409, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
410 goto finish;
411 }
412
413 r = sd_bus_call(bus, m, 0, &error, &reply);
414 if (r < 0) {
415 log_error("Failed to issue method call: %s", bus_error_message(&error, -r))({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 415, __func__, "Failed to issue method call: %s"
, bus_error_message(&error, -r)) : -abs(_e); })
;
416 goto finish;
417 }
418
419 r = sd_bus_message_read(reply, "s", &mid);
420 if (r < 0) {
421 log_error_errno(r, "Failed to parse machine ID: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 421, __func__, "Failed to parse machine ID: %m"
) : -abs(_e); })
;
422 goto finish;
423 }
424
425 log_info("Machine ID is %s.", mid)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 425, __func__, "Machine ID is %s."
, mid) : -abs(_e); })
;
426
427 m = sd_bus_message_unref(m);
428
429 r = sd_bus_message_new_method_call(
430 bus,
431 &m,
432 "org.freedesktop.systemd.test",
433 "/",
434 "org.freedesktop.systemd.test",
435 "Slow");
436 if (r < 0) {
437 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 437, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
438 goto finish;
439 }
440
441 reply = sd_bus_message_unref(reply);
442
443 r = sd_bus_call(bus, m, 200 * USEC_PER_MSEC((usec_t) 1000ULL), &error, &reply);
444 if (r < 0)
445 log_info("Failed to issue method call: %s", bus_error_message(&error, -r))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 445, __func__, "Failed to issue method call: %s"
, bus_error_message(&error, -r)) : -abs(_e); })
;
446 else
447 log_info("Slow call succeed.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 447, __func__, "Slow call succeed."
) : -abs(_e); })
;
448
449 m = sd_bus_message_unref(m);
450
451 r = sd_bus_message_new_method_call(
452 bus,
453 &m,
454 "org.freedesktop.systemd.test",
455 "/",
456 "org.freedesktop.systemd.test",
457 "Slow");
458 if (r < 0) {
459 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 459, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
460 goto finish;
461 }
462
463 r = sd_bus_call_async(bus, NULL((void*)0), m, quit_callback, &quit, 200 * USEC_PER_MSEC((usec_t) 1000ULL));
464 if (r < 0) {
465 log_info("Failed to issue method call: %s", bus_error_message(&error, -r))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 465, __func__, "Failed to issue method call: %s"
, bus_error_message(&error, -r)) : -abs(_e); })
;
466 goto finish;
467 }
468
469 while (!quit) {
470 r = sd_bus_process(bus, NULL((void*)0));
471 if (r < 0) {
472 log_error_errno(r, "Failed to process requests: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 472, __func__, "Failed to process requests: %m"
) : -abs(_e); })
;
473 goto finish;
474 }
475 if (r == 0) {
476 r = sd_bus_wait(bus, (uint64_t) -1);
477 if (r < 0) {
478 log_error_errno(r, "Failed to wait: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 478, __func__, "Failed to wait: %m"
) : -abs(_e); })
;
479 goto finish;
480 }
481 }
482 }
483
484 r = 0;
485
486finish:
487 if (bus) {
488 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *q;
489
490 r = sd_bus_message_new_method_call(
491 bus,
492 &q,
493 "org.freedesktop.systemd.test",
494 "/",
495 "org.freedesktop.systemd.test",
496 "ExitClient2");
497 if (r < 0) {
498 log_error_errno(r, "Failed to allocate method call: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 498, __func__, "Failed to allocate method call: %m"
) : -abs(_e); })
;
499 goto finish;
500 }
501
502 (void) sd_bus_send(bus, q, NULL((void*)0));
503 }
504
505 return INT_TO_PTR(r)((void *) ((intptr_t) (r)));
506}
507
508int main(int argc, char *argv[]) {
509 pthread_t c1, c2;
510 sd_bus *bus;
511 void *p;
512 int q, r;
513
514 r = server_init(&bus);
515 if (r < 0) {
516 log_info("Failed to connect to bus, skipping tests.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 516, __func__, "Failed to connect to bus, skipping tests."
) : -abs(_e); })
;
517 return EXIT_TEST_SKIP77;
518 }
519
520 log_info("Initialized...")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/libsystemd/sd-bus/test-bus-chat.c", 520, __func__, "Initialized..."
) : -abs(_e); })
;
521
522 r = pthread_create(&c1, NULL((void*)0), client1, bus);
523 if (r != 0)
524 return EXIT_FAILURE1;
525
526 r = pthread_create(&c2, NULL((void*)0), client2, bus);
527 if (r != 0)
528 return EXIT_FAILURE1;
529
530 r = server(bus);
531
532 q = pthread_join(c1, &p);
533 if (q != 0)
534 return EXIT_FAILURE1;
535 if (PTR_TO_INT(p)((int) ((intptr_t) (p))) < 0)
536 return EXIT_FAILURE1;
537
538 q = pthread_join(c2, &p);
539 if (q != 0)
540 return EXIT_FAILURE1;
541 if (PTR_TO_INT(p)((int) ((intptr_t) (p))) < 0)
542 return EXIT_FAILURE1;
543
544 if (r < 0)
545 return EXIT_FAILURE1;
546
547 return EXIT_SUCCESS0;
548}