Bug Summary

File:build-scan/../src/hostname/hostnamed.c
Warning:line 357, column 24
Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n'

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 hostnamed.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 systemd-hostnamed.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/hostname/hostnamed.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <errno(*__errno_location ()).h>
4#include <string.h>
5#include <sys/utsname.h>
6#include <unistd.h>
7
8#include "alloc-util.h"
9#include "bus-util.h"
10#include "def.h"
11#include "env-util.h"
12#include "fileio-label.h"
13#include "hostname-util.h"
14#include "os-util.h"
15#include "parse-util.h"
16#include "path-util.h"
17#include "selinux-util.h"
18#include "strv.h"
19#include "user-util.h"
20#include "util.h"
21#include "virt.h"
22
23#define VALID_DEPLOYMENT_CHARS("0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"-.:")
(DIGITS"0123456789" LETTERS"abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "-.:")
24
25enum {
26 PROP_HOSTNAME,
27 PROP_STATIC_HOSTNAME,
28 PROP_PRETTY_HOSTNAME,
29 PROP_ICON_NAME,
30 PROP_CHASSIS,
31 PROP_DEPLOYMENT,
32 PROP_LOCATION,
33 PROP_KERNEL_NAME,
34 PROP_KERNEL_RELEASE,
35 PROP_KERNEL_VERSION,
36 PROP_OS_PRETTY_NAME,
37 PROP_OS_CPE_NAME,
38 PROP_HOME_URL,
39 _PROP_MAX
40};
41
42typedef struct Context {
43 char *data[_PROP_MAX];
44 Hashmap *polkit_registry;
45} Context;
46
47static void context_reset(Context *c) {
48 int p;
49
50 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 50,
__PRETTY_FUNCTION__); } while (0)
;
51
52 for (p = 0; p < _PROP_MAX; p++)
53 c->data[p] = mfree(c->data[p]);
54}
55
56static void context_free(Context *c) {
57 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 57,
__PRETTY_FUNCTION__); } while (0)
;
58
59 context_reset(c);
60 bus_verify_polkit_async_registry_free(c->polkit_registry);
61}
62
63static int context_read_data(Context *c) {
64 int r;
65 struct utsname u;
66
67 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 67,
__PRETTY_FUNCTION__); } while (0)
;
68
69 context_reset(c);
70
71 assert_se(uname(&u) >= 0)do { if ((__builtin_expect(!!(!(uname(&u) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("uname(&u) >= 0"), "../src/hostname/hostnamed.c"
, 71, __PRETTY_FUNCTION__); } while (0)
;
72 c->data[PROP_KERNEL_NAME] = strdup(u.sysname);
73 c->data[PROP_KERNEL_RELEASE] = strdup(u.release);
74 c->data[PROP_KERNEL_VERSION] = strdup(u.version);
75 if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] ||
76 !c->data[PROP_KERNEL_VERSION])
77 return -ENOMEM12;
78
79 c->data[PROP_HOSTNAME] = gethostname_malloc();
80 if (!c->data[PROP_HOSTNAME])
81 return -ENOMEM12;
82
83 r = read_etc_hostname(NULL((void*)0), &c->data[PROP_STATIC_HOSTNAME]);
84 if (r < 0 && r != -ENOENT2)
85 return r;
86
87 r = parse_env_file(NULL((void*)0), "/etc/machine-info", NEWLINE"\n\r",
88 "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME],
89 "ICON_NAME", &c->data[PROP_ICON_NAME],
90 "CHASSIS", &c->data[PROP_CHASSIS],
91 "DEPLOYMENT", &c->data[PROP_DEPLOYMENT],
92 "LOCATION", &c->data[PROP_LOCATION],
93 NULL((void*)0));
94 if (r < 0 && r != -ENOENT2)
95 return r;
96
97 r = parse_os_release(NULL((void*)0),
98 "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME],
99 "CPE_NAME", &c->data[PROP_OS_CPE_NAME],
100 "HOME_URL", &c->data[PROP_HOME_URL],
101 NULL((void*)0));
102 if (r < 0 && r != -ENOENT2)
103 return r;
104
105 return 0;
106}
107
108static bool_Bool valid_chassis(const char *chassis) {
109 assert(chassis)do { if ((__builtin_expect(!!(!(chassis)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("chassis"), "../src/hostname/hostnamed.c"
, 109, __PRETTY_FUNCTION__); } while (0)
;
110
111 return nulstr_contains(
112 "vm\0"
113 "container\0"
114 "desktop\0"
115 "laptop\0"
116 "convertible\0"
117 "server\0"
118 "tablet\0"
119 "handset\0"
120 "watch\0"
121 "embedded\0",
122 chassis);
123}
124
125static bool_Bool valid_deployment(const char *deployment) {
126 assert(deployment)do { if ((__builtin_expect(!!(!(deployment)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("deployment"), "../src/hostname/hostnamed.c"
, 126, __PRETTY_FUNCTION__); } while (0)
;
127
128 return in_charset(deployment, VALID_DEPLOYMENT_CHARS("0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"-.:")
);
129}
130
131static const char* fallback_chassis(void) {
132 char *type;
133 unsigned t;
134 int v, r;
135
136 v = detect_virtualization();
137 if (VIRTUALIZATION_IS_VM(v))
138 return "vm";
139 if (VIRTUALIZATION_IS_CONTAINER(v))
140 return "container";
141
142 r = read_one_line_file("/sys/class/dmi/id/chassis_type", &type);
143 if (r < 0)
144 goto try_acpi;
145
146 r = safe_atou(type, &t);
147 free(type);
148 if (r < 0)
149 goto try_acpi;
150
151 /* We only list the really obvious cases here. The DMI data is unreliable enough, so let's not do any
152 additional guesswork on top of that.
153
154 See the SMBIOS Specification 3.0 section 7.4.1 for details about the values listed here:
155
156 https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
157 */
158
159 switch (t) {
160
161 case 0x3: /* Desktop */
162 case 0x4: /* Low Profile Desktop */
163 case 0x6: /* Mini Tower */
164 case 0x7: /* Tower */
165 return "desktop";
166
167 case 0x8: /* Portable */
168 case 0x9: /* Laptop */
169 case 0xA: /* Notebook */
170 case 0xE: /* Sub Notebook */
171 return "laptop";
172
173 case 0xB: /* Hand Held */
174 return "handset";
175
176 case 0x11: /* Main Server Chassis */
177 case 0x1C: /* Blade */
178 case 0x1D: /* Blade Enclosure */
179 return "server";
180
181 case 0x1E: /* Tablet */
182 return "tablet";
183
184 case 0x1F: /* Convertible */
185 case 0x20: /* Detachable */
186 return "convertible";
187 }
188
189try_acpi:
190 r = read_one_line_file("/sys/firmware/acpi/pm_profile", &type);
191 if (r < 0)
192 return NULL((void*)0);
193
194 r = safe_atou(type, &t);
195 free(type);
196 if (r < 0)
197 return NULL((void*)0);
198
199 /* We only list the really obvious cases here as the ACPI data is not really super reliable.
200 *
201 * See the ACPI 5.0 Spec Section 5.2.9.1 for details:
202 *
203 * http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
204 */
205
206 switch(t) {
207
208 case 1: /* Desktop */
209 case 3: /* Workstation */
210 case 6: /* Appliance PC */
211 return "desktop";
212
213 case 2: /* Mobile */
214 return "laptop";
215
216 case 4: /* Enterprise Server */
217 case 5: /* SOHO Server */
218 case 7: /* Performance Server */
219 return "server";
220
221 case 8: /* Tablet */
222 return "tablet";
223 }
224
225 return NULL((void*)0);
226}
227
228static char* context_fallback_icon_name(Context *c) {
229 const char *chassis;
230
231 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 231
, __PRETTY_FUNCTION__); } while (0)
;
232
233 if (!isempty(c->data[PROP_CHASSIS]))
234 return strappend("computer-", c->data[PROP_CHASSIS]);
235
236 chassis = fallback_chassis();
237 if (chassis)
238 return strappend("computer-", chassis);
239
240 return strdup("computer");
241}
242
243static bool_Bool hostname_is_useful(const char *hn) {
244 return !isempty(hn) && !is_localhost(hn);
245}
246
247static int context_update_kernel_hostname(Context *c) {
248 const char *static_hn;
249 const char *hn;
250
251 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 251
, __PRETTY_FUNCTION__); } while (0)
;
252
253 static_hn = c->data[PROP_STATIC_HOSTNAME];
254
255 /* /etc/hostname with something other than "localhost"
256 * has the highest preference ... */
257 if (hostname_is_useful(static_hn))
258 hn = static_hn;
259
260 /* ... the transient host name, (ie: DHCP) comes next ... */
261 else if (!isempty(c->data[PROP_HOSTNAME]))
262 hn = c->data[PROP_HOSTNAME];
263
264 /* ... fallback to static "localhost.*" ignored above ... */
265 else if (!isempty(static_hn))
266 hn = static_hn;
267
268 /* ... and the ultimate fallback */
269 else
270 hn = FALLBACK_HOSTNAME"localhost";
271
272 if (sethostname_idempotent(hn) < 0)
273 return -errno(*__errno_location ());
274
275 return 0;
276}
277
278static int context_write_data_static_hostname(Context *c) {
279
280 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 280
, __PRETTY_FUNCTION__); } while (0)
;
281
282 if (isempty(c->data[PROP_STATIC_HOSTNAME])) {
283
284 if (unlink("/etc/hostname") < 0)
285 return errno(*__errno_location ()) == ENOENT2 ? 0 : -errno(*__errno_location ());
286
287 return 0;
288 }
289 return write_string_file_atomic_label("/etc/hostname", c->data[PROP_STATIC_HOSTNAME]);
290}
291
292static int context_write_data_machine_info(Context *c) {
293
294 static const char * const name[_PROP_MAX] = {
295 [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
296 [PROP_ICON_NAME] = "ICON_NAME",
297 [PROP_CHASSIS] = "CHASSIS",
298 [PROP_DEPLOYMENT] = "DEPLOYMENT",
299 [PROP_LOCATION] = "LOCATION",
300 };
301
302 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0);
303 int r, p;
304
305 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 305
, __PRETTY_FUNCTION__); } while (0)
;
306
307 r = load_env_file(NULL((void*)0), "/etc/machine-info", NULL((void*)0), &l);
308 if (r < 0 && r != -ENOENT2)
309 return r;
310
311 for (p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) {
312 _cleanup_free___attribute__((cleanup(freep))) char *t = NULL((void*)0);
313 char **u;
314
315 assert(name[p])do { if ((__builtin_expect(!!(!(name[p])),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("name[p]"), "../src/hostname/hostnamed.c"
, 315, __PRETTY_FUNCTION__); } while (0)
;
316
317 if (isempty(c->data[p])) {
318 strv_env_unset(l, name[p]);
319 continue;
320 }
321
322 t = strjoin(name[p], "=", c->data[p])strjoin_real((name[p]), "=", c->data[p], ((void*)0));
323 if (!t)
324 return -ENOMEM12;
325
326 u = strv_env_set(l, t);
327 if (!u)
328 return -ENOMEM12;
329
330 strv_free_and_replace(l, u)({ strv_free(l); (l) = (u); (u) = ((void*)0); 0; });
331 }
332
333 if (strv_isempty(l)) {
334 if (unlink("/etc/machine-info") < 0)
335 return errno(*__errno_location ()) == ENOENT2 ? 0 : -errno(*__errno_location ());
336
337 return 0;
338 }
339
340 return write_env_file_label("/etc/machine-info", l);
341}
342
343static int property_get_icon_name(
344 sd_bus *bus,
345 const char *path,
346 const char *interface,
347 const char *property,
348 sd_bus_message *reply,
349 void *userdata,
350 sd_bus_error *error) {
351
352 _cleanup_free___attribute__((cleanup(freep))) char *n = NULL((void*)0);
353 Context *c = userdata;
354 const char *name;
355
356 if (isempty(c->data[PROP_ICON_NAME]))
357 name = n = context_fallback_icon_name(c);
Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n'
358 else
359 name = c->data[PROP_ICON_NAME];
360
361 if (!name)
362 return -ENOMEM12;
363
364 return sd_bus_message_append(reply, "s", name);
365}
366
367static int property_get_chassis(
368 sd_bus *bus,
369 const char *path,
370 const char *interface,
371 const char *property,
372 sd_bus_message *reply,
373 void *userdata,
374 sd_bus_error *error) {
375
376 Context *c = userdata;
377 const char *name;
378
379 if (isempty(c->data[PROP_CHASSIS]))
380 name = fallback_chassis();
381 else
382 name = c->data[PROP_CHASSIS];
383
384 return sd_bus_message_append(reply, "s", name);
385}
386
387static int method_set_hostname(sd_bus_message *m, void *userdata, sd_bus_error *error) {
388 Context *c = userdata;
389 const char *name;
390 int interactive;
391 int r;
392
393 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/hostname/hostnamed.c", 393
, __PRETTY_FUNCTION__); } while (0)
;
394 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 394
, __PRETTY_FUNCTION__); } while (0)
;
395
396 r = sd_bus_message_read(m, "sb", &name, &interactive);
397 if (r < 0)
398 return r;
399
400 if (isempty(name))
401 name = c->data[PROP_STATIC_HOSTNAME];
402
403 if (isempty(name))
404 name = FALLBACK_HOSTNAME"localhost";
405
406 if (!hostname_is_valid(name, false0))
407 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid hostname '%s'", name);
408
409 if (streq_ptr(name, c->data[PROP_HOSTNAME]))
410 return sd_bus_reply_method_return(m, NULL((void*)0));
411
412 r = bus_verify_polkit_async(
413 m,
414 CAP_SYS_ADMIN21,
415 "org.freedesktop.hostname1.set-hostname",
416 NULL((void*)0),
417 interactive,
418 UID_INVALID((uid_t) -1),
419 &c->polkit_registry,
420 error);
421 if (r < 0)
422 return r;
423 if (r == 0)
424 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
425
426 r = free_and_strdup(&c->data[PROP_HOSTNAME], name);
427 if (r < 0)
428 return r;
429
430 r = context_update_kernel_hostname(c);
431 if (r < 0) {
432 log_error_errno(r, "Failed to set host 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/hostname/hostnamed.c", 432, __func__, "Failed to set host name: %m"
) : -abs(_e); })
;
433 return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %m");
434 }
435
436 log_info("Changed host name to '%s'", strna(c->data[PROP_HOSTNAME]))({ 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/hostname/hostnamed.c", 436, __func__, "Changed host name to '%s'"
, strna(c->data[PROP_HOSTNAME])) : -abs(_e); })
;
437
438 (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "Hostname", NULL((void*)0));
439
440 return sd_bus_reply_method_return(m, NULL((void*)0));
441}
442
443static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_error *error) {
444 Context *c = userdata;
445 const char *name;
446 int interactive;
447 int r;
448
449 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/hostname/hostnamed.c", 449
, __PRETTY_FUNCTION__); } while (0)
;
450 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 450
, __PRETTY_FUNCTION__); } while (0)
;
451
452 r = sd_bus_message_read(m, "sb", &name, &interactive);
453 if (r < 0)
454 return r;
455
456 name = empty_to_null(name);
457
458 if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME]))
459 return sd_bus_reply_method_return(m, NULL((void*)0));
460
461 if (!isempty(name) && !hostname_is_valid(name, false0))
462 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid static hostname '%s'", name);
463
464 r = bus_verify_polkit_async(
465 m,
466 CAP_SYS_ADMIN21,
467 "org.freedesktop.hostname1.set-static-hostname",
468 NULL((void*)0),
469 interactive,
470 UID_INVALID((uid_t) -1),
471 &c->polkit_registry,
472 error);
473 if (r < 0)
474 return r;
475 if (r == 0)
476 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
477
478 r = free_and_strdup(&c->data[PROP_STATIC_HOSTNAME], name);
479 if (r < 0)
480 return r;
481
482 r = context_update_kernel_hostname(c);
483 if (r < 0) {
484 log_error_errno(r, "Failed to set host 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/hostname/hostnamed.c", 484, __func__, "Failed to set host name: %m"
) : -abs(_e); })
;
485 return sd_bus_error_set_errnof(error, r, "Failed to set hostname: %m");
486 }
487
488 r = context_write_data_static_hostname(c);
489 if (r < 0) {
490 log_error_errno(r, "Failed to write static host 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/hostname/hostnamed.c", 490, __func__, "Failed to write static host name: %m"
) : -abs(_e); })
;
491 return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %m");
492 }
493
494 log_info("Changed static host name to '%s'", strna(c->data[PROP_STATIC_HOSTNAME]))({ 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/hostname/hostnamed.c", 494, __func__, "Changed static host name to '%s'"
, strna(c->data[PROP_STATIC_HOSTNAME])) : -abs(_e); })
;
495
496 (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL((void*)0));
497
498 return sd_bus_reply_method_return(m, NULL((void*)0));
499}
500
501static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_message_handler_t cb, sd_bus_error *error) {
502 int interactive;
503 const char *name;
504 int r;
505
506 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 506
, __PRETTY_FUNCTION__); } while (0)
;
507 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/hostname/hostnamed.c", 507
, __PRETTY_FUNCTION__); } while (0)
;
508
509 r = sd_bus_message_read(m, "sb", &name, &interactive);
510 if (r < 0)
511 return r;
512
513 name = empty_to_null(name);
514
515 if (streq_ptr(name, c->data[prop]))
516 return sd_bus_reply_method_return(m, NULL((void*)0));
517
518 if (!isempty(name)) {
519 /* The icon name might ultimately be used as file
520 * name, so better be safe than sorry */
521
522 if (prop == PROP_ICON_NAME && !filename_is_valid(name))
523 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid icon name '%s'", name);
524 if (prop == PROP_PRETTY_HOSTNAME && string_has_cc(name, NULL((void*)0)))
525 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid pretty host name '%s'", name);
526 if (prop == PROP_CHASSIS && !valid_chassis(name))
527 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid chassis '%s'", name);
528 if (prop == PROP_DEPLOYMENT && !valid_deployment(name))
529 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid deployment '%s'", name);
530 if (prop == PROP_LOCATION && string_has_cc(name, NULL((void*)0)))
531 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid location '%s'", name);
532 }
533
534 /* Since the pretty hostname should always be changed at the
535 * same time as the static one, use the same policy action for
536 * both... */
537
538 r = bus_verify_polkit_async(
539 m,
540 CAP_SYS_ADMIN21,
541 prop == PROP_PRETTY_HOSTNAME ? "org.freedesktop.hostname1.set-static-hostname" : "org.freedesktop.hostname1.set-machine-info",
542 NULL((void*)0),
543 interactive,
544 UID_INVALID((uid_t) -1),
545 &c->polkit_registry,
546 error);
547 if (r < 0)
548 return r;
549 if (r == 0)
550 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
551
552 r = free_and_strdup(&c->data[prop], name);
553 if (r < 0)
554 return r;
555
556 r = context_write_data_machine_info(c);
557 if (r < 0) {
558 log_error_errno(r, "Failed to write machine info: %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/hostname/hostnamed.c", 558, __func__, "Failed to write machine info: %m"
) : -abs(_e); })
;
559 return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %m");
560 }
561
562 log_info("Changed %s to '%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/hostname/hostnamed.c", 566, __func__, "Changed %s to '%s'"
, prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : prop ==
PROP_DEPLOYMENT ? "deployment" : prop == PROP_LOCATION ? "location"
: prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->
data[prop])) : -abs(_e); })
563 prop == PROP_PRETTY_HOSTNAME ? "pretty host name" :({ 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/hostname/hostnamed.c", 566, __func__, "Changed %s to '%s'"
, prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : prop ==
PROP_DEPLOYMENT ? "deployment" : prop == PROP_LOCATION ? "location"
: prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->
data[prop])) : -abs(_e); })
564 prop == PROP_DEPLOYMENT ? "deployment" :({ 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/hostname/hostnamed.c", 566, __func__, "Changed %s to '%s'"
, prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : prop ==
PROP_DEPLOYMENT ? "deployment" : prop == PROP_LOCATION ? "location"
: prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->
data[prop])) : -abs(_e); })
565 prop == PROP_LOCATION ? "location" :({ 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/hostname/hostnamed.c", 566, __func__, "Changed %s to '%s'"
, prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : prop ==
PROP_DEPLOYMENT ? "deployment" : prop == PROP_LOCATION ? "location"
: prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->
data[prop])) : -abs(_e); })
566 prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->data[prop]))({ 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/hostname/hostnamed.c", 566, __func__, "Changed %s to '%s'"
, prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : prop ==
PROP_DEPLOYMENT ? "deployment" : prop == PROP_LOCATION ? "location"
: prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->
data[prop])) : -abs(_e); })
;
567
568 (void) sd_bus_emit_properties_changed(
569 sd_bus_message_get_bus(m),
570 "/org/freedesktop/hostname1",
571 "org.freedesktop.hostname1",
572 prop == PROP_PRETTY_HOSTNAME ? "PrettyHostname" :
573 prop == PROP_DEPLOYMENT ? "Deployment" :
574 prop == PROP_LOCATION ? "Location" :
575 prop == PROP_CHASSIS ? "Chassis" : "IconName" , NULL((void*)0));
576
577 return sd_bus_reply_method_return(m, NULL((void*)0));
578}
579
580static int method_set_pretty_hostname(sd_bus_message *m, void *userdata, sd_bus_error *error) {
581 return set_machine_info(userdata, m, PROP_PRETTY_HOSTNAME, method_set_pretty_hostname, error);
582}
583
584static int method_set_icon_name(sd_bus_message *m, void *userdata, sd_bus_error *error) {
585 return set_machine_info(userdata, m, PROP_ICON_NAME, method_set_icon_name, error);
586}
587
588static int method_set_chassis(sd_bus_message *m, void *userdata, sd_bus_error *error) {
589 return set_machine_info(userdata, m, PROP_CHASSIS, method_set_chassis, error);
590}
591
592static int method_set_deployment(sd_bus_message *m, void *userdata, sd_bus_error *error) {
593 return set_machine_info(userdata, m, PROP_DEPLOYMENT, method_set_deployment, error);
594}
595
596static int method_set_location(sd_bus_message *m, void *userdata, sd_bus_error *error) {
597 return set_machine_info(userdata, m, PROP_LOCATION, method_set_location, error);
598}
599
600static const sd_bus_vtable hostname_vtable[] = {
601 SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = {
.element_size = sizeof(sd_bus_vtable) }, }, }
,
602 SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "Hostname", .signature = "s"
, .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_HOSTNAME, }, }, }
,
603 SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "StaticHostname", .signature
= "s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_STATIC_HOSTNAME, }, },
}
,
604 SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "PrettyHostname", .signature
= "s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, }, },
}
,
605 SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "IconName", .signature = "s"
, .get = property_get_icon_name, .set = ((void*)0), .offset =
0, }, }, }
,
606 SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "Chassis", .signature = "s",
.get = property_get_chassis, .set = ((void*)0), .offset = 0,
}, }, }
,
607 SD_BUS_PROPERTY("Deployment", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "Deployment", .signature = "s"
, .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, }, }, }
,
608 SD_BUS_PROPERTY("Location", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_LOCATION, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
, .x = { .property = { .member = "Location", .signature = "s"
, .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_LOCATION, }, }, }
,
609 SD_BUS_PROPERTY("KernelName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "KernelName", .signature = "s"
, .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, }, }, }
,
610 SD_BUS_PROPERTY("KernelRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "KernelRelease", .signature =
"s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, }, }, }
,
611 SD_BUS_PROPERTY("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "KernelVersion", .signature =
"s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, }, }, }
,
612 SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "OperatingSystemPrettyName",
.signature = "s", .get = ((void*)0), .set = ((void*)0), .offset
= __builtin_offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME
, }, }, }
,
613 SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "OperatingSystemCPEName", .signature
= "s", .get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, }, }, }
,
614 SD_BUS_PROPERTY("HomeURL", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOME_URL, SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "HomeURL", .signature = "s",
.get = ((void*)0), .set = ((void*)0), .offset = __builtin_offsetof
(Context, data) + sizeof(char*) * PROP_HOME_URL, }, }, }
,
615 SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetHostname", .signature = "sb"
, .result = ((void*)0), .handler = method_set_hostname, .offset
= 0, }, }, }
,
616 SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_hostname, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetStaticHostname", .signature
= "sb", .result = ((void*)0), .handler = method_set_static_hostname
, .offset = 0, }, }, }
,
617 SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetPrettyHostname", .signature
= "sb", .result = ((void*)0), .handler = method_set_pretty_hostname
, .offset = 0, }, }, }
,
618 SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetIconName", .signature = "sb"
, .result = ((void*)0), .handler = method_set_icon_name, .offset
= 0, }, }, }
,
619 SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetChassis", .signature = "sb"
, .result = ((void*)0), .handler = method_set_chassis, .offset
= 0, }, }, }
,
620 SD_BUS_METHOD("SetDeployment", "sb", NULL, method_set_deployment, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDeployment", .signature = "sb"
, .result = ((void*)0), .handler = method_set_deployment, .offset
= 0, }, }, }
,
621 SD_BUS_METHOD("SetLocation", "sb", NULL, method_set_location, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLocation", .signature = "sb"
, .result = ((void*)0), .handler = method_set_location, .offset
= 0, }, }, }
,
622 SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, },
623};
624
625static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
626 _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0);
627 int r;
628
629 assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("c"), "../src/hostname/hostnamed.c", 629
, __PRETTY_FUNCTION__); } while (0)
;
630 assert(event)do { if ((__builtin_expect(!!(!(event)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("event"), "../src/hostname/hostnamed.c",
630, __PRETTY_FUNCTION__); } while (0)
;
631 assert(_bus)do { if ((__builtin_expect(!!(!(_bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("_bus"), "../src/hostname/hostnamed.c", 631
, __PRETTY_FUNCTION__); } while (0)
;
632
633 r = sd_bus_default_system(&bus);
634 if (r < 0)
635 return log_error_errno(r, "Failed to get system bus connection: %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/hostname/hostnamed.c", 635, __func__, "Failed to get system bus connection: %m"
) : -abs(_e); })
;
636
637 r = sd_bus_add_object_vtable(bus, NULL((void*)0), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", hostname_vtable, c);
638 if (r < 0)
639 return log_error_errno(r, "Failed to register 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/hostname/hostnamed.c", 639, __func__, "Failed to register object: %m"
) : -abs(_e); })
;
640
641 r = sd_bus_request_name_async(bus, NULL((void*)0), "org.freedesktop.hostname1", 0, NULL((void*)0), NULL((void*)0));
642 if (r < 0)
643 return log_error_errno(r, "Failed to request 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/hostname/hostnamed.c", 643, __func__, "Failed to request name: %m"
) : -abs(_e); })
;
644
645 r = sd_bus_attach_event(bus, event, 0);
646 if (r < 0)
647 return log_error_errno(r, "Failed to attach bus to event loop: %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/hostname/hostnamed.c", 647, __func__, "Failed to attach bus to event loop: %m"
) : -abs(_e); })
;
648
649 *_bus = TAKE_PTR(bus)({ typeof(bus) _ptr_ = (bus); (bus) = ((void*)0); _ptr_; });
650
651 return 0;
652}
653
654int main(int argc, char *argv[]) {
655 Context context = {};
656 _cleanup_(sd_event_unrefp)__attribute__((cleanup(sd_event_unrefp))) sd_event *event = NULL((void*)0);
657 _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0);
658 int r;
659
660 log_set_target(LOG_TARGET_AUTO);
661 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
662 log_open();
663
664 umask(0022);
665 mac_selinux_init();
666
667 if (argc != 1) {
668 log_error("This program takes no arguments.")({ 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/hostname/hostnamed.c", 668, __func__, "This program takes no arguments."
) : -abs(_e); })
;
669 r = -EINVAL22;
670 goto finish;
671 }
672
673 r = sd_event_default(&event);
674 if (r < 0) {
675 log_error_errno(r, "Failed to allocate event loop: %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/hostname/hostnamed.c", 675, __func__, "Failed to allocate event loop: %m"
) : -abs(_e); })
;
676 goto finish;
677 }
678
679 sd_event_set_watchdog(event, true1);
680
681 r = connect_bus(&context, event, &bus);
682 if (r < 0)
683 goto finish;
684
685 r = context_read_data(&context);
686 if (r < 0) {
687 log_error_errno(r, "Failed to read hostname and machine information: %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/hostname/hostnamed.c", 687, __func__, "Failed to read hostname and machine information: %m"
) : -abs(_e); })
;
688 goto finish;
689 }
690
691 r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC(30*((usec_t) 1000000ULL)), NULL((void*)0), NULL((void*)0));
692 if (r < 0) {
693 log_error_errno(r, "Failed to run event loop: %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/hostname/hostnamed.c", 693, __func__, "Failed to run event loop: %m"
) : -abs(_e); })
;
694 goto finish;
695 }
696
697finish:
698 context_free(&context);
699
700 return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0;
701}