From 2fc625bbab024176edd8fa9ba447032cb2802356 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 3 Dec 2011 05:46:48 -0500 Subject: [PATCH] rc: use /etc/hostname if available This is significantly less overhead than an init script. --- src/openrc/rc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/openrc/rc.c b/src/openrc/rc.c index 5bee9e6cf..b5cec8739 100644 --- a/src/openrc/rc.c +++ b/src/openrc/rc.c @@ -473,12 +473,33 @@ handle_signal(int sig) errno = serrno; } +static void +do_early_hostname(void) +{ +#ifdef __linux__ + /* Set hostname if available */ + char *buffer = NULL; + size_t len; + + if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) { + if (buffer[len - 2] == '\n') + buffer[--len - 1] = '\0'; + if (sethostname(buffer, len)) { + /* ignore */; + } + free(buffer); + } +#endif +} + static void do_sysinit(void) { struct utsname uts; const char *sys; + do_early_hostname(); + /* exec init-early.sh if it exists * This should just setup the console to use the correct * font. Maybe it should setup the keyboard too? */