Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 2006 13:08:46 GMT
From:      Pietro Cerutti<pietro.cerutti@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   conf/105568: Add more flexibility to rc.conf, to choose "_enable" values at startup
Message-ID:  <200611151308.kAFD8k0w092027@www.freebsd.org>
Resent-Message-ID: <200611151310.kAFDA1wC095795@freefall.freebsd.org>

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

>Number:         105568
>Category:       conf
>Synopsis:       Add more flexibility to rc.conf, to choose "_enable" values at startup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 15 13:10:01 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Pietro Cerutti
>Release:        6.2-PRERELEASE
>Organization:
>Environment:
FreeBSD gahr-laptop 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #0: Tue Nov 14 22:09:12 CET 2006     root@gahr-laptop:/usr/obj/usr/src/sys/GAHR  i386
>Description:
The rc.conf(5) file is the configuration mechanism of the RC process, which is responsible to bring up the system after init(8).
Among the other functions (i.e. setting the hostname), a list of variable of the form DAEMON_enable=[yes|no] is used to decide whether a particular DAEMON should be started at boot.

This configuration mechanism is rather static, because it requires editing the rc.conf file to change the decision about a daemon. 
To disable a daemon, at the present is required in the best case to boot in single user mode (so that the daemon is not started), change the variable, and exit in multiuser mode without the daemon being started.

The attached patch permits a variable to be set to "ask" [i.e. samba_enable=ask]. At startup, a message of the form "RC_ASK - Enable samba? [yes|no] " will be displayed, and the user will be allowed to choose whether samba will be enabled or not. The decision will be stored in the file /var/run/samba.ask, so that at shutdown the RC mechanism is able to decide whether stopping the service is required or not.

I found it useful specially on laptops, where the networking environment often changes, and the set of needed daemons change from session to session.

This patch affects /etc/rc.subr, enhancing the "checkyesno" routine to accept "ask" values.
>How-To-Repeat:

>Fix:
1) Apply the patch:
     cd /etc
     patch < rc.subr.diff.txt
2) Modify some decisions in rc.conf (i.e. postfix_enable="ask", ...)
3) Shutdown in single user mode, and exit on multiuser mode (no reboot is required)
4) When prompted, decide whether postfix should be started or not

Patch attached with submission follows:

--- rc.subr.orig	Wed Nov 15 14:03:59 2006
+++ rc.subr	Wed Nov 15 13:44:31 2006
@@ -122,7 +122,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 +141,36 @@
 	[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 -p "RC_ASK - Enable $name? [yes|no] " _enable
+      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
 		;;

>Release-Note:
>Audit-Trail:
>Unformatted:



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