X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fhostname-setup.c;h=e9869bb4dff4d64f6d8d1500bd956815fc38cd26;hp=8b0ff793847ee78ecec438009cff10ba15314d96;hb=43515ba0cecda2be8244a9f75078ac4a561092d9;hpb=a338bab5d0603a179befce062bc6fc8a6521a232 diff --git a/src/hostname-setup.c b/src/hostname-setup.c index 8b0ff7938..e9869bb4d 100644 --- a/src/hostname-setup.c +++ b/src/hostname-setup.c @@ -30,7 +30,7 @@ #include "util.h" #include "log.h" -#if defined(TARGET_FEDORA) || defined(TARGET_ALTLINUX) +#if defined(TARGET_FEDORA) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) #define FILENAME "/etc/sysconfig/network" #elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) || defined(TARGET_FRUGALWARE) #define FILENAME "/etc/HOSTNAME" @@ -87,7 +87,7 @@ 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) +#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) int r; FILE *f; @@ -174,16 +174,36 @@ int hostname_setup(void) { else log_warning("Failed to read configured hostname: %s", strerror(-r)); - hn = "localhost"; + hn = NULL; } else hn = b; + if (!hn) { + /* Don't override the hostname if it is unset and not + * explicitly configured */ + + char *old_hostname = NULL; + + if ((old_hostname = gethostname_malloc())) { + bool already_set; + + already_set = old_hostname[0] != 0; + free(old_hostname); + + if (already_set) + goto finish; + } + + hn = "localhost"; + } + if (sethostname(hn, strlen(hn)) < 0) { log_warning("Failed to set hostname to <%s>: %m", hn); r = -errno; } else log_info("Set hostname to <%s>.", hn); +finish: free(b); return r;