Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 107724 - Bad pid-file parsing prevents bind init script from starting
Summary: Bad pid-file parsing prevents bind init script from starting
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Konstantin Arkhipov (RETIRED)
URL:
Whiteboard:
Keywords: Inclusion
: 110847 111120 117196 117478 (view as bug list)
Depends on:
Blocks: 102135
  Show dependency tree
 
Reported: 2005-09-30 10:47 UTC by kfm
Modified: 2006-01-02 12:51 UTC (History)
9 users (show)

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


Attachments
#gentoo-server_bind-issue.log (#gentoo-server_bind-issue.log,936 bytes, text/plain)
2005-09-30 10:50 UTC, kfm
Details
#gentoo-server-bind-issue.log (#gentoo-server_bind-issue.log,1.04 KB, text/plain)
2005-09-30 10:52 UTC, kfm
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kfm 2005-09-30 10:47:46 UTC
Hi. In response to a complaing in the #gentoo-server channel, I've discovered
that the method used to ascertain the value of the "pid-file" setting in
named.conf fails under certain circumstances. In this particular case, the line
was as follows (preceded by a tab):

  pid-file "/var/run/named/named.pid"; // location of pid file

This resulted in start-stop-daemon being executed a follows:

  start-stop-daemon --start --quiet --pidfile /var/run/named/named.pid //
location of pid file --exec /usr/sbin/named -- -u named -n 1

The method used to determine the correct value is difficult to comprehend and
very hacky IMHO. Might I propose the following instead:

  PIDFILE=$(grep -Eo -m1 "^[^#\"]*pid\-file +\".+\" *;"
${CHROOT}/etc/bind/named.conf | cut -d\" -f2)

This solves the problem as well as being cleaner and easier to understand.
Perhaps the init.d scripts could benefit from improved validation/sanity checks
also? Please view the excerpt from the IRC conversation I had for more
information which I will attach to this bug. Thanks.
Comment 1 kfm 2005-09-30 10:50:14 UTC
Created attachment 69577 [details]
#gentoo-server_bind-issue.log

An excerpt from the conversation I had with the person who experienced the
problem. Some additional points are raised which may be worth considering
within the context of this bug.
Comment 2 kfm 2005-09-30 10:52:55 UTC
Created attachment 69578 [details]
#gentoo-server-bind-issue.log

Oops, 2 lines were missing in the previous attachment.
Comment 3 Konstantin Arkhipov (RETIRED) gentoo-dev 2005-09-30 11:48:01 UTC
fixed in 9.3.1-r5 and 9.2.5-r7

thanks, Kerin
Comment 4 kfm 2005-09-30 12:17:16 UTC
Sorry Konstantin, this is a harder problem at first than it appears and the
method I suggested wasn't quite yet up to scratch. The main issue is that it
penalises lines that have the # and " chars used in what could be a potentially
legitimate context. For example, consider a line as thus:

  someoption="#foo#"; pid-file="bar"; // Comment

Also it appeared to be flaky when no indentation was used. Now I've just tested
an alternative with various permutations and I'm quite sure that I've nailed it
this time! I tried hard to get it all into one grep expression but in this case
I think that splitting it into two makes more sense (where the first pass deals
with commented lines):

  egrep -v "^([[:cntrl:] ]+#|#)" /etc/bind/named.conf \
    | egrep -o -m1 "pid\-file +\".+\" *;" \
    | cut -d\" -f2
  
The [[:cntrl:]] class is used to workaround the fact that we can't use \t to
match tabs and is quite acceptable in this case I think. So first we filter out
lines that begin with a hash, allowing for any amount of preceding whitespace.
Then we just grab a `pid-file "foo";` type statement from the first matching
line but this time without caring whereabouts in the line it occurs (seeing as
commented lines have already been filtered out). It does allow for valid
whitespace within that statement though. Please confirm as working and apply :)
Comment 5 kfm 2005-09-30 12:22:16 UTC
Obviously, I forgot to prepend ${CHROOT} to the file path as well in my previous
comment ;)
Comment 6 kfm 2005-09-30 12:38:12 UTC
/me sighs and remembers that named.conf supports no less than 3 comment styles
(/* */, //, #). Fixed:

egrep -v "^([[:cntrl:] ]+(#|//|/\*)|(#|//|/\*))" ${CHROOT}/etc/bind/named.conf
    | egrep -o -m1 "pid\-file +\".+\" *;" \
    | cut -d\" -f2

It won't deal with lines in the following format:

  foo="bar"; // pid-file="baz";

To address that would take some serious voodoo and I don't think it's worth it.
So the above is my final proposition.
Comment 7 Konstantin Arkhipov (RETIRED) gentoo-dev 2005-09-30 15:33:19 UTC
uhh, yet another bump.. :-)

fixed in 9.3.1-r6 and 9.2.5-r8

thanks again, Kerin
Comment 8 Roman Pertl 2005-10-03 15:43:26 UTC
I've installed net-dns/bind-9.3.1-r6 (using chroot) and i have problemes when 
stopping/reloading. I have changed /etc/init.d/named to get it work:

line 48:
start-stop-daemon --stop --quiet --pidfile ${CHROOT:+$CHROOT/}$PIDFILE \

line 55:
if [ ! -f ${CHROOT:+$CHROOT/}$PIDFILE ]
Comment 9 Konstantin Arkhipov (RETIRED) gentoo-dev 2005-10-03 15:48:24 UTC
is it reproducible after first stop and/or restart?
Comment 10 Roman Pertl 2005-10-04 09:14:00 UTC
Yes, it is reproducable. On another server I use net-dns/bind-9.2.5-r6 and 
chroot works perfectly. The init.d-file of this version contains line 32:

PIDFILE="${CHROOT}$PIDFILE"

It is missing in the version of bind-9.3.1-r6. Adding this line this init-file 
fix the problem for me.
Comment 11 Arnaud Launay 2005-10-30 11:38:12 UTC
Bug #110847 is about that. But there is also another problem: if pid-file is not
specified in named.conf (or if it's specified in another file, like an included
one...), the init script doesn't work.
Comment 12 Andreas Aronsson 2005-11-01 01:41:57 UTC
9.2.5-r6

fixed it this way:

<snip>

stop() {
        ebegin "Stopping ${CHROOT:+chrooted }named"
        checkconfig || return 2
        start-stop-daemon --stop --quiet --pidfile ${CHROOT}$PIDFILE \         
                                                                               
                                            
                --exec /usr/sbin/named -- stop
        eend $?
}

</snip>
Comment 13 Jakub Moc (RETIRED) gentoo-dev 2005-11-01 04:45:21 UTC
*** Bug 110847 has been marked as a duplicate of this bug. ***
Comment 14 Jakub Moc (RETIRED) gentoo-dev 2005-11-01 04:50:07 UTC
*** Bug 111120 has been marked as a duplicate of this bug. ***
Comment 15 Jakub Moc (RETIRED) gentoo-dev 2005-11-01 04:50:59 UTC
Reopening, there are another two bugs on broken init script, still does not work
correctly.
Comment 16 Steponas Kazakevicius 2005-11-02 07:33:42 UTC
I can confirm this...
With bind-9.3.1-r6 the /etc/init.d/named does not contain the fix as stated in
"Additional Comment #12 From  Andreas Aronsson", so it didnt work for me (the
stop() function). After adding the {$CHROOT} before $PIDFILE it is working as it
should.
Comment 17 Chuck 2005-11-02 07:58:23 UTC
I guess I just don't understand what kind of voodoo you guys are trying to do 
here. Why so complicated? this init script has served me perfectly from 
previous versions, and I simply save it and reinstall it every bind update and 
I never ever have a problem. And it is simplicity in itself. Why change it? 
Unless there are issues I am not aware of, I live by 'if it ain't broke don't 
fix it'. 
 
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.rc,v 1.1 2005/08/03 
16:54:38 voxus Exp $ 
 
 
Comment 18 Jakub Moc (RETIRED) gentoo-dev 2005-11-02 08:21:44 UTC
(In reply to comment #17)
> I guess I just don't understand what kind of voodoo you guys are trying to do 
> here. Why so complicated? 

I guess we'd like to install a *working* init script, that's all. So no voodoo. ;p

Comment 19 Chuck 2005-11-02 08:49:02 UTC
Then why not just go back to a previous version of the script that worked fine? 
Like I said I don't know the reasons why attempted changes from a seemingly 
working script were started, but.. if it was just to 'improve it' then I vote 
for going backward:) if there was a problem that only showed under certain 
circumstances then.... im all wet :) I only know the version of the init i have 
been using has worked perfectly for me. 
Comment 20 Jan Oravec 2005-11-03 03:47:06 UTC
What about allowing /etc/conf.d/named to specify PIDFILE?

If the $PIDFILE is not set there, try some heuristics (e.g. various proposed
greps here). If these fails (i.e. the output is not correct), use
"/var/run/named/named.pid" as default.

Or maybe just drop the heuristics completely and use /etc/conf.d/named + default
value?
Comment 21 Chuck 2005-11-03 04:07:08 UTC
(In reply to comment #20) 
 
>  
> Or maybe just drop the heuristics completely and use /etc/conf.d/named + 
default 
> value? 
 
This has been the traditional way since forever. Below is a working init script 
from the past that has served me very well with never an error of any kind 
whether I specify a pid in named.conf or don't. Mostly everyone I have ever 
dealt with in any kind of support or tech capacity do not specify a pid in 
named.conf but use the default and in the past 3 years I have never run across 
anyone attempting to define it differently. 
 
 
#!/sbin/runscript 
# Copyright 1999-2004 Gentoo Foundation 
# Distributed under the terms of the GNU General Public License v2 
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.rc,v 1.1 2005/08/03 
16:54:38 voxus Exp $ 
 
opts="start stop reload restart" 
 
depend() { 
        need net 
        use logger 
        provide dns 
} 
 
checkconfig() { 
        if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then 
                eerror "No ${CHROOT}/etc/bind/named.conf file exists!" 
        fi 
 
        # In case someone doesn't have $CPU set from /etc/conf.d/named 
        if [ ! ${CPU} ] ; then 
                CPU="1" 
        fi 
 
        # As with the named.conf test, above, there's no need 
        # for chroot and non-chroot cases here 
        PIDFILE=$(grep "pid-file" ${CHROOT}/etc/bind/named.conf | \ 
                egrep -v ".*[#,//].*pid-file" | \ 
                head -n 1 | \ 
                sed -ne 's:.*pid-file\(.*\)\"\(.*\)\";:\2:p') 
        [ -n "$PIDFILE" ] || PIDFILE=/var/run/named.pid 
 
        PIDFILE="${CHROOT}$PIDFILE" 
 
        KEY="${CHROOT}/etc/bind/rndc.key" 
} 
 
start() { 
        ebegin "Starting ${CHROOT:+chrooted }named" 
        checkconfig || return 1 
        start-stop-daemon --start --quiet --pidfile ${PIDFILE} \ 
                --exec /usr/sbin/named \ 
                -- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT} 
        eend $? 
} 
 
stop() { 
        ebegin "Stopping ${CHROOT:+chrooted }named" 
        checkconfig || return 2 
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \ 
                --exec /usr/sbin/named -- stop 
        eend $? 
} 
 
reload() { 
        checkconfig || return 3 
        if [ ! -f $PIDFILE ] ; then 
                /etc/init.d/named start &>/dev/null 
                exit 
        fi 
 
        if [ -f $KEY ] ; then 
                ebegin "Reloading named.conf and zone files" 
                rndc -k $KEY reload &>/dev/null 
                eend $? 
        else /etc/init.d/named restart &>/dev/null 
        fi 
} 
 
# restart() is taken care of by runscript. 
 
I used to use one from early 2004/late 2003 but lost it in a drive death so 
this is the earliest one I have that works well. 
Comment 22 Konstantin Arkhipov (RETIRED) gentoo-dev 2005-11-09 01:25:21 UTC
fixed (by introducing PIDFILE in /etc/conf.d/named) in 9.2.5-r9, 9.3.1-r7, 9.3.
2_beta2
Comment 23 Jakub Moc (RETIRED) gentoo-dev 2005-12-30 07:13:13 UTC
*** Bug 117196 has been marked as a duplicate of this bug. ***
Comment 24 Jakub Moc (RETIRED) gentoo-dev 2006-01-02 12:51:06 UTC
*** Bug 117478 has been marked as a duplicate of this bug. ***