Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 6029 - [RC-Scripts] Custom commandline options not working 100% correctly
Summary: [RC-Scripts] Custom commandline options not working 100% correctly
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Martin Schlemmer (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-05 03:39 UTC by Pieter Boeren
Modified: 2002-08-07 13:06 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/sbin/runscript.sh (runscript.sh,12.75 KB, text/plain)
2002-08-05 14:23 UTC, Martin Schlemmer (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pieter Boeren 2002-08-05 03:39:26 UTC
Followed the RC-Script guide (http://www.gentoo.org/doc/rc-scripts.html), but 
when I came to the custom commandline options, I noticed a strange behavior. 
When I put opts="${opts} foo" in my script and provide a foo() function (as 
said in the guide), a call to the script (called script for this example) with 
an unknown parameter gives this as result (look at the "Usage" section): 
 
* ERROR: wrong args. (  star / star ) 
 
* Usage: script {foo|foo} 
*        script without arguments for full help 
 
Two times "foo", but "start", "stop", "restart" are gone (but do work!).
Comment 1 SpanKY gentoo-dev 2002-08-05 10:52:56 UTC
could you perhaps post your script ? :)
Comment 2 Pieter Boeren 2002-08-05 11:10:14 UTC
I could do that, but it is a generic problem ;) 
 
Just something like: 
 
!/sbin/runscript 
 
opts="${opts} foo" 
 
start() { 
  echo "start" 
} 
 
foo() { 
  echo "foo" 
} 
 
will cause the strange behavior when you call it with a unknow commandline 
parameter. 
Comment 3 Pieter Boeren 2002-08-05 11:13:40 UTC
The missing # in front of !/sbin/runscript is a copy-paste mistake by me, but I 
can edit my message I believe. In the script is it there though ;) 
Comment 4 Martin Schlemmer (RETIRED) gentoo-dev 2002-08-05 13:00:44 UTC
Seems like I have fixed whatever the problem was already.  Try
baselayout-1.8.0 (masked) and let me know, thanks.

-------------------------snip---------------------------
nosferatu tmp # /etc/init.d/foo start
start
nosferatu tmp # /etc/init.d/foo stop 
nosferatu tmp # /etc/init.d/foo stop
 * ERROR:  "foo" has not yet been started.
nosferatu tmp # /etc/init.d/foo foo 
foo
nosferatu tmp # /etc/init.d/foo start
start
nosferatu tmp # /etc/init.d/foo foo
foo
nosferatu tmp # cat /etc/init.d/foo
#!/sbin/runscript 
 
opts="${opts} foo" 
 
start() { 
  echo "start" 
} 
 
foo() { 
  echo "foo" 
} 
 
nosferatu tmp # 
-------------------------snip---------------------------
Comment 5 Pieter Boeren 2002-08-05 13:17:51 UTC
But what happens if you run your script with: "/etc/init.d/foo testing123" 
(without making any changes to your script!!)?    
    
According to me you have to get (as part of the output): "Usage: foo (foo|foo}" 
and not "Usage: foo (start|stop|restart|foo}" 
Comment 6 SpanKY gentoo-dev 2002-08-05 13:31:24 UTC
i use baselayout on my machines and i get the same results as him
he isnt saying that {start,stop,foo} dont work, hes saying the help is wrong

root@rux0r root # ./test f
 * ERROR:  wrong args. (  f / f )

 * Usage: test {foo|foo}
 *        test without arguments for full help
Comment 7 SpanKY gentoo-dev 2002-08-05 13:42:49 UTC
*** i guess at this point in runscript.sh:
source ${myscript}

if [ -z "${opts}" ]
then
        opts="start stop restart"
fi

*** change it to:
opts="start stop restart"
source ${myscript}

*** unless this breaks current scripts, in which case this would be better:
source ${myscript}

for defo in start stop restart ; do
    for o in ${opt} ; do
        if [ "${o}" == "${defo}" ] ; then
            defo=
            break
        fi
    done
    [ -n "${defo}" ] && opt="${defo} ${opt}"
done
Comment 8 Pieter Boeren 2002-08-05 13:53:25 UTC
First solution works for me, but the second one not. It gives the same result  
as without your "patch":  
  
pieter root # ./foo f  
 * ERROR:  wrong args. (  f / f )  
  
 * Usage: foo {foo|foo}  
 *        foo without arguments for full help  
  
but as you are not sure if the first solution is 100% correct, I'll wait for 
Martin to say something about this ;) 
Comment 9 Martin Schlemmer (RETIRED) gentoo-dev 2002-08-05 14:01:26 UTC
Whoops .. long day ? :P

change:

    myline="Usage: ${myservice} {$*"

to:

    myline="Usage: ${myservice} {${opts}"

---------------------------------snip------------------------------
nosferatu tmp # /etc/init.d/acpid lksjd
 * ERROR:  wrong args. (  lksjd / lksjd )

 * Usage: acpid {start stop restart}
 *        acpid without arguments for full help
nosferatu tmp # 
---------------------------------snip------------------------------


Comment 10 SpanKY gentoo-dev 2002-08-05 14:08:31 UTC
that didnt work for me martin, same results as original report

as for my comment about breaking scripts, it would 'break' a script if the user 
had defined opts in their script as 'opts="start stop restart food"'

as for the second one, it should be 'opts' and not 'opt' :x
Comment 11 Martin Schlemmer (RETIRED) gentoo-dev 2002-08-05 14:23:55 UTC
Created attachment 2840 [details]
/sbin/runscript.sh

This should be the fixed one.
Comment 12 Martin Schlemmer (RETIRED) gentoo-dev 2002-08-05 14:24:37 UTC
ok, have to be $* and not $opts, else the ' ' do not get converted to '|'.
Comment 13 SpanKY gentoo-dev 2002-08-05 14:31:31 UTC
works great, nice fix :)
Comment 14 Pieter Boeren 2002-08-05 14:33:30 UTC
Thanks! Now its working like it should be (I guess ;)). 
Comment 15 Martin Schlemmer (RETIRED) gentoo-dev 2002-08-06 15:42:29 UTC
Commited to CVS, should make next baselayout.