X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fcore%2Fhostname-setup.c;h=dbd2227e212d47464d190eba8a77c43d9de6f4cb;hb=075ff6863d39c8c2846b53e31707605545b1f17e;hp=03b5f472a55287ce31c4c547265d5e203f74f94c;hpb=fb3d2b8fec7c705d8027e6967adae0c2a86acf31;p=elogind.git diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c index 03b5f472a..dbd2227e2 100644 --- a/src/core/hostname-setup.c +++ b/src/core/hostname-setup.c @@ -30,12 +30,10 @@ #include "util.h" #include "log.h" -#if defined(TARGET_FEDORA) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MEEGO) || defined(TARGET_MAGEIA) +#if defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA) #define FILENAME "/etc/sysconfig/network" #elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) #define FILENAME "/etc/HOSTNAME" -#elif defined(TARGET_ARCH) -#define FILENAME "/etc/rc.conf" #elif defined(TARGET_GENTOO) #define FILENAME "/etc/conf.d/hostname" #endif @@ -65,9 +63,9 @@ static int read_and_strip_hostname(const char *path, char **hn) { static int read_distro_hostname(char **hn) { -#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MEEGO) || defined(TARGET_MAGEIA) +#if defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA) int r; - FILE *f; + _cleanup_fclose_ FILE *f = NULL; assert(hn); @@ -114,7 +112,6 @@ static int read_distro_hostname(char **hn) { r = -ENOENT; finish: - fclose(f); return r; #elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) @@ -151,31 +148,20 @@ int hostname_setup(void) { r = read_hostname(&b); if (r < 0) { + hn = NULL; + if (r == -ENOENT) enoent = true; else log_warning("Failed to read configured hostname: %s", strerror(-r)); - - hn = NULL; } else hn = b; - if (!hn) { - /* Don't override the hostname if it is unset and not - * explicitly configured */ - - char *old_hostname = NULL; - - old_hostname = gethostname_malloc(); - if (old_hostname) { - bool already_set; - - already_set = old_hostname[0] != 0; - free(old_hostname); - - if (already_set) - goto finish; - } + if (isempty(hn)) { + /* Don't override the hostname if it is already set + * and not explicitly configured */ + if (hostname_is_set()) + goto finish; if (enoent) log_info("No hostname configured.");