From nobody@FreeBSD.org Wed Oct 9 07:59:01 2002 Return-Path: Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7AB2837B401 for ; Wed, 9 Oct 2002 07:59:01 -0700 (PDT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0D2AC43E8A for ; Wed, 9 Oct 2002 07:58:46 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g99Ewk7R077668 for ; Wed, 9 Oct 2002 07:58:46 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.6/8.12.6/Submit) id g99EwkGv077667; Wed, 9 Oct 2002 07:58:46 -0700 (PDT) Message-Id: <200210091458.g99EwkGv077667@www.freebsd.org> Date: Wed, 9 Oct 2002 07:58:46 -0700 (PDT) From: Walter Kenaston To: freebsd-gnats-submit@FreeBSD.org Subject: unterminated string in rc.conf leaves system unuseable / disk readonly X-Send-Pr-Version: www-1.0 >Number: 43865 >Category: bin >Synopsis: unterminated string in rc.conf leaves system unuseable / disk readonly >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 09 08:00:03 PDT 2002 >Closed-Date: Wed Oct 09 10:13:03 PDT 2002 >Last-Modified: Wed Oct 9 14:10:01 PDT 2002 >Originator: Walter Kenaston >Release: 4.6.2 >Organization: >Environment: FreeBSD 4.6.2 release 0; generic i386 compile >Description: An error in hand-editting /etc/rc.conf - a missing quote character, in this case - caused the OS to be in an unuseable state after reboot. (The most this ought to cause is an erorr message and an unprocessed configuration keyword.) >How-To-Repeat: Take out the leading quote on one of the string values in /etc/rc.conf. >Fix: Re-installing the OS, don't ever make a mistake in FreeBSD configuration files, or make FreeBSD handle errors in a fail-safe manner. >Release-Note: >Audit-Trail: State-Changed-From-To: open->closed State-Changed-By: ceri State-Changed-When: Wed Oct 9 10:11:27 PDT 2002 State-Changed-Why: Pilot error. /etc/rc.conf is sourced by /bin/sh, and therefore must be in valid /bin/sh syntax. If you have garbled /etc/rc.conf (or any of the other startup files), this does not mean that you have to reinstall the system - boot into single user and correct the error. http://www.freebsd.org/cgi/query-pr.cgi?pr=43865 From: Giorgos Keramidas To: Walter Kenaston Cc: bug-followup@freebsd.org Subject: Re: bin/43865: unterminated string in rc.conf leaves system unuseable / disk readonly Date: Wed, 9 Oct 2002 18:21:13 +0300 On 2002-10-09 07:58, Walter Kenaston wrote: > An error in hand-editting /etc/rc.conf - a missing quote character, > in this case - caused the OS to be in an unuseable state after > reboot. (The most this ought to cause is an erorr message and an > unprocessed configuration keyword.) Any ideas how this can be done? This isn't a bug report, but a description of something that is already known and documented. In fact, the documentation includes workarounds for the cases when the administrator has caused something like this to happen by being careless enough. From: Giorgos Keramidas To: Ian Dowse Cc: Ceri Davies , walterk1@earthlink.net, bug-followup@freebsd.org Subject: Re: bin/43865: unterminated string in rc.conf leaves system unuseable / disk readonly Date: Wed, 9 Oct 2002 22:36:08 +0300 [-- Please keep bug-followup@freebsd.org in the Cc: list. --] On 2002-10-09 19:10, Ian Dowse wrote: > In message <200210091713.g99HD2Ut063553@freefall.freebsd.org>, > Ceri Davies writes: > >State-Changed-From-To: open->closed > >Pilot error. > > > >/etc/rc.conf is sourced by /bin/sh, and > >therefore must be in valid /bin/sh syntax. > > I actually think that this is a perfectly reasonable bug report. > It is far too easy to miss a quote in rc.conf, yet the file would > rarely contain more than name="value" lines. That's a lot of > foot-shooting potential for very little gain, and is especially > problematic when making configuration changes remotely. One of the ideas I had and never actually got around to implementing was a shell wrapper around $EDITOR that allows root to edit rc.conf and then checks to see that sh(1) can still parse the resulting file. Something along the lines of: # viconf >>> copy /etc/rc.conf to /tmp/rc.conf.orig.$$ and /tmp/rc.conf.$$$ >>> fire up $EDITOR on /tmp/rc.conf.$$$ >>> check to see if the following command works fine: /bin/sh -c '. /tmp/rc.conf.$$' >>> on failure, show a diff -u, and prompt the user for a) abort, e) edit again Does that sound a useful thing to have around? The idea is similar to vipw(8), but it still won't stop anyone from messing around with rc.conf manually. From: Ceri Davies To: Giorgos Keramidas Cc: Ian Dowse , bug-followup@freebsd.org Subject: Re: bin/43865: unterminated string in rc.conf leaves system unuseable / disk readonly Date: Wed, 9 Oct 2002 21:20:18 +0100 On Wed, Oct 09, 2002 at 10:36:08PM +0300, Giorgos Keramidas wrote: > [-- Please keep bug-followup@freebsd.org in the Cc: list. --] > One of the ideas I had and never actually got around to implementing > was a shell wrapper around $EDITOR that allows root to edit rc.conf > and then checks to see that sh(1) can still parse the resulting file. > > Something along the lines of: > > # viconf > >>> copy /etc/rc.conf to /tmp/rc.conf.orig.$$ > and /tmp/rc.conf.$$$ > >>> fire up $EDITOR on /tmp/rc.conf.$$$ > >>> check to see if the following command works fine: > > /bin/sh -c '. /tmp/rc.conf.$$' > > >>> on failure, show a diff -u, and prompt the user for > a) abort, e) edit again Sounds good. lockf is your friend. Ceri -- you can't see when light's so strong you can't see when light is gone From: Giorgos Keramidas To: Ceri Davies Cc: bug-followup@freebsd.org Subject: Re: bin/43865: unterminated string in rc.conf leaves system unuseable / disk readonly Date: Wed, 9 Oct 2002 23:38:12 +0300 On 2002-10-09 21:20, Ceri Davies wrote: > On Wed, Oct 09, 2002 at 10:36:08PM +0300, Giorgos Keramidas wrote: > > One of the ideas I had and never actually got around to implementing > > was a shell wrapper around $EDITOR that allows root to edit rc.conf > > and then checks to see that sh(1) can still parse the resulting file. > > > > Something along the lines of: > > > > # viconf > > >>> copy /etc/rc.conf to /tmp/rc.conf.orig.$$ > > Sounds good. lockf is your friend. Well, I meant to avoid locking since it will future edits if a crash happens during the period that the lock is held. I'll try to write something and follow-up later. From: Ian Dowse To: Giorgos Keramidas Cc: Ceri Davies , walterk1@earthlink.net, bug-followup@freebsd.org Subject: Re: bin/43865: unterminated string in rc.conf leaves system unuseable / disk readonly Date: Wed, 09 Oct 2002 22:00:03 +0100 In message <20021009193608.GF15316@hades.hell.gr>, Giorgos Keramidas writes: >One of the ideas I had and never actually got around to implementing >was a shell wrapper around $EDITOR that allows root to edit rc.conf >and then checks to see that sh(1) can still parse the resulting file. Yes, that sounds like it would help a lot. I was thinking more of a modification to the code that sources rc.conf to instead do something like: file=/etc/rc.conf lineno=0 while read line; do lineno=$(expr ${lineno} + 1) if (eval "${line}" > /dev/null 2>&-); then eval "${line}" else echo "${file}:${lineno}:" `eval "${line}" 2>&1` 1>&2 fi done < "${file}" This causes each line in rc.conf to be treated completely separately, and gives almost-sensible, non-fatal errors for failures. /etc/rc.conf:5: eval: 1: Syntax error: Unterminated quoted string /etc/rc.conf:45: eval: 1: Syntax error: Unterminated quoted string It does end up forking a lot of sub-shells and evaluates each line multiple times though, so could do with some improvement... Ian >Unformatted: