NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

misc/47251: rc.d script using _chdir silently crashes



>Number:         47251
>Category:       misc
>Synopsis:       rc.d script using _chdir silently crashes
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 26 22:10:00 +0000 2012
>Originator:     Guillaume
>Release:        6.0
>Organization:
>Environment:
NetBSD andy 6.0 NetBSD 6.0 (GENERIC) i386
>Description:
I could not get a home-written /etc/rc.d/name script to work for an application 
that uses ${name}_chdir shell variable.

I couldn't even see the string 'Starting ${name}' when playing the script.

It seemed that the -x file test returned 0 in my case.
>How-To-Repeat:
1. create a little "service" :

echo '#!/bin/sh\n\n#Dummy server, waiting on port 8080\nnc -l -p 8080 2>&1 >> 
/tmp/test &\n' >> /root/test_br

2. create a (really minimalist) initscript

#!/bin/sh

. /etc/rc.subr

name="test_br"
rcvar=${name}
test_br_chdir=/root/

command="./test_br"

load_rc_config $name
run_rc_command "$1"

3. cd to a directory different than /root

cd /tmp

4. launch initscript

/etc/rc.d/test_br onestart

=> silently KO
>Fix:
Modifying the -x execfile test was enough ; the following diff illustrates a 
solution :

--- rc.subr.orig        2012-11-26 22:09:41.000000000 +0100
+++ rc.subr     2012-11-26 22:42:01.000000000 +0100
@@ -603,7 +603,7 @@
                                exit 1
                        fi
 
-                       if [ ! -x ${_chroot}${command} ]; then
+                       if [ ! -x ${_chroot}${command} -a ! -x 
${_chdir}${command} ]; then
                                return 0
                        fi
 
(I'm everything but a shell expert, please don't blame ^^)

after applying this diff, you can test :

3bis. cd to a directory different than /root

cd /tmp

4bis. launch initscript

/etc/rc.d/test_br onestart

=> Starting test_br.

5. connect to the server and talk to it. Great.



Home | Main Index | Thread Index | Old Index