nut: Fix unset of runas user (ups server)
authorDaniel F. Dickinson <cshored@thecshore.com>
Tue, 27 Aug 2019 04:15:12 +0000 (00:15 -0400)
committerDaniel F. Dickinson <cshored@thecshore.com>
Tue, 27 Aug 2019 04:46:51 +0000 (00:46 -0400)
Running as non-root was failing due to misplace local keyword
causing runas to be unset from calling value.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
net/nut/files/nut-server.init

index d878e36419d38956e939b0333dd67f13d0be00c7..611d79e06902dff0cc30971882bda471b68900a4 100755 (executable)
@@ -39,12 +39,11 @@ upsd_statepath() {
 }
 
 upsd_runas() {
-       local cfg="$1"
        local runas
 
-       [ -n "$RUNAS" ] && return
+       [ -n "$RUNAS" ] && return 0
 
-       config_get runas "$cfg" runas
+       config_get runas upsd runas
        RUNAS="$runas"
 }
 
@@ -223,7 +222,6 @@ build_global_driver_config() {
        get_write_driver_config "$cfg" synchronous
        config_get runas "$cfg" user
        RUNAS="$runas"
-       upsd_runas
 
        echo "" >>$UPS_C
 }
@@ -239,11 +237,13 @@ build_config() {
        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"
 
        build_server_config
+       [ -n "$RUNAS" ] && chgrp "$(id -gn "$RUNAS")" "$UPS_C"
 }
 
 start_driver_instance() {
@@ -284,8 +284,7 @@ start_driver_instance() {
 }
 
 start_server_instance() {
-       local RUNAS
-       build_config
+       local cfg="$1"
 
        [ "$haveserver" != 1 ] && return
 
@@ -300,7 +299,6 @@ start_server_instance() {
 start_service() {
        local havedriver haveserver
        local STATEPATH=/var/run/nut
-       local RUNAS
 
        # Avoid hotplug inadvertenly restarting driver during
        # forced shutdown