From owner-freebsd-bugs@FreeBSD.ORG Wed Nov 15 13:10:51 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8116B16A494 for ; Wed, 15 Nov 2006 13:10:51 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8D2FD43DB0 for ; Wed, 15 Nov 2006 13:10:02 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id kAFDA1tE095796 for ; Wed, 15 Nov 2006 13:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id kAFDA1wC095795; Wed, 15 Nov 2006 13:10:01 GMT (envelope-from gnats) Resent-Date: Wed, 15 Nov 2006 13:10:01 GMT Resent-Message-Id: <200611151310.kAFDA1wC095795@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pietro Cerutti Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9481F16A412 for ; Wed, 15 Nov 2006 13:09:02 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB40743D98 for ; Wed, 15 Nov 2006 13:08:46 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id kAFD8k8H092028 for ; Wed, 15 Nov 2006 13:08:46 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id kAFD8k0w092027; Wed, 15 Nov 2006 13:08:46 GMT (envelope-from nobody) Message-Id: <200611151308.kAFD8k0w092027@www.freebsd.org> Date: Wed, 15 Nov 2006 13:08:46 GMT From: Pietro Cerutti To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: conf/105568: Add more flexibility to rc.conf, to choose "_enable" values at startup X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Nov 2006 13:10:51 -0000 >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: