Finding $pidfile from a conf file (Was: Re: conf/153460: devd(8) cannot be restarted correctly via /etc/rc.d script)

Doug Barton dougb at FreeBSD.org
Mon Apr 18 23:08:07 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 12/29/2010 03:44, Garrett Cooper wrote:
| Yeah, and while I do agree there are some issues with the change.
|
| For starters, devd.conf does also have a pid-file directive so the
| .conf file and the rc script can get out of sync:

So it's taken me some time to get back to this, but I think I've got
something. The reason that I didn't want to just hack in a quick fix to
this particular issue is that I wanted to come up with a more generic
solution. We have a non-trivial number of ports that have rolled their
own versions of this, so that sounds like it's time for something to be
added to rc.subr to me. :)

In the (hopefully) attached script is an implementation of
get_pidfile_from_conf() that I think works pretty well, along with an
example of utilization. I've tested this with the various conf files I
could find from base and ports that specify the pid file and so far so
good.

The implementation example is written the way it is so that it can be
used in ports' scripts immediately, even if the feature isn't in the
system's rc.subr.

Comments are welcome, especially welcome would be testing with your
local conf files. I plan to commit this on Friday if no one has a better
idea.


Doug

- -- 

	Nothin' ever doesn't change, but nothin' changes much.
			-- OK Go

	Breadth of IT experience, and depth of knowledge in the DNS.
	Yours for the right price.  :)  http://SupersetSolutions.com/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (FreeBSD)

iQEcBAEBCAAGBQJNrMRVAAoJEFzGhvEaGryE9ksH/0xPj5VX4LgZG3vU4LAwdg1t
aCqOFdehpWvdwzsLqhBhJOWeYu8kD+Of9j3/HAW1JU9mBzoDwxYV5Z5xV0psx2mx
qUPDh4im6xqXkH4gC7GR84N3j9peaP0gZBq3Z63rB6ujfqaj62WS+X44o/weRTxy
SxnPH780lBV9aQ62SoM/U0oL6RXsuUQhyof+LCeZRGZ2wLh3fk5E9IcztgB9z5r8
zYx9pM2broWTvjZIwoqCBgwJDqi8yp57cXM491RGfXhIuTTNzEB88kAedO15leeg
VvP8Q/6j2CglU+hbJDoi7LBb3XMep4cJtGmJrr2nzya2lB1bqbUJWdAfwOjnAqI=
=Y+Y3
-----END PGP SIGNATURE-----
-------------- next part --------------
#!/bin/sh

# get_pidfile_from_conf string file
#
#	Takes a string to search for in the specified file.
#	Ignores lines with traditional comment characters.
#
# Example:
# if ! pidfile=`get_pidfile_from_conf "string" "file" 2>/dev/null`; then
#	pidfile='/path/to/default'
#fi
#
get_pidfile_from_conf()
{
	local string file line

	string="$1" ; file="$2"

	if [ -z "$string" -o -z "$file" ] || [ ! -s "$file" ]; then
		err 3 'USAGE: get_pidfile_from_conf string file'
	fi

	while read line; do
		case "$line" in
		*[#\;]*${string}*)	continue ;;
		*${string}*)		break ;;
		esac
	done < $file

	if [ -n "$line" ]; then
		line=${line#*/}
		line="/${line%%[\"\;]*}"
		echo $line
	else
		return 1
	fi
}

if ! pidfile=`get_pidfile_from_conf "$1" "$2" 2>/dev/null`; then
	pidfile='some default'
fi

echo "pidfile: $pidfile"

exit $?


More information about the freebsd-rc mailing list