]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - lib/functions
daemon ssd mode: always setsid, so programs that properly don't daemonize get detache...
[projects/rc-scripts.git] / lib / functions
index 56cab8051812f76851c20bf7fd4e7767a7ba5ba5..aee3cc1fff66dddf06e08dbcd3f12c5690132895 100644 (file)
@@ -726,13 +726,14 @@ daemon() {
                if [ "$closefds" = 1 ]; then
                        exec 1>&-
                        exec 2>&-
-                       exec 0>&-
+                       exec 0<&-
                elif [ "$redirfds" = 1 ]; then
                        exec 1>/dev/null
                        exec 2>/dev/null
-                       exec 0>/dev/null
+                       exec 0</dev/null
                else
                        exec 2>&1
+                       exec 0</dev/null
                fi
 
                if is_no "$RC_LOGGING"; then
@@ -749,6 +750,14 @@ daemon() {
                                done
                                IFS=$o
                        fi
+                       set -- "$prog" "$@"
+
+                       # use setsid to detach from terminal,
+                       # needs pidfile or ssd would check setsid program instead of real program
+                       if [ "$pidfile" ]; then
+                               set -- /usr/bin/setsid "$@"
+                       fi
+
                        /sbin/start-stop-daemon -q --start \
                                --nicelevel $nice \
                                ${pidfile:+--pidfile $pidfile} \
@@ -758,8 +767,8 @@ daemon() {
                                ${fork:+--background} \
                                ${waitname:+--name $waitname} \
                                ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
-                               --exec "$prog" \
-                               -- ${1:+"$@"}
+                               --exec "$1" \
+                               -- "$@"
                else
                        nice -n $nice initlog -c "$prog" 2>&1 </dev/null
                fi
This page took 0.036949 seconds and 4 git commands to generate.