>Synopsis: rc(8) ignores last line without newline of *.conf
System : OpenBSD 6.4
Details : OpenBSD 6.4-current (GENERIC) #527: Mon Dec 24 22:16:45 MST 2018
Machine : amd64
When /etc/rc reads some configuration files, it ignores the
last line if it doesn't end with a newline. I noticed this problem
after Reddit's /u/FOSSilized_Daemon reported that the last line of
mixerctl.conf didn't work:
https://www.reddit.com/r/openbsd/comments/a9lnu1/mixerctl_and_audio_configuration/ecmzvvx/ stripcom() in /etc/rc uses `while read _line ; do ... done`
to read these files, but `read _line` exits 1 when the last line is
without a newline. This behavior in sh and ksh is consistent with
bash, dash, ksh93, and yash:
$ printf what | ksh -c 'read p; echo $p $?'
$ printf what | bash -c 'read p; echo $p $?'
ksh(1) only says, "If no input is read, *read* exits with
a non-zero status." bash(1), dash(1), and ksh93(1) mention that
*read* fails when EOF. yash(1) says, "Note that the exit status is
non-zero if an end of input is encountered before reading the entire
In a machine with no sysctl.conf:
# printf kern.hostid=1 > /etc/sysctl.conf
After the reboot:
$ sysctl kern.hostid
Can also copy stripcom() to another script and test it.
One can work around the problem by ending files like
sysctl.conf(5) with a newline.
The fix might require fixing stripcom() in /etc/rc, fixing
stripcom() in /etc/netstart, and changing the manuals of sh(1) and
ksh(1) to describe what happens when there is no final newline.
The following version of stripcom() might work, but I'm not
sure. It adds `|| [[ -n $_line ]]` to the while condition.
Re: rc(8) ignores last line without newline of *.conf
George Koehler wrote:
> stripcom() in /etc/rc uses `while read _line ; do ... done`
> to read these files, but `read _line` exits 1 when the last line is
> without a newline. This behavior in sh and ksh is consistent with
> bash, dash, ksh93, and yash: