No functional change, just a tiny hoisting in the parser I'd like to better reflect the order in which we parse the tokens.
If the given domain was already specified, don't bother allocating and initializing it. Drop the obvious comment while here. OK? Index: parse.y =================================================================== RCS file: /cvs/src/usr.sbin/ldomctl/parse.y,v retrieving revision 1.13 diff -u -p -r1.13 parse.y --- parse.y 28 Nov 2019 18:40:42 -0000 1.13 +++ parse.y 30 Dec 2019 22:54:10 -0000 @@ -110,6 +110,12 @@ grammar : /* empty */ ; domain : DOMAIN STRING optnl '{' optnl { + struct domain *odomain; + SIMPLEQ_FOREACH(odomain, &conf->domain_list, entry) + if (strcmp(odomain->name, $2) == 0) { + yyerror("duplicate domain name: %s", $2); + YYERROR; + } domain = xzalloc(sizeof(struct domain)); domain->name = $2; SIMPLEQ_INIT(&domain->vdisk_list); @@ -118,13 +124,6 @@ domain : DOMAIN STRING optnl '{' optnl SIMPLEQ_INIT(&domain->iodev_list); } domainopts_l '}' { - /* domain names need to be unique. */ - struct domain *odomain; - SIMPLEQ_FOREACH(odomain, &conf->domain_list, entry) - if (strcmp(odomain->name, $2) == 0) { - yyerror("duplicate domain name: %s", $2); - YYERROR; - } SIMPLEQ_INSERT_TAIL(&conf->domain_list, domain, entry); domain = NULL; }