Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/config Tidy up error messages, line wraps, initializ...



details:   https://anonhg.NetBSD.org/src/rev/069e9be5ac54
branches:  trunk
changeset: 828040:069e9be5ac54
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Nov 24 18:45:59 2017 +0000

description:
Tidy up error messages, line wraps, initialization. NFC.

diffstat:

 usr.bin/config/sem.c |  75 +++++++++++++++++++++++++++------------------------
 1 files changed, 40 insertions(+), 35 deletions(-)

diffs (268 lines):

diff -r cb74cd006864 -r 069e9be5ac54 usr.bin/config/sem.c
--- a/usr.bin/config/sem.c      Fri Nov 24 17:51:10 2017 +0000
+++ b/usr.bin/config/sem.c      Fri Nov 24 18:45:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.80 2017/11/19 00:41:10 kre Exp $     */
+/*     $NetBSD: sem.c,v 1.81 2017/11/24 18:45:59 christos Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: sem.c,v 1.80 2017/11/19 00:41:10 kre Exp $");
+__RCSID("$NetBSD: sem.c,v 1.81 2017/11/24 18:45:59 christos Exp $");
 
 #include <sys/param.h>
 #include <ctype.h>
@@ -214,7 +214,8 @@
        CFGDBG(4, "fixing devbase `%s'", dev->d_name);
        for (al = dev->d_attrs; al != NULL; al = al->al_next) {
                a = al->al_this;
-               CFGDBG(4, "fixing devbase `%s' attr `%s'", dev->d_name, a->a_name);
+               CFGDBG(4, "fixing devbase `%s' attr `%s'", dev->d_name,
+                   a->a_name);
                if (a->a_iattr) {
                        a->a_refs = addtoattr(a->a_refs, dev);
                        CFGDBG(3, "device `%s' has iattr `%s'", dev->d_name,
@@ -228,8 +229,8 @@
                        }
                        if (dev->d_classattr == NULL) {
                                dev->d_classattr = a;
-                               CFGDBG(3, "device `%s' is devclass `%s'", dev->d_name,
-                                   a->a_name);
+                               CFGDBG(3, "device `%s' is devclass `%s'",
+                                   dev->d_name, a->a_name);
                        }
                } else {
                        if (strcmp(dev->d_name, a->a_name) != 0) {
@@ -396,7 +397,7 @@
        struct loclist *ll;
 
        if (devclass)
-               panic("defattr(%s): locators and devclass", name);
+               panic("%s: %s has both locators and devclass", __func__, name);
 
        if (defattr(name, locs, deps, devclass) != 0)
                return (1);
@@ -426,7 +427,8 @@
        int errored = 0;
 
        if (deps)
-               panic("defattr(%s): dependencies and devclass", name);
+               panic("%s: %s has both dependencies and devclass", __func__,
+                   name);
 
        if (defattr(name, locs, deps, devclass) != 0)
                return (1);
@@ -434,9 +436,9 @@
        a = getattr(name);
        (void)snprintf(classenum, sizeof(classenum), "DV_%s", name);
        for (cp = classenum + 3; *cp; cp++) {
-               if (!errored &&
-                   (!isalnum((unsigned char)*cp) ||
-                     (isalpha((unsigned char)*cp) && !islower((unsigned char)*cp)))) {
+               if (!errored && (!isalnum((unsigned char)*cp) ||
+                     (isalpha((unsigned char)*cp)
+                     && !islower((unsigned char)*cp)))) {
                        cfgerror("device class names must be "
                            "lower-case alphanumeric characters");
                        errored = 1;
@@ -625,7 +627,7 @@
                dev->d_umax = 0;
                TAILQ_INSERT_TAIL(&allbases, dev, d_next);
                if (ht_insert(devbasetab, name, dev))
-                       panic("getdevbase(%s)", name);
+                       panic("%s: Can't insert %s", __func__, name);
                CFGDBG(3, "devbase defined `%s'", dev->d_name);
        }
        return (dev);
@@ -765,7 +767,7 @@
                deva->d_ipp = &deva->d_ihead;
                TAILQ_INSERT_TAIL(&alldevas, deva, d_next);
                if (ht_insert(devatab, name, deva))
-                       panic("getdeva(%s)", name);
+                       panic("%s: Can't insert %s", __func__, name);
        }
        return (deva);
 }
@@ -938,7 +940,7 @@
        char buf[NAMESIZE];
 
        if ((part -= 'a') >= maxpartitions || part < 0)
-               panic("resolve");
+               panic("%s: Bad partition %c", __func__, part);
        if ((nv = *nvp) == NULL) {
                dev_t   d = NODEV;
                /*
@@ -1111,7 +1113,7 @@
                if (!strcmp(cf->cf_name, name))
                        break;
        if (cf == NULL)
-               panic("lost configuration `%s'", name);
+               panic("%s: lost configuration for %s", __func__, name);
 
        TAILQ_REMOVE(&allcf, cf, cf_next);
 }
@@ -1251,14 +1253,12 @@
        struct devbase *ab;     /* not NULL => at another dev */
        struct deva *iba;       /* devbase attachment used */
        struct deva *lastiba;
-       int atunit;
+       int atunit, first;
 
        lastiba = NULL;
        if ((i = getdevi(name)) == NULL)
                goto bad;
        ib = i->i_base;
-       iba = NULL;
-       p = NULL;
        attr = finddevattr(name, at, ib, &ab, &atunit);
        if (attr == NULL) {
                i->i_active = DEVI_BROKEN;
@@ -1271,11 +1271,13 @@
                            attr == &errattr ? NULL : attr))
                                break;
 
+               first = lastiba == ib->d_ahead;
                if (iba == NULL) {
-                       if (lastiba != ib->d_ahead)
+                       if (!first)
                                goto bad;
                        if (attr != &errattr) {
-                               panic("adddev: can't figure out attachment");
+                               panic("%s: can't figure out attachment",
+                                   __func__);
                        } else {
                                cfgerror("`%s' cannot attach to the root",
                                    ib->d_name);
@@ -1283,7 +1285,7 @@
                        }
                }
                // get a new one if it is not the first time
-               if (lastiba != ib->d_ahead && (i = getdevi(name)) == NULL)
+               if (!first && (i = getdevi(name)) == NULL)
                        goto bad;
 
                if (attr != &errattr) {
@@ -1296,7 +1298,8 @@
                         */
                        p = getpspec(attr, ab, atunit, iba);
                        p->p_devs = newnv(NULL, NULL, i, 0, p->p_devs);
-               }
+               } else
+                       p = NULL;
 
                if ((i->i_locs = fixloc(name, attr, loclist)) == NULL) {
                        i->i_active = DEVI_BROKEN;
@@ -1399,7 +1402,7 @@
        CFGDBG(5, "removing devi `%s'", i->i_name);
        f = ht_lookup(devitab, i->i_name);
        if (f == NULL)
-               panic("remove_devi(): instance %s disappeared from devitab",
+               panic("%s: instance %s disappeared from devitab", __func__,
                    i->i_name);
 
        if (i->i_active == DEVI_BROKEN) {
@@ -1447,8 +1450,8 @@
                    ppi = &(*ppi)->i_bsame)
                        continue;
                if (*ppi == NULL)
-                       panic("deldev: dev (%s) doesn't list the devi"
-                           " (%s at %s)", d->d_name, i->i_name, i->i_at);
+                       panic("%s: dev (%s) doesn't list the devi (%s at %s)",
+                           __func__, d->d_name, i->i_name, i->i_at);
                f = *ppi;
                if (f == i)
                        /* That implies d->d_ihead == i */
@@ -1474,7 +1477,7 @@
            ppi = &(*ppi)->i_asame)
                continue;
        if (*ppi == NULL)
-               panic("deldev: deva (%s) doesn't list the devi (%s)",
+               panic("%s: deva (%s) doesn't list the devi (%s)", __func__,
                    iba->d_name, i->i_name);
        f = *ppi;
        if (f == i)
@@ -1513,7 +1516,7 @@
        f = ht_lookup(deaddevitab, i->i_name);
        if (f == NULL) {
                if (ht_insert(deaddevitab, i->i_name, i))
-                       panic("remove_devi(%s) - can't add to deaddevitab",
+                       panic("%s: can't add %s to deaddevitab", __func__,
                            i->i_name);
        } else {
                for (j = f; j->i_alias != NULL; j = j->i_alias)
@@ -1733,7 +1736,8 @@
        /* ok, everything should be set up, so instantiate a fake device */
        i = getdevi(name);
        if (i == NULL)
-               panic("device `%s' expected to be present", name);
+               panic("%s: device `%s' expected to be present", __func__,
+                   name);
        ib = i->i_base;
        iba = ib->d_ahead;
 
@@ -1767,9 +1771,9 @@
        d->d_ihead = NULL;      /* make sure it won't be considered active */
        TAILQ_REMOVE(&allpseudo, i, i_next);
        if (ht_remove(devitab, name))
-               panic("%s(%s) - can't remove from devitab", __func__, name);
+               panic("%s: Can't remove %s from devitab", __func__, name);
        if (ht_insert(deaddevitab, name, i))
-               panic("%s(%s) - can't add to deaddevitab", __func__, name);
+               panic("%s: Can't add %s to deaddevitab", __func__, name);
 }
 
 void
@@ -1793,7 +1797,7 @@
        }
        i = newdevi(name, number - 1, d);       /* foo 16 => "foo0..foo15" */
        if (ht_insert(devitab, name, i))
-               panic("addpseudo(%s)", name);
+               panic("%s: %s", __func__, name);
        /* Useful to retrieve the instance from the devbase */
        d->d_ihead = i;
        i->i_active = DEVI_ACTIVE;
@@ -1863,6 +1867,7 @@
 int
 fixdevis(void)
 {
+       const char *msg;
        struct devi *i;
        struct pspec *p;
        int error = 0;
@@ -1878,11 +1883,11 @@
                         */
                        ++error;
                        p = i->i_pspec;
+                       msg = p == NULL ? "no parent" :
+                           (p->p_atunit == WILD ? "nothing matching" : "no");
                        cfgxerror(i->i_srcfile, i->i_lineno,
                            "`%s at %s' is orphaned (%s `%s' found)", 
-                           i->i_name, i->i_at,
-                           p == NULL || p->p_atunit == WILD ?
-                           "nothing matching" : "no", i->i_at);
+                           i->i_name, i->i_at, msg, i->i_at);
                } else if (vflag && i->i_active == DEVI_IGNORED)
                        cfgxwarn(i->i_srcfile, i->i_lineno, "ignoring "
                            "explicitly orphaned instance `%s at %s'",
@@ -1960,7 +1965,7 @@
        i = newdevi(name, unit, d);
        if (firsti == NULL) {
                if (ht_insert(devitab, name, i))
-                       panic("getdevi(%s)", name);
+                       panic("%s: %s", __func__, name);
                *d->d_ipp = i;
                d->d_ipp = &i->i_bsame;
        } else {
@@ -2233,7 +2238,7 @@
                lp[ord] = m->ll_string;
        }
        if (ord != attr->a_loclen)
-               panic("fixloc");
+               panic("%s: bad length", __func__);
        lp[ord] = NULL;
        nextra = 0;
        ep = extra;



Home | Main Index | Thread Index | Old Index