hostapd: rework postinst script to avoid lock-ups on first boot

The postinst script tries parsing the wireless MAC address from the sysfs, and
in case of failure, obtains a random string from /dev/urandom. This caused two
problems when booting with systemd:

 * The wifi interface's sysfs entry is not available because the interface
hasn't had time to start up yet, forcing the script to always resort to the
/dev/urandom fallback.
 * Even though the postinst scripts are run after populating the volatile
filesystems (as can be seen in run-postinsts.service's dependencies), trying
to read either /dev/random or /dev/urandom at this point in the system's
initialization causes it to lock up indefinitely.

To avoid either situation, add the following changes:

 * Immediately exit when running on a non-wireless target, as the script isn't
necessary in this use case.
 * Parse the wireless mac address from /proc/device-tree/wireless, which is
guaranteed to always be available when the script runs. By doing this, we can
remove the /dev/urandom fallback entirely.

https://jira.digi.com/browse/DEL-6415

Signed-off-by: Gabriel Valcazar <gabriel.valcazar@digi.com>
This commit is contained in:
Gabriel Valcazar 2019-02-14 13:56:02 +01:00
parent 803dde16b0
commit b769f90e2a
1 changed files with 6 additions and 6 deletions

View File

@ -30,16 +30,16 @@ do_install_append_ccimx8x() {
}
pkg_postinst_ontarget_${PN}() {
# Exit if there is no wireless hardware available
if [ ! -e /proc/device-tree/wireless/mac-address ]; then
exit 0
fi
# Append the last two bytes of the wlan0 MAC address to the SSID of the
# hostAP configuration files
# Get the last two bytes of the wlan0 MAC address
MAC="$(cut -d ':' -f5,6 /sys/class/net/wlan0/address | tr -d ':')"
# If wlan0 is not available, use a random value with no hexadecimal characters
if [ -z "${MAC}" ]; then
MAC="$(cat /dev/urandom | tr -dc 'G-Z' | fold -w 4 | head -n 1)"
fi
MAC="$(dd conv=swab if=/proc/device-tree/wireless/mac-address 2>/dev/null | hexdump | head -n 1 | cut -d ' ' -f 4)"
find "${sysconfdir}" -type f -name 'hostapd_wlan?.conf' -exec \
sed -i -e "s,##MAC##,${MAC},g" {} \;