Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 2006 20:27:25 +0100
From:      "Pietro Cerutti" <pietro.cerutti@gmail.com>
To:        Ingo <ingom-list@freenet.de>,  "FreeBSD Questions" <freebsd-questions@freebsd.org>,  freebsd-stable@freebsd.org
Subject:   Re: rc.subr modification: testing and feedback are welcome! [here's the patch]
Message-ID:  <e572718c0611151127n4d3f4274p54ef136424e7bbc3@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Ouch... here's the patch ;-)

On 11/15/06, Pietro Cerutti <pietro.cerutti@gmail.com> wrote:
> On 11/15/06, Ingo <ingom-list@freenet.de> wrote:
> >
> > Hello,
>
> Hello,
>
> > There should be an tiemout so that the system boots even if I forget to
> > choose
>
> Yup, great idea. The new patch [attached] permits you to set:
>
> DAEMON_ask_timeout={0-9}[s|m|h]
> and
> DAEMON_ask_default=[yes|no]
>
> in rc.conf
>
> Default values have been put in rc.subr ("5s" and "yes")
>
> >
> > It should also be possible to use the short form [y/n] while booting in
> > addition to yes/no to start the deamon,
>
> This could be done, but at the moment I rely on the checkyesno
> subroutine in rc.subr, which only accepts [yes, true, on, 1] and [no,
> false, off, 0] in any combination of upper and lower case.
>
>
> >
> > greetings
> >
>
> Thanks for input, regards
>
>
> --
> Pietro Cerutti
> ICQ: 117293691
> PGP: 0x9571F78E
>
> - ASCII Ribbon Campaign -
>  against HTML e-mail and
>  proprietary attachments
>    www.asciiribbon.org
>


-- 
Pietro Cerutti
ICQ: 117293691
PGP: 0x9571F78E

- ASCII Ribbon Campaign -
 against HTML e-mail and
 proprietary attachments
   www.asciiribbon.org

[-- Attachment #2 --]
--- /etc/rc.subr.orig	Wed Nov 15 14:03:59 2006
+++ /etc/rc.subr	Wed Nov 15 20:10:32 2006
@@ -56,6 +56,8 @@
 ID="/usr/bin/id"
 JID=`ps -p $$ -o jid=`
 IDCMD="if [ -x $ID ]; then $ID -un; fi"
+ASK_TIMEOUT="5s"
+ASK_DEFAULT="YES"
 
 case ${OSTYPE} in
 FreeBSD)
@@ -122,7 +124,8 @@
 
 #
 # 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", let the user choose at runtime between "yes" and "no".
 #	Return 0 if it's "yes" (et al), nonzero otherwise.
 #
 checkyesno()
@@ -140,7 +143,52 @@
 	[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
 		return 1
 		;;
-	*)
+
+      # "ask"
+	[Aa][Ss][Kk])
+      
+      # answer already stored in .ask file,
+      # this should be the case on shutdown
+      _file="/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 choice to file,
+      # this should be the case on startup
+
+      # Read timeout and default answer for daemon
+      eval _timeout=\$${name}_ask_timeout
+      eval _response=\$${name}_ask_default
+
+      if [ ! $_timeout ]; then
+         _timeout=$ASK_TIMEOUT
+      fi
+
+      if [ ! $_response ]; then
+         _response=$ASK_DEFAULT
+      fi
+
+      read -t $_timeout -p "RC_ASK - Enable $name? [yes|no] " _enable
+      if [ $? -eq 1 ]; then
+         _enable=${_response}
+      fi
+      if checkyesno _enable; then
+         _choice="yes"
+         _return=0
+      else
+         _choice="no"
+         _return=1
+      fi
+      echo "$_choice" > $_file
+      return  $_return;
+      ;;
+
+   *)
 		warn "\$${1} is not set properly - see ${rcvar_manpage}."
 		return 1
 		;;

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e572718c0611151127n4d3f4274p54ef136424e7bbc3>