Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config When deleting orphans detect parent<->child l...



details:   https://anonhg.NetBSD.org/src/rev/27ecbf237ecd
branches:  trunk
changeset: 827886:27ecbf237ecd
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Nov 16 17:08:07 2017 +0000

description:
When deleting orphans detect parent<->child loops and break them.
"active" is not a boolean, use the right comparison.

diffstat:

 usr.bin/config/defs.h |   4 +++-
 usr.bin/config/main.c |  28 +++++++++++++++++++++++-----
 2 files changed, 26 insertions(+), 6 deletions(-)

diffs (91 lines):

diff -r 48693b72ac9c -r 27ecbf237ecd usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Thu Nov 16 14:28:19 2017 +0000
+++ b/usr.bin/config/defs.h     Thu Nov 16 17:08:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.99 2017/06/16 00:10:09 christos Exp $       */
+/*     $NetBSD: defs.h,v 1.100 2017/11/16 17:08:07 christos Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -264,6 +264,8 @@
 struct devbase {
        const char *d_name;             /* e.g., "sd" */
        TAILQ_ENTRY(devbase) d_next;
+       int     d_level;
+       struct devbase *d_levelparent;
        int     d_isdef;                /* set once properly defined */
        int     d_ispseudo;             /* is a pseudo-device */
        devmajor_t d_major;             /* used for "root on sd0", e.g. */
diff -r 48693b72ac9c -r 27ecbf237ecd usr.bin/config/main.c
--- a/usr.bin/config/main.c     Thu Nov 16 14:28:19 2017 +0000
+++ b/usr.bin/config/main.c     Thu Nov 16 17:08:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.91 2016/09/05 00:40:28 sevan Exp $  */
+/*     $NetBSD: main.c,v 1.92 2017/11/16 17:08:07 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.91 2016/09/05 00:40:28 sevan Exp $");
+__RCSID("$NetBSD: main.c,v 1.92 2017/11/16 17:08:07 christos Exp $");
 
 #ifndef MAKE_BOOTSTRAP
 #include <sys/cdefs.h>
@@ -1868,6 +1868,15 @@
        return 0;
 }
 
+static int
+is_orphan_loop(const struct devbase *d, const struct devbase *p)
+{
+
+       for (; p && d != p; p = p->d_levelparent)
+               continue;
+       return d == p;
+}
+
 static void
 do_kill_orphans(struct devbase *d, struct attr *at, struct devbase *parent,
     int state)
@@ -1879,6 +1888,9 @@
        struct pspec *p;
        int active = 0;
 
+       if (d->d_levelparent == NULL)
+               d->d_levelparent = parent;
+
        /*
         * A pseudo-device will always attach at root, and if it has an
         * instance (it cannot have more than one), it is enough to consider
@@ -1938,9 +1950,9 @@
                /*
                 * If we've been there but have made no change, stop.
                 */
-               if (seen && !active)
+               if (seen && active != DEVI_ACTIVE)
                        return;
-               if (!active) {
+               if (active != DEVI_ACTIVE) {
                        struct cdd_params cdd = { d, at, parent };
                        /* Look for a matching dead devi */
                        if (ht_enumerate(deaddevitab, check_dead_devi, &cdd) &&
@@ -1963,9 +1975,15 @@
 
        for (al = d->d_attrs; al != NULL; al = al->al_next) {
                a = al->al_this;
-               for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
+               for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next) {
+                       if (is_orphan_loop(nv1->nv_ptr, d)) {
+                               if (d->d_level++ > 1)
+                                       continue;
+                       }
                        do_kill_orphans(nv1->nv_ptr, a, d, active);
+               }
        }
+       d->d_levelparent = NULL;
 }
 
 static int



Home | Main Index | Thread Index | Old Index