Дана 25/12/20 04:00PM, [email protected] написа:
> Before you complain about my daemon= line, I agree it is better
> to make a copy of the script and put the full-path-to-the-daemon
> in there!
> 
> I wanted a generic way to find the path to the daemon that would
> not be influenced by the caller's PATH.  (safety, consistency)

A bit safer (not dependant on PATH) might be something like:

        #!/bin/ksh

        prog=${0##*/}

        if [ -x /usr/sbin/"$prog" ]; then
                daemon=/usr/sbin/"$prog"
        elif [ -x /usr/local/sbin/"$prog" ]; then
                daemon=/usr/local/sbin/"$prog"
        else
                exit 1
        fi

        . /etc/rc.d/rc.subr

        rc_cmd $1

This way, if the executable is moved from /usr/local/sbin to /usr/sbin,
the transition is seamless, but other directories in PATH or default
search path are not considered. The if-construct is used deliberately 
instead of altering PATH, to preserve it for $prog.

Reply via email to