-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rc: use /etc/hostname if available #585
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,12 +473,31 @@ handle_signal(int sig) | |
errno = serrno; | ||
} | ||
|
||
static void | ||
do_early_hostname(void) | ||
{ | ||
/* Set hostname if available */ | ||
char *buffer = NULL; | ||
size_t len; | ||
|
||
if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) { | ||
if (buffer[len - 2] == '\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't handle the case where |
||
buffer[--len - 1] = '\0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please split this into 2 lines; it'd be much more readable that way. |
||
if (sethostname(buffer, len)) { | ||
/* ignore */; | ||
} | ||
free(buffer); | ||
} | ||
} | ||
|
||
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? */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
hostname
tool from net-tools on Linux has a-b
flag that will fall back to setting the hostname tolocalhost
if the file does not exist or is empty; this would probably be a good idea to implement, as on Linux, the hostname could be an empty string otherwise.hostname
also allows for comment lines (line starts with#
) in/etc/hostname
, which are ignored; this could also be useful.