NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-i386/43563: boot.cfg doesn't support comments



>Number:         43563
>Category:       port-i386
>Synopsis:       boot.cfg doesn't support comments
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 03 12:45:00 +0000 2010
>Originator:     Wolfgang Solfrank
>Release:        NetBSD 5.99.33
>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@localhost:/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;



Home | Main Index | Thread Index | Old Index