NetBSD Problem Report #43563

From wolfgang@Solfrank.net  Sat Jul  3 12:43:53 2010
Return-Path: <wolfgang@Solfrank.net>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id F24EE63BA69
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  3 Jul 2010 12:43:52 +0000 (UTC)
Message-Id: <20100703124347.331078D@pc.Solfrank.net>
Date: Sat,  3 Jul 2010 14:43:47 +0200 (MEST)
From: ws@netbsd.org
Reply-To: ws@netbsd.org
To: gnats-bugs@gnats.NetBSD.org
Subject: boot.cfg doesn't support comments
X-Send-Pr-Version: 3.95

>Number:         43563
>Category:       port-i386
>Synopsis:       boot.cfg doesn't support comments
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-i386-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 03 12:45:00 +0000 2010
>Closed-Date:    Mon Aug 22 01:05:26 +0000 2011
>Last-Modified:  Mon Aug 22 01:05:26 +0000 2011
>Originator:     Wolfgang Solfrank
>Release:        NetBSD 5.99.33
>Organization:

>Environment:
System: NetBSD pc.Solfrank.net 5.99.33 NetBSD 5.99.33 (GENERIC) #0: Wed Jun 30 18:00:57 MEST 2010 ws@ws.solfrank.net:/src/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
While boot.cfg(5) suggests that the file supports comments starting with #,
in fact this isn't implemented.  If you include such lines in the file,
the line is indeed ignored, but the line following it is, too.
>How-To-Repeat:
Try a boot.cfg like the following:

	# This comment leads to the following line to be ignored
	menu=Boot normally:boot
	menu=Boot single-user:boot -s
	menu=Boot from second disk:boot hd1a:
	timeout=-1
	default=1

and watch the menu to contain only two lines.

>Fix:
The following patch fixes the problem for me.  It even allows
comments on any line (stuff after the hash is ignored) and
handles tabs and space alike:

Index: sys/arch/i386/stand/lib/bootmenu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/stand/lib/bootmenu.c,v
retrieving revision 1.8
diff -u -r1.8 bootmenu.c
--- sys/arch/i386/stand/lib/bootmenu.c	14 Sep 2009 10:42:42 -0000	1.8
+++ sys/arch/i386/stand/lib/bootmenu.c	3 Jul 2010 12:14:28 -0000
@@ -101,7 +101,7 @@
 	int cmenu, cbanner, len;
 	int fd, err, off;
 	struct stat st;
-	char *key, *value, *v2;
+	char *next, *key, *value, *v2;

 	/* Clear bootconf structure */
 	memset((void *)&bootconf, 0, sizeof(bootconf));
@@ -157,13 +157,22 @@

 	cmenu = 0;
 	cbanner = 0;
-	for (c = bc; *c; c++) {
+	for (c = bc; *c; c = next) {
 		key = c;
+		/* find end of line */
+		for (; *c && *c != '\n'; c++)
+			/* zero terminate line on start of comment */
+			if (*c == '#')
+				*c = 0;
+		/* zero terminate line */
+		if (*(next = c))
+			*next++ = 0;
 		/* Look for = separator between key and value */
-		for (; *c && *c != '='; c++)
+		for (c = key; *c && *c != '='; c++)
 			continue;
+		/* Ignore lines with no key=value pair */
 		if (*c == '\0')
-			break; /* break if at end of data */
+			continue;

 		/* zero terminate key which points to keyword */
 		*c++ = 0;
Index: sys/arch/i386/stand/lib/parseutils.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/stand/lib/parseutils.c,v
retrieving revision 1.5
diff -u -r1.5 parseutils.c
--- sys/arch/i386/stand/lib/parseutils.c	14 Dec 2008 17:03:43 -0000	1.5
+++ sys/arch/i386/stand/lib/parseutils.c	3 Jul 2010 12:14:28 -0000
@@ -52,13 +52,22 @@
 {
 	char *options;

-	if ((options = strchr(arg, ' ')) == NULL)
+	for (options = arg; *options; options++) {
+		switch (*options) {
+		case ' ':
+		case '\t':
+			*options++ = '\0';
+			break;
+		default:
+			continue;
+		}
+		break;
+	}
+	if (*options == '\0')
 		return "";
-	else
-		*options++ = '\0';

-	/* trim leading blanks */
-	while (*options && *options == ' ')
+	/* trim leading blanks/tabs */
+	while (*options == ' ' || *options == '\t')
 		options++;

 	return options;

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/43563 CVS commit: src/sys/arch/i386/stand/lib
Date: Thu, 18 Aug 2011 09:20:04 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Thu Aug 18 13:20:04 UTC 2011

 Modified Files:
 	src/sys/arch/i386/stand/lib: bootmenu.c parseutils.c

 Log Message:
 PR/43563: Wolfgang Solfrank: boot.cfg doesn't support comments
 Fix makes it support # comments and treat spaces and tabs the same way.


 To generate a diff of this commit:
 cvs rdiff -u -r1.9 -r1.10 src/sys/arch/i386/stand/lib/bootmenu.c
 cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/stand/lib/parseutils.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 22 Aug 2011 01:05:26 +0000
State-Changed-Why:
Christos committed it (Christos never closes PRs...)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.