]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/hostname-setup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
12 #include "alloc-util.h"
14 #include "hostname-setup.h"
15 #include "hostname-util.h"
18 #include "string-util.h"
21 int hostname_setup(void) {
22 _cleanup_free_
char *b
= NULL
;
27 r
= read_etc_hostname(NULL
, &b
);
32 log_warning_errno(r
, "Failed to read configured hostname: %m");
39 /* Don't override the hostname if it is already set
40 * and not explicitly configured */
41 if (hostname_is_set())
45 log_info("No hostname configured.");
47 hn
= FALLBACK_HOSTNAME
;
50 r
= sethostname_idempotent(hn
);
52 return log_warning_errno(r
, "Failed to set hostname to <%s>: %m", hn
);
54 log_info("Set hostname to <%s>.", hn
);