Date: Mon, 1 Oct 2007 20:40:12 GMT From: Pietro Cerutti <gahr@gahr.ch> To: freebsd-rc@FreeBSD.org Subject: Re: conf/105568: [patch] Add more flexibility to rc.conf, to choose "_enable" values at startup Message-ID: <200710012040.l91KeC2t097859@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR conf/105568; it has been noted by GNATS. From: Pietro Cerutti <gahr@gahr.ch> To: bug-followup@FreeBSD.org, pietro.cerutti@gmail.com Cc: Subject: Re: conf/105568: [patch] Add more flexibility to rc.conf, to choose "_enable" values at startup Date: Mon, 01 Oct 2007 13:42:43 +0200 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig71BA73101BF0FB5456761C13 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable This patch applies against 6.2-STABLE --- rc.subr.orig 2007-10-01 13:21:35.000000000 +0200 +++ rc.subr 2007-10-01 13:37:10.000000000 +0200 @@ -58,6 +58,9 @@ PS=3D"/bin/ps -ww" JID=3D`$PS -p $$ -o jid=3D` +ASK_TIMEOUT=3D"5s" +ASK_DEFAULT=3D"YES" + case ${OSTYPE} in FreeBSD) SYSCTL_W=3D"${SYSCTL}" @@ -123,7 +126,9 @@ # # checkyesno var -# Test $1 variable, and warn if not set to YES or NO. +# Test $1 variable, and warn if not set to YES, NO or ASK. +# If it's "ask", prompt the user to decide wheter to set +# $1 to YES or NO. # Return 0 if it's "yes" (et al), nonzero otherwise. # checkyesno() @@ -141,6 +146,63 @@ [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1 ;; + [Aa][Ss][Kk]) + # "ask" + + # Answer is stored in .ask file + # -> we are shutting down + _file=3D"/var/run/$name.ask" + if [ -f $_file ]; then + read _response < $_file + if checkyesno _response; then + return 0 + else + return 1 + fi + fi + + # Prompt and save answer in .ask file + # -> we are entering multi-user mode + + # Read timeout and default answer fo this daemon + eval _timeout=3D\$${name}_ask_timeout + eval _default=3D\=C3=A0=C3=A0{name}_ask_default + + # Timeout not set for this daemon + # -> revert to global default timeout + if [ ! $_timeout ]; then + _timeout=3D$ASK_TIMEOUT + fi + + # Default answer not set for this daemon + # -> revert to global default answer + if [ ! $_default ]; then + _default=3D$ASK_DEFAULT + fi + + # Read decision from stdin + read -t $_timeout -p "RC_ASK - Enable $name? [yes|no]" _enable + + # If timeout is elapsed, set default answer + if [ $? -eq 1 ]; then + _enable=3D${_response} + fi + + # Call checkyes no on answer + if checkyesno _enable; then + _choice=3D"yes" + _return=3D0 + else + _choice=3D"no" + _return=3D1 + fi + + # Save decision to .ask file + echo "$_choice" > $_file + + return $_return + ;; + *) warn "\$${1} is not set properly - see ${rcvar_manpage}." return 1 --=20 Pietro Cerutti PGP Public Key: http://gahr.ch/pgp --------------enig71BA73101BF0FB5456761C13 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFHAN04wMJqmJVx944RCmhSAKCS8s4ExqdfiLgNfMxsVOzsnPn7kACdEXzg 1VPh3f5DkPtn+jbXqZWXFzA= =+Gcs -----END PGP SIGNATURE----- --------------enig71BA73101BF0FB5456761C13--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710012040.l91KeC2t097859>