summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2005-12-30 16:28:06 +0000
committerru <ru@FreeBSD.org>2005-12-30 16:28:06 +0000
commit59fdf73a6329f3374fc227a0ee075258faf861e1 (patch)
tree88ec37e8c7a70a624495559a2639d280f195a656
parent9d1801a10554429dd1cfce2268b2f14d02e25509 (diff)
downloadFreeBSD-src-59fdf73a6329f3374fc227a0ee075258faf861e1.zip
FreeBSD-src-59fdf73a6329f3374fc227a0ee075258faf861e1.tar.gz
- Avoid adding devices multiple times to the device list.
- Avoid adding options multiple times to the option list. Based on a patch by: Matt Emmerton <matt@gsicomp.on.ca>
-rw-r--r--usr.sbin/config/config.y92
-rw-r--r--usr.sbin/config/mkmakefile.c7
2 files changed, 66 insertions, 33 deletions
diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y
index 168f4f8..770833d 100644
--- a/usr.sbin/config/config.y
+++ b/usr.sbin/config/config.y
@@ -343,13 +343,33 @@ newfile(char *name)
}
/*
- * add a device to the list of devices
+ * Find a device in the list of devices.
+ */
+static struct device *
+finddev(char *name)
+{
+ struct device *dp;
+
+ STAILQ_FOREACH(dp, &dtab, d_next)
+ if (eq(dp->d_name, name))
+ return (dp);
+
+ return (NULL);
+}
+
+/*
+ * Add a device to the list of devices.
*/
static void
newdev(char *name)
{
struct device *np;
+ if (finddev(name)) {
+ printf("WARNING: duplicate device `%s' encountered.\n", name);
+ return;
+ }
+
np = (struct device *) malloc(sizeof *np);
memset(np, 0, sizeof(*np));
np->d_name = name;
@@ -357,31 +377,49 @@ newdev(char *name)
}
/*
- * remove a device from the list of devices
+ * Remove a device from the list of devices.
*/
static void
rmdev(char *name)
{
- struct device *dp, *rmdp;
-
- STAILQ_FOREACH(dp, &dtab, d_next) {
- if (eq(dp->d_name, name)) {
- rmdp = dp;
- dp = STAILQ_NEXT(dp, d_next);
- STAILQ_REMOVE(&dtab, rmdp, device, d_next);
- free(rmdp->d_name);
- free(rmdp);
- if (dp == NULL)
- break;
- }
+ struct device *dp;
+
+ dp = finddev(name);
+ if (dp != NULL) {
+ STAILQ_REMOVE(&dtab, dp, device, d_next);
+ free(dp->d_name);
+ free(dp);
}
}
+/*
+ * Find an option in the list of options.
+ */
+static struct opt *
+findopt(struct opt_head *list, char *name)
+{
+ struct opt *op;
+
+ SLIST_FOREACH(op, list, op_next)
+ if (eq(op->op_name, name))
+ return (op);
+
+ return (NULL);
+}
+
+/*
+ * Add an option to the list of options.
+ */
static void
newopt(struct opt_head *list, char *name, char *value)
{
struct opt *op;
+ if (findopt(list, name)) {
+ printf("WARNING: duplicate option `%s' encountered.\n", name);
+ return;
+ }
+
op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
op->op_name = name;
@@ -390,22 +428,20 @@ newopt(struct opt_head *list, char *name, char *value)
SLIST_INSERT_HEAD(list, op, op_next);
}
+/*
+ * Remove an option from the list of options.
+ */
static void
rmopt(struct opt_head *list, char *name)
{
- struct opt *op, *rmop;
-
- SLIST_FOREACH(op, list, op_next) {
- if (eq(op->op_name, name)) {
- rmop = op;
- op = SLIST_NEXT(op, op_next);
- SLIST_REMOVE(list, rmop, opt, op_next);
- free(rmop->op_name);
- if (rmop->op_value != NULL)
- free(rmop->op_value);
- free(rmop);
- if (op == NULL)
- break;
- }
+ struct opt *op;
+
+ op = findopt(list, name);
+ if (op != NULL) {
+ SLIST_REMOVE(list, op, opt, op_next);
+ free(op->op_name);
+ if (op->op_value != NULL)
+ free(op->op_value);
+ free(op);
}
}
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 157cff6..655d7e9 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -310,7 +310,7 @@ read_file(char *fname)
struct device *dp;
struct opt *op;
char *wd, *this, *compilewith, *depends, *clean, *warning;
- int compile, match, nreqs, devfound, std, filetype,
+ int compile, match, nreqs, std, filetype,
imp_rule, no_obj, before_depend, mandatory, nowerror;
fp = fopen(fname, "r");
@@ -465,14 +465,11 @@ nextparam:
nowerror = 1;
goto nextparam;
}
- devfound = 0; /* XXX duplicate device entries */
STAILQ_FOREACH(dp, &dtab, d_next)
if (eq(dp->d_name, wd)) {
dp->d_done |= DEVDONE;
- devfound = 1;
+ goto nextparam;
}
- if (devfound)
- goto nextparam;
if (mandatory) {
printf("%s: mandatory device \"%s\" not found\n",
fname, wd);
OpenPOWER on IntegriCloud