Conversation
This is significantly less overhead than an init script.
dwfreed
left a comment
There was a problem hiding this comment.
This does not handle the case where the hostname is being set via /etc/conf.d/hostname which the initscript allows. A deprecation warning should be added to the initscript, and a louder one should be added for users of the conf.d method.
|
|
||
| if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) { | ||
| if (buffer[len - 2] == '\n') | ||
| buffer[--len - 1] = '\0'; |
There was a problem hiding this comment.
Please split this into 2 lines; it'd be much more readable that way.
| size_t len; | ||
|
|
||
| if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) { | ||
| if (buffer[len - 2] == '\n') |
There was a problem hiding this comment.
This doesn't handle the case where len is 0 or 1, resulting in an out of bounds read and potentially an out of bounds write (!!!)
| char *buffer = NULL; | ||
| size_t len; | ||
|
|
||
| if (rc_getfile(RC_SYSCONFDIR "/hostname", &buffer, &len)) { |
There was a problem hiding this comment.
The hostname tool from net-tools on Linux has a -b flag that will fall back to setting the hostname to localhost 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.
This is an alternative to #585 in which we keep the init script but use `hostname -F` to read the value from @SYSCONFDIR@/hostname. This allows for comments in the hostname file. Also, we deprecate using /etc/conf.d/* to set the host name.
This is significantly less overhead than an init script.