Skip to content

Commit

Permalink
rc: use /etc/hostname if available
Browse files Browse the repository at this point in the history
This is significantly less overhead than an init script.
  • Loading branch information
vapier authored and williamh committed Jul 25, 2024
1 parent ba6de6d commit 2fc625b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/openrc/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
Expand Down

0 comments on commit 2fc625b

Please sign in to comment.