Subject: misc/35366: /etc/rc.subr _find_processes doesn't always find existing process when it is interpreted program.
To: None <misc-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Dominik Joe Pantucek <joe@joe.cz>
List: netbsd-bugs
Date: 01/06/2007 11:50:00
>Number:         35366
>Category:       misc
>Synopsis:       /etc/rc.subr _find_processes doesn't always find existing process when it is interpreted program.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 06 11:50:00 +0000 2007
>Originator:     Dominik Joe Pantucek <joe@joe.cz>
>Release:        NetBSD 3.0.1
>Organization:
	
>Environment:
System: NetBSD Osgiliath 3.0.1 NetBSD 3.0.1 (OSGILIATH) #2: Wed Oct 11 15:47:51 CEST 2006 root@Osgiliath:/usr/obj/sys/arch/i386/compile/OSGILIATH i386
Architecture: i386
Machine: i386
>Description:
	Found when using "/etc/rc.d/amavisd status" command with the default rc.d script from amavisd pkgsrc distribution. It always shows amavisd as not running. The reason for this is bad match in _find_processes function in /etc/rc.subr. The 1.65 version (netbsd-3.0.1) doesn't handle such situations at all and 1.67 (-current) handles them in slightly insufficient way.
	The problem is exposed, when programs alter their argv[] from full paths to just basenames - like /usr/bin/perl -> perl, /usr/pkg/sbin/amavisd -> amavisd.
	1.65 - doesn't handle this at all
	1.67 - handles interpreter name change, not the script name change (it can handle "perl /usr/pkg/sbin/amavisd" not "perl: amavis")
>How-To-Repeat:
	Install amavisd or other package from pkgsrc which has rc.d script that uses rc.subr and its daemon is interpreted script modifying argv.
	Copy its rc.d script to /etc/rc.d (or run it from other location like /usr/pkg/etc/rc.d)
	Run /etc/rc.d/amavisd start (or equivalent)
	Run /etc/rc.d/amavisd status (dtto)
	It will tell you the daemon is not running.
>Fix:
	I've created two patches which fix this in a clean way. One for 1.65 and other for 1.67 version of rc.subr.
	http://joe.cz/netbsd/rc.subr-1.65-shortmatch.diff
	http://joe.cz/netbsd/rc.subr-1.67-shortmatch.diff
	The latter removes the insufficient match from 1.67 and replaces it with fully abbreviated match (see source).