Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Jan 2019 02:17:19 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r342809 - stable/11/usr.sbin/config
Message-ID:  <201901060217.x062HJ0d082249@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Sun Jan  6 02:17:18 2019
New Revision: 342809
URL: https://svnweb.freebsd.org/changeset/base/342809

Log:
  MFC r342362-r342363: config(8) duplicate option handling
  
  r342362:
  config(8): Allow duplicate options to be specified
  
  config(8)'s option handling has been written to allow duplicate options; if
  the value changes, then the latest value is used and an informative message
  is printed to stderr like so:
  
  /usr/src/sys/amd64/conf/TEST: option "VERBOSE_SYSINIT" redefined from 0 to 1
  
  Currently, this is only a possibility for cpu types, MAXUSERS, and
  MACHINE_ARCH. Anything else duplicated in a config file will use the first
  value set and error about duplicated options on subsequent appearances,
  which is arguably unfriendly since one could specify:
  
  include GENERIC
  nooptions VERBOSE_SYSINIT
  options VERBOSE_SYSINIT
  
  to redefine the value later anyways.
  
  Reported by:	mmacy
  
  r342363:
  config(8): Remove all instances of an option when opting out
  
  Quick follow-up to r342362: options can appear multiple times now, so
  clean up all of them as needed. For non-OPTIONS options, this has no effect
  since they're already de-duplicated.

Modified:
  stable/11/usr.sbin/config/config.y
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/config/config.y
==============================================================================
--- stable/11/usr.sbin/config/config.y	Sun Jan  6 02:15:09 2019	(r342808)
+++ stable/11/usr.sbin/config/config.y	Sun Jan  6 02:17:18 2019	(r342809)
@@ -97,7 +97,7 @@ static void newdev(char *name);
 static void newfile(char *name);
 static void newenvvar(char *name, bool is_file);
 static void rmdev_schedule(struct device_head *dh, char *name);
-static void newopt(struct opt_head *list, char *name, char *value, int append);
+static void newopt(struct opt_head *list, char *name, char *value, int append, int dupe);
 static void rmopt_schedule(struct opt_head *list, char *name);
 
 static char *
@@ -210,7 +210,7 @@ System_spec:
 	  ;
 
 System_id:
-	Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0); };
+	Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0, 0); };
 
 System_parameter_list:
 	  System_parameter_list ID
@@ -230,13 +230,13 @@ NoOpt_list:
 		;
 Option:
 	Save_id {
-		newopt(&opt, $1, NULL, 0);
+		newopt(&opt, $1, NULL, 0, 1);
 		if (strchr($1, '=') != NULL)
 			errx(1, "%s:%d: The `=' in options should not be "
 			    "quoted", yyfile, yyline);
 	      } |
 	Save_id EQUALS Opt_value {
-		newopt(&opt, $1, $3, 0);
+		newopt(&opt, $1, $3, 0, 1);
 	      } ;
 
 NoOption:
@@ -264,10 +264,10 @@ Mkopt_list:
 		;
 
 Mkoption:
-	Save_id { newopt(&mkopt, $1, ns(""), 0); } |
-	Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0); } |
-	Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0); } |
-	Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1); } ;
+	Save_id { newopt(&mkopt, $1, ns(""), 0, 0); } |
+	Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0, 0); } |
+	Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0, 0); } |
+	Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1, 0); } ;
 
 Dev:
 	ID { $$ = $1; }
@@ -293,7 +293,7 @@ NoDev_list:
 
 Device:
 	Dev {
-		newopt(&opt, devopt($1), ns("1"), 0);
+		newopt(&opt, devopt($1), ns("1"), 0, 0);
 		/* and the device part */
 		newdev($1);
 		}
@@ -430,7 +430,7 @@ findopt(struct opt_head *list, char *name)
  * Add an option to the list of options.
  */
 static void
-newopt(struct opt_head *list, char *name, char *value, int append)
+newopt(struct opt_head *list, char *name, char *value, int append, int dupe)
 {
 	struct opt *op, *op2;
 
@@ -443,7 +443,7 @@ newopt(struct opt_head *list, char *name, char *value,
 	}
 
 	op2 = findopt(list, name);
-	if (op2 != NULL && !append) {
+	if (op2 != NULL && !append && !dupe) {
 		fprintf(stderr,
 		    "WARNING: duplicate option `%s' encountered.\n", name);
 		return;
@@ -456,9 +456,15 @@ newopt(struct opt_head *list, char *name, char *value,
 	op->op_ownfile = 0;
 	op->op_value = value;
 	if (op2 != NULL) {
-		while (SLIST_NEXT(op2, op_append) != NULL)
-			op2 = SLIST_NEXT(op2, op_append);
-		SLIST_NEXT(op2, op_append) = op;
+		if (append) {
+			while (SLIST_NEXT(op2, op_append) != NULL)
+				op2 = SLIST_NEXT(op2, op_append);
+			SLIST_NEXT(op2, op_append) = op;
+		} else {
+			while (SLIST_NEXT(op2, op_next) != NULL)
+				op2 = SLIST_NEXT(op2, op_next);
+			SLIST_NEXT(op2, op_next) = op;
+		}
 	} else
 		SLIST_INSERT_HEAD(list, op, op_next);
 }
@@ -471,8 +477,7 @@ rmopt_schedule(struct opt_head *list, char *name)
 {
 	struct opt *op;
 
-	op = findopt(list, name);
-	if (op != NULL) {
+	while ((op = findopt(list, name)) != NULL) {
 		SLIST_REMOVE(list, op, opt, op_next);
 		free(op->op_name);
 		free(op);



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