[projects/rc-scripts] daemon: rewrite $@ to modify command, use runuser instead of su

glen glen at pld-linux.org
Sat Oct 10 01:32:51 CEST 2015


commit 8714ffa414c8f182efa0bddf96486d99b89651bd
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Thu Oct 8 18:05:32 2015 +0300

    daemon: rewrite $@ to modify command, use runuser instead of su
    
    this simplifies and avoids shell syntax. but until initlog, sigh

 lib/functions | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
---
diff --git a/lib/functions b/lib/functions
index ecd8e8d..6ded514 100644
--- a/lib/functions
+++ b/lib/functions
@@ -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
 }
 
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/rc-scripts.git/commitdiff/1a0c02d0983a76562fa875a1bab45ece246b26a6



More information about the pld-cvs-commit mailing list