hostname-setup.c revision cae356ad49b505a5172d4dbb830d7ec8f32a9953
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering This file is part of systemd.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering Copyright 2010 Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering systemd is free software; you can redistribute it and/or modify it
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering under the terms of the GNU Lesser General Public License as published by
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering (at your option) any later version.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering systemd is distributed in the hope that it will be useful, but
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering Lesser General Public License for more details.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering You should have received a copy of the GNU Lesser General Public License
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering#if defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA)
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE)
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poetteringstatic int read_and_strip_hostname(const char *path, char **hn) {
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poetteringstatic int read_distro_hostname(char **hn) {
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering#if defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA)
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE)
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering return read_and_strip_hostname(FILENAME, hn);
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering /* First, try to load the generic hostname configuration file,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering * that we support on all distributions */
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering r = read_and_strip_hostname("/etc/hostname", hn);
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering log_warning("Failed to read configured hostname: %s", strerror(-r));
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering /* Don't override the hostname if it is already set
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering * and not explicitly configured */
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering log_warning("Failed to set hostname to <%s>: %m", hn);