Index | Thread | Search

From:
obsd@mulh.net
Subject:
Update stripcom function in netstart
To:
tech@openbsd.org
Date:
Thu, 4 Sep 2025 07:09:00 -0400

Download raw body.

Thread
  • obsd@mulh.net:

    Update stripcom function in netstart

Could the "stripcom" function in /etc/netstart be replaced
to use the (better) stripcom function from /etc/rc?

Besides being consistent in function definition the rc version
will remove inline comments whereas the netstart version does not.

True that the netstart script barely uses stripcom itself but the
updated function would be useful doing includes in hostname.if files.

For example in my /etc/hostname.wg0 file I have:
   inet 192.0.2.1 0xffffff00
   $(stripcom /etc/wireguard.wg0)

This keeps the secrets (and complexity) out of the hostname.if file.
Helps as I prefer not to have "+" for hostname.if files in changelist.

Since $(...) concatenates everything into one line (ok for wireguard)
the netstart version of stripcom effectively makes the first comment
comment out the rest of the file.


/etc/netstart:
-  # Echo file $1 to stdout. Skip comment lines. Strip leading and trailing
-  # whitespace if IFS is set.
+  # Strip in- and whole-line comments from a file.
+  # Strip leading and trailing whitespace if IFS is set.
   # Usage: stripcom /path/to/file
   stripcom() {
           local _file=$1 _line

-          [[ -f $_file ]] || return
+          [[ -s $_file ]] || return

           while read _line; do
-                  [[ -n ${_line%%#*} ]] && print -r -- "$_line"
+                  _line=${_line%%#*}
+                  [[ -n $_line ]] && print -r -- "$_line"
           done <$_file
   }


In /etc/rc there is an extra space in the "while" line in stripcom.

/etc/rc:
-          while read _line ; do
+          while read _line; do


I'm a user not a developer so I don't know how to create proper diffs.