This one time, at band camp, Peter Eisentraut said: > Using getopt to parse the arguments of start_daemon is trouble because > it parses the arguments that are supposed to be passed to the daemon. > For example: > > start_daemon -p /var/run/dirmngr.pid /usr/bin/dirmngr --daemon --sh > > What it tried running is this: > > /sbin/start-stop-daemon --start --nicelevel 0 --quiet --exec -p --oknodo > --pidfile /dev/null -- /var/run/dirmngr.pid /usr/bin/dirmngr --daemon --sh > > Which ended up this way: > > /sbin/start-stop-daemon: stat -p: No such file or directory (No such file or > directory) > > So this init script is broken.
The problem as I found it, is slightly more subtle than I realized when
sending what turned out to be a horribly broken pathc (sorry, Chris - my
tests worked fine, but I guess I wasn't thorough enough).
The main problem is that OPTIND isn't reset across getopt calls, making
it do wierd and unexpec ted things on the next run.
This patch should fix that (and takes care of the remaining bugs my
patch introduced, I think)
--- init-functions 2006-08-07 19:15:46.000000000 +0100
+++ init-functions 2006-08-09 00:28:10.000000000 +0100
@@ -33,6 +33,7 @@
nice=0
pidfile=/dev/null
+ OPTIND=1
while getopts fn:p: opt ; do
case "$opt" in
f) force=1;;
@@ -42,10 +43,11 @@
done
shift $(($OPTIND - 1))
- [ "$1" = '--' ] && shift
exec="$1"; shift
+ [ "$1" = '--' ] && shift
+
if [ $force = 1 ]; then
/sbin/start-stop-daemon --start --nicelevel $nice --quiet --startas
$exec --pidfile /dev/null --oknodo -- "$@"
elif [ $pidfile ]; then
@@ -60,8 +62,9 @@
pidfile=
specified=
- while getopts p:- opt ; do
- case $opt in
+ OPTIND=1
+ while getopts p: opt ; do
+ case "$opt" in
p) pidfile="$OPTARG"; specified=1;;
esac
done
@@ -97,8 +100,9 @@
pidfile=
specified=
- while getopts p:- opt ; do
- case $i in
+ OPTIND=1
+ while getopts p: opt ; do
+ case "$opt" in
p) pidfile="$OPTARG"; specified=1;;
esac
done
Thanks, and sorry again,
--
-----------------------------------------------------------------
| ,''`. Stephen Gran |
| : :' : [EMAIL PROTECTED] |
| `. `' Debian user, admin, and developer |
| `- http://www.debian.org |
-----------------------------------------------------------------
signature.asc
Description: Digital signature

