Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Add debugging info.



details:   https://anonhg.NetBSD.org/src/rev/bc58628afa3d
branches:  trunk
changeset: 786373:bc58628afa3d
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 27 17:13:50 2013 +0000

description:
Add debugging info.

diffstat:

 sys/kern/kern_sysctl.c |  101 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 70 insertions(+), 31 deletions(-)

diffs (226 lines):

diff -r d36a3d7f4847 -r bc58628afa3d sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c    Sat Apr 27 17:13:32 2013 +0000
+++ b/sys/kern/kern_sysctl.c    Sat Apr 27 17:13:50 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sysctl.c,v 1.240 2013/02/09 01:20:08 christos Exp $       */
+/*     $NetBSD: kern_sysctl.c,v 1.241 2013/04/27 17:13:50 christos Exp $       */
 
 /*-
  * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.240 2013/02/09 01:20:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.241 2013/04/27 17:13:50 christos Exp $");
 
 #include "opt_defcorename.h"
 #include "ksyms.h"
@@ -106,6 +106,13 @@
 
 typedef void sysctl_setup_func(struct sysctllog **);
 
+#define SYSCTL_DEBUG
+#ifdef SYSCTL_DEBUG
+#define DPRINTF(a)     printf a
+#else
+#define DPRINTF(a)
+#endif
+
 struct sysctllog {
        const struct sysctlnode *log_root;
        int *log_num;
@@ -1433,8 +1440,8 @@
        KASSERT(rw_lock_held(&sysctl_treelock));
 
        if (SYSCTL_VERS(rnode->sysctl_flags) != SYSCTL_VERSION) {
-               printf("sysctl_lookup: rnode %p wrong version\n", rnode);
-               return (EINVAL);
+               printf("%s: rnode %p wrong version\n", __func__, rnode);
+               return EINVAL;
        }
 
        error = 0;
@@ -1443,16 +1450,20 @@
         * you can't "look up" a node.  you can "query" it, but you
         * can't "look it up".
         */
-       if (SYSCTL_TYPE(rnode->sysctl_flags) == CTLTYPE_NODE || namelen != 0)
-               return (EINVAL);
+       if (SYSCTL_TYPE(rnode->sysctl_flags) == CTLTYPE_NODE || namelen != 0) {
+               DPRINTF(("%s: can't lookup a node\n", __func__));
+               return EINVAL;
+       }
 
        /*
         * some nodes are private, so only root can look into them.
         */
        if (l != NULL && (rnode->sysctl_flags & CTLFLAG_PRIVATE) &&
            (error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_SYSCTL,
-           KAUTH_REQ_SYSTEM_SYSCTL_PRVT, NULL, NULL, NULL)) != 0)
-               return (error);
+           KAUTH_REQ_SYSTEM_SYSCTL_PRVT, NULL, NULL, NULL)) != 0) {
+               DPRINTF(("%s: private node\n", __func__));
+               return error;
+       }
 
        /*
         * if a node wants to be writable according to different rules
@@ -1464,8 +1475,10 @@
            !(rnode->sysctl_flags & CTLFLAG_ANYWRITE) &&
            (error = kauth_authorize_system(l->l_cred,
            KAUTH_SYSTEM_SYSCTL, KAUTH_REQ_SYSTEM_SYSCTL_MODIFY, NULL, NULL,
-           NULL)) != 0)
-               return (error);
+           NULL)) != 0) {
+               DPRINTF(("%s: can't modify\n", __func__));
+               return error;
+       }
 
        /*
         * is this node supposedly writable?
@@ -1476,8 +1489,10 @@
         * it appears not to be writable at this time, so if someone
         * tried to write to it, we must tell them to go away
         */
-       if (!rw && newp != NULL)
-               return (EPERM);
+       if (!rw && newp != NULL) {
+               DPRINTF(("%s: not writable\n", __func__));
+               return EPERM;
+       }
 
        /*
         * step one, copy out the stuff we have presently
@@ -1499,7 +1514,8 @@
                        d = __UNCONST(&rnode->sysctl_qdata);
                        break;
                default:
-                       return (EINVAL);
+                       DPRINTF(("%s: bad type\n", __func__));
+                       return EINVAL;
                }
        } else
                d = rnode->sysctl_data;
@@ -1507,17 +1523,20 @@
                sz = strlen(d) + 1; /* XXX@@@ possible fault here */
        else
                sz = rnode->sysctl_size;
-       if (oldp != NULL)
+       if (oldp != NULL) {
                error = sysctl_copyout(l, d, oldp, MIN(sz, *oldlenp));
-       if (error)
-               return (error);
+               if (error) {
+                       DPRINTF(("%s: bad copyout %d\n", __func__, error));
+                       return error;
+               }
+       }
        *oldlenp = sz;
 
        /*
         * are we done?
         */
        if (newp == NULL || newlen == 0)
-               return (0);
+               return 0;
 
        /*
         * hmm...not done.  must now "copy in" new value.  re-adjust
@@ -1531,13 +1550,20 @@
                 * these data must be *exactly* the same size coming
                 * in.  bool may only be true or false.
                 */
-               if (newlen != sz)
-                       return (EINVAL);
+               if (newlen != sz) {
+                       DPRINTF(("%s: bad size %zu != %zu\n", __func__, newlen,
+                           sz));
+                       return EINVAL;
+               }
                error = sysctl_copyin(l, newp, &tmp, sz);
-               if (tmp != true && tmp != false)
+               if (tmp != true && tmp != false) {
+                       DPRINTF(("%s: tmp %d\n", __func__, tmp));
                        return EINVAL;
-               if (error)
+               }
+               if (error) {
+                       DPRINTF(("%s: copyin %d\n", __func__, error));
                        break;
+               }
                *(bool *)d = tmp;
                break;
        }
@@ -1548,8 +1574,11 @@
                 * these data must be *exactly* the same size coming
                 * in.
                 */
-               if (newlen != sz)
-                       return (EINVAL);
+               if (newlen != sz) {
+                       DPRINTF(("%s: bad size %zu != %zu\n", __func__, newlen,
+                           sz));
+                       return EINVAL;
+               }
                error = sysctl_copyin(l, newp, d, sz);
                break;
        case CTLTYPE_STRING: {
@@ -1562,20 +1591,26 @@
                /*
                 * too much new string?
                 */
-               if (newlen > sz)
-                       return (EINVAL);
+               if (newlen > sz) {
+                       DPRINTF(("%s: bad size %zu > %zu\n", __func__, newlen,
+                           sz));
+                       return EINVAL;
+               }
 
                /*
                 * temporary copy of new inbound string
                 */
                len = MIN(sz, newlen);
                newbuf = malloc(len, M_SYSCTLDATA, M_WAITOK|M_CANFAIL);
-               if (newbuf == NULL)
-                       return (ENOMEM);
+               if (newbuf == NULL) {
+                       DPRINTF(("%s: oomem %zu\n", __func__, len));
+                       return ENOMEM;
+               }
                error = sysctl_copyin(l, newp, newbuf, len);
                if (error) {
                        free(newbuf, M_SYSCTLDATA);
-                       return (error);
+                       DPRINTF(("%s: copyin %d\n", __func__, error));
+                       return error;
                }
 
                /*
@@ -1584,7 +1619,8 @@
                 */
                if (newbuf[len - 1] != '\0' && len == sz) {
                        free(newbuf, M_SYSCTLDATA);
-                       return (EINVAL);
+                       DPRINTF(("%s: string too long\n", __func__));
+                       return EINVAL;
                }
 
                /*
@@ -1598,10 +1634,13 @@
                break;
        }
        default:
-               return (EINVAL);
+               DPRINTF(("%s: bad type\n", __func__));
+               return EINVAL;
        }
+       if (error)
+               DPRINTF(("%s: copyin %d\n", __func__, error));
 
-       return (error);
+       return error;
 }
 
 /*



Home | Main Index | Thread Index | Old Index