Date: Mon, 18 Apr 2011 16:08:05 -0700 From: Doug Barton <dougb@FreeBSD.org> To: Garrett Cooper <yanegomi@gmail.com> Cc: "freebsd-rc@FreeBSD.org" <freebsd-rc@freebsd.org>, "ggg_mail@inbox.ru" <ggg_mail@inbox.ru> Subject: Finding $pidfile from a conf file (Was: Re: conf/153460: devd(8) cannot be restarted correctly via /etc/rc.d script) Message-ID: <4DACC455.4040603@FreeBSD.org> In-Reply-To: <AANLkTinRSC_pBVdK_m8Hrk=_32mjMZDSc77__5iUyV_Z@mail.gmail.com> References: <201012272253.oBRMrH7k025331@freefall.freebsd.org> <1232C1B4-DA64-4332-906E-288B8C1E39FE@gmail.com> <4D1A3DFE.8090009@FreeBSD.org> <AANLkTinRSC_pBVdK_m8Hrk=_32mjMZDSc77__5iUyV_Z@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------080904040004030305020202 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit -----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----- --------------080904040004030305020202 Content-Type: text/plain; name="testpid" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="testpid" #!/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 $? --------------080904040004030305020202--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DACC455.4040603>