X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=hostname-setup.c;h=b8551d9802feb48715d8ebffdfa47c2d0c9b8777;hp=5f3ee77ac01a61d3ffc94745d5609f967f47ba46;hb=3177a7fa12247d30b854fcb7697cd578b9086bf5;hpb=206bf5c294d300cf05ee7b17c5bf42a21f6a52c0 diff --git a/hostname-setup.c b/hostname-setup.c index 5f3ee77ac..b8551d980 100644 --- a/hostname-setup.c +++ b/hostname-setup.c @@ -32,15 +32,27 @@ #define LINE_MAX 4096 +#if defined(TARGET_FEDORA) +#define FILENAME "/etc/sysconfig/network" +#elif defined(TARGET_SUSE) +#define FILENAME "/etc/HOSTNAME" +#elif defined(TARGET_DEBIAN) +#define FILENAME "/etc/hostname" +#elif defined(TARGET_ARCH) +#define FILENAME "/etc/rc.conf" +#elif defined(TARGET_GENTOO) +#define FILENAME "/etc/conf.d/hostname" +#endif + static int read_hostname(char **hn) { -#if defined(TARGET_FEDORA) +#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) int r; FILE *f; assert(hn); - if (!(f = fopen("/etc/sysconfig/network", "re"))) + if (!(f = fopen(FILENAME, "re"))) return -errno; for (;;) { @@ -57,7 +69,7 @@ static int read_hostname(char **hn) { s = strstrip(line); - if (!startswith(s, "HOSTNAME=")) + if (!startswith_no_case(s, "HOSTNAME=")) continue; if (!(k = strdup(s+9))) { @@ -65,6 +77,11 @@ static int read_hostname(char **hn) { goto finish; } + if (!(k = delete_chars(k, "\"\'"))) { + r = -ENOMEM; + goto finish; + } + *hn = k; break; } @@ -75,13 +92,13 @@ finish: fclose(f); return r; -#elif defined(TARGET_SUSE) +#elif defined(TARGET_SUSE) || defined(TARGET_DEBIAN) int r; char *s, *k; assert(hn); - if ((r = read_one_line_file("/etc/HOSTNAME", &s)) < 0) + if ((r = read_one_line_file(FILENAME, &s)) < 0) return r; k = strdup(strstrip(s)); @@ -92,22 +109,6 @@ finish: *hn = k; -#elif defined(TARGET_DEBIAN) - int r; - char *s, *k; - - assert(hn); - - if ((r = read_one_line_file("/etc/hostname", &s)) < 0) - return r; - - k = strdup(strstrip(s)); - free(s); - - if (!k) - return -ENOMEM; - - *hn = k; #else #warning "Don't know how to read the hostname"