Skip to content

Commit a4cfc9b

Browse files
vapierwilliamh
authored andcommitted
rc: use /etc/hostname if available
This is significantly less overhead than an init script.
1 parent 0b86c06 commit a4cfc9b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/openrc/rc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,33 @@ handle_signal(int sig)
451451
errno = serrno;
452452
}
453453

454+
static void
455+
do_early_hostname(void)
456+
{
457+
#ifdef __linux__
458+
/* Set hostname if available */
459+
char *buffer = NULL;
460+
size_t len;
461+
462+
if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) {
463+
if (buffer[len - 2] == '\n')
464+
buffer[--len - 1] = '\0';
465+
if (sethostname(buffer, len)) {
466+
/* ignore */;
467+
}
468+
free(buffer);
469+
}
470+
#endif
471+
}
472+
454473
static void
455474
do_sysinit()
456475
{
457476
struct utsname uts;
458477
const char *sys;
459478

479+
do_early_hostname();
480+
460481
/* exec init-early.sh if it exists
461482
* This should just setup the console to use the correct
462483
* font. Maybe it should setup the keyboard too? */

0 commit comments

Comments
 (0)