Module Name:    src
Committed By:   pooka
Date:           Sun May  2 15:35:01 UTC 2010

Modified Files:
        src/usr.bin/config: sem.c

Log Message:
Prefer a real device for pseudoroot and only create a fake device
in the case we are attaching to a pure attribute.  Otherwise we
end up creating a fake device instance every time ...


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/config/sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/config/sem.c
diff -u src/usr.bin/config/sem.c:1.37 src/usr.bin/config/sem.c:1.38
--- src/usr.bin/config/sem.c:1.37	Sat May  1 23:54:35 2010
+++ src/usr.bin/config/sem.c	Sun May  2 15:35:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sem.c,v 1.37 2010/05/01 23:54:35 pooka Exp $	*/
+/*	$NetBSD: sem.c,v 1.38 2010/05/02 15:35:00 pooka Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -1407,6 +1407,12 @@
 	nvfreel(stack);
 }
 
+/*
+ * Insert given device "name" into devroottab.  In case "name"
+ * designates a pure interface attribute, create a fake device
+ * instance for the attribute and insert that into the roottab
+ * (this scheme avoids mucking around with the orphanage analysis).
+ */
 void
 addpseudoroot(const char *name)
 {
@@ -1425,14 +1431,24 @@
 	}
 
 	/*
-	 * Assume given pseudoroot is an interface attribute.  If it
-	 * is, do stunts.  If it isn't, try a device next.
+	 * Prefer device because devices with locators define an
+	 * implicit interface attribute.  However, if a device is
+	 * not available, try to attach to the interface attribute.
+	 * This makes sure adddev() doesn't get confused when we
+	 * are really attaching to a device (alternatively we maybe
+	 * could specify a non-NULL atlist to defdevattach() below).
 	 */
-	attr = ht_lookup(attrtab, intern(buf));
-	if (attr && attr->a_iattr && /*XXX*/strcmp(buf, "mainbus") != 0) {
+	ib = ht_lookup(devbasetab, intern(buf));
+	if (ib == NULL) {
 		struct devbase *fakedev;
 		char fakename[NAMESIZE];
 
+		attr = ht_lookup(attrtab, intern(buf));
+		if (!(attr && attr->a_iattr)) {
+			cfgerror("pseudo-root `%s' not available", name);
+			return;
+		}
+
 		/*
 		 * here we cheat a bit: create a fake devbase with the
 		 * interface attribute and instantiate it.  quick, cheap,
@@ -1441,7 +1457,7 @@
 		 * in ioconf, just used by config to make sure we start from
 		 * the right place.
 		 */ 
-		snprintf(fakename, sizeof(fakename), "%sattrs", buf);
+		snprintf(fakename, sizeof(fakename), "%s_devattrs", buf);
 		fakedev = getdevbase(intern(fakename));
 		fakedev->d_isdef = 1;
 		fakedev->d_ispseudo = 0;
@@ -1458,7 +1474,7 @@
 	/* ok, everything should be set up, so instantiate a fake device */
 	i = getdevi(name);
 	if (i == NULL)
-		return;
+		panic("device `%s' expected to be present", name);
 	ib = i->i_base;
 	iba = ib->d_ahead;
 

Reply via email to