From 0368474a6a610d15c7de92010fde161d9e465180 Mon Sep 17 00:00:00 2001 From: kevans Date: Sun, 6 Jan 2019 02:17:18 +0000 Subject: [PATCH] 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. --- usr.sbin/config/config.y | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index e5296a27156..26bf4c160c9 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -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, int append) } 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, int append) 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); -- 2.45.2