]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
daemon: rewrite $@ to modify command, use runuser instead of su
authorElan Ruusamäe <glen@delfi.ee>
Thu, 8 Oct 2015 15:05:32 +0000 (18:05 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Thu, 8 Oct 2015 15:05:33 +0000 (18:05 +0300)
this simplifies and avoids shell syntax. but until initlog, sigh

lib/functions

index ecd8e8d95063990fee18912ccedeec7dcce7fec1..6ded51470f77b561bc81aa26f07f05cc4649afe9 100644 (file)
@@ -628,9 +628,10 @@ _daemon_set_ulimits() {
        done
 }
 
-# inner function used by daemon()
-# do not call this directly, as it expects variables being inherited
-# it expects options parsed by daemon() and command to be executed in "$@"
+# inner function used by daemon().
+# do not call this directly, as it expects variables being inherited.
+# also it expects to be called from subshell as it exports env.
+# it expects options parsed by daemon() and command to be executed in "$@".
 _daemon_exec() {
        local prog=""
        umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
@@ -689,21 +690,14 @@ _daemon_exec() {
                        --exec "$prog" \
                        -- "$@"
        else
-               if [ -n "$user" -a "$user" != "root" ]; then
-                       prog="/bin/su $user -s /bin/sh -c \""
-               fi
                if [ "$fork" = "1" ]; then
-                       prog="/usr/bin/setsid ${prog:-sh -c \"}"
+                       set -- /usr/bin/setsid "$@"
                fi
-               # If command to execute ends with quotation mark, add remaining
-               # arguments and close quotation.
-               if [ "$prog" != "${prog%\"}" ]; then
-                       prog="$prog $*$end\""
-               else
-                       prog="$prog $*$end"
+               if [ -n "$user" -a "$user" != "root" ]; then
+                       set -- /bin/runuser -u "$user" -- "$@"
                fi
 
-               nice -n $nice initlog -c "$prog" 2>&1 </dev/null
+               nice -n $nice initlog -c "$*" 2>&1 </dev/null
        fi
 }
 
This page took 0.301104 seconds and 4 git commands to generate.