]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/hostname-setup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
9 #include "hostname-setup.h"
10 #include "hostname-util.h"
13 #include "string-util.h"
16 int hostname_setup(void) {
17 _cleanup_free_
char *b
= NULL
;
22 r
= read_etc_hostname(NULL
, &b
);
27 log_warning_errno(r
, "Failed to read configured hostname: %m");
34 /* Don't override the hostname if it is already set
35 * and not explicitly configured */
36 if (hostname_is_set())
40 log_info("No hostname configured.");
42 hn
= FALLBACK_HOSTNAME
;
45 r
= sethostname_idempotent(hn
);
47 return log_warning_errno(r
, "Failed to set hostname to <%s>: %m", hn
);
49 log_info("Set hostname to <%s>.", hn
);