From e97684652125844c451e7fbf127b8f0a35653492 Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Tue, 27 Aug 2019 00:19:03 -0400 Subject: [PATCH] nut: Fix statepath handling The statepath was getting the wrong permission and/or not created at the right time. This commit includes fixes for handling the statepath (typically /var/run/nut). Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-server.init | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 611d79e06..8062861fd 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -31,10 +31,9 @@ get_write_driver_config() { } upsd_statepath() { - local cfg="$1" local statepath - config_get statepath "$cfg" statepath "/var/run/nut" + config_get statepath upsd statepath /var/run/nut STATEPATH="$statepath" } @@ -64,7 +63,7 @@ upsd_config() { config_get runas "$cfg" runas RUNAS="$runas" - config_get statepath "$cfg" statepath "/var/run/nut" + config_get statepath "$cfg" statepath /var/run/nut STATEPATH="$statepath" config_get maxage "$cfg" maxage @@ -128,13 +127,14 @@ build_server_config() { chmod 0644 /var/etc/nut/nut.conf [ -d "${STATEPATH}" ] || { - mkdir -m 0750 -p "${STATEPATH}" + mkdir -p "${STATEPATH}" + chmod 0750 "${STATEPATH}" } if [ -n "$RUNAS" ]; then - chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}" - chgrp $(id -gn $RUNAS) "$USERS_C" - chgrp $(id -gn $RUNAS) "$UPSD_C" + chown "$RUNAS":"$(id -gn "$RUNAS")" "${STATEPATH}" + chgrp "$(id -gn "$RUNAS")" "$USERS_C" + chgrp "$(id -gn "$RUNAS")" "$UPSD_C" fi haveserver=1 } @@ -235,13 +235,11 @@ build_config() { chmod 0640 "$UPS_C" config_load nut_server - config_foreach upsd_statepath upsd upsd_runas config_foreach build_global_driver_config driver_global config_foreach build_driver_config driver - [ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C" - + upsd_statepath build_server_config [ -n "$RUNAS" ] && chgrp "$(id -gn "$RUNAS")" "$UPS_C" } @@ -260,18 +258,19 @@ start_driver_instance() { mkdir -m 0755 -p "$(dirname "$UPS_C")" - [ ! -s "$UPS_C" ] && build_config + upsd_statepath + build_config # Avoid hotplug inadvertenly restarting driver during # forced shutdown [ -f /var/run/killpower ] && return 0 - [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0 - - - config_foreach upsd_statepath upsd + if [ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ]; then + return 0 + fi if [ -n "$RUNAS" ]; then - chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}" + chown "$RUNAS":"$(id -gn "$RUNAS")" "${STATEPATH}" + chgrp "$(id -gn "$RUNAS")" "$UPS_C" fi config_get driver "$cfg" driver "usbhid-ups"