]>
git.proxmox.com Git - systemd.git/blob - src/core/hostname-setup.c
2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "alloc-util.h"
26 #include "hostname-setup.h"
27 #include "hostname-util.h"
30 #include "string-util.h"
33 int hostname_setup(void) {
35 _cleanup_free_
char *b
= NULL
;
39 r
= read_hostname_config("/etc/hostname", &b
);
44 log_warning_errno(r
, "Failed to read configured hostname: %m");
51 /* Don't override the hostname if it is already set
52 * and not explicitly configured */
53 if (hostname_is_set())
57 log_info("No hostname configured.");
62 r
= sethostname_idempotent(hn
);
64 return log_warning_errno(r
, "Failed to set hostname to <%s>: %m", hn
);
66 log_info("Set hostname to <%s>.", hn
);