Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys In sysctl_realloc(), don't make 'i' act as both an child...
details: https://anonhg.NetBSD.org/src/rev/62a70b906a11
branches: trunk
changeset: 746862:62a70b906a11
user: dyoung <dyoung%NetBSD.org@localhost>
date: Fri Aug 21 22:51:00 2009 +0000
description:
In sysctl_realloc(), don't make 'i' act as both an child-array
iterator and the length of the old child array, but introduce a
new variable, 'olen', for the latter purpose.
In sysctl_alloc(), name a constant.
Introduce sysctl_log_print(), a handy debug routine.
No functional changes intended.
diffstat:
sys/kern/kern_sysctl.c | 58 +++++++++++++++++++++++++++++++++++++++----------
sys/sys/sysctl.h | 3 +-
2 files changed, 48 insertions(+), 13 deletions(-)
diffs (134 lines):
diff -r 941a23511e7c -r 62a70b906a11 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c Fri Aug 21 22:43:32 2009 +0000
+++ b/sys/kern/kern_sysctl.c Fri Aug 21 22:51:00 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sysctl.c,v 1.223 2009/08/21 22:43:32 dyoung Exp $ */
+/* $NetBSD: kern_sysctl.c,v 1.224 2009/08/21 22:51:00 dyoung 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.223 2009/08/21 22:43:32 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.224 2009/08/21 22:51:00 dyoung Exp $");
#include "opt_defcorename.h"
#include "ksyms.h"
@@ -2313,9 +2313,43 @@
rw_exit(&sysctl_treelock);
}
+void
+sysctl_log_print(const struct sysctllog *slog)
+{
+ int i, len;
+
+ printf("root %p left %d size %d content", (const void *)slog->log_root,
+ slog->log_left, slog->log_size);
+
+ for (len = 0, i = slog->log_left; i < slog->log_size; i++) {
+ switch (len) {
+ case 0:
+ len = -1;
+ printf(" version %d", slog->log_num[i]);
+ break;
+ case -1:
+ len = -2;
+ printf(" type %d", slog->log_num[i]);
+ break;
+ case -2:
+ len = slog->log_num[i];
+ printf(" len %d:", slog->log_num[i]);
+ if (len <= 0)
+ len = -1;
+ break;
+ default:
+ len--;
+ printf(" %d", slog->log_num[i]);
+ break;
+ }
+ }
+ printf(" end\n");
+}
+
int
sysctl_log_add(struct sysctllog **logp, const struct sysctlnode *node)
{
+ const int size0 = 16;
int name[CTL_MAXNAME], namelen, i;
const struct sysctlnode *pnode;
struct sysctllog *log;
@@ -2333,17 +2367,17 @@
/* XXX print error message? */
return (-1);
}
- log->log_num = malloc(16 * sizeof(int),
+ log->log_num = malloc(size0 * sizeof(int),
M_SYSCTLDATA, M_WAITOK|M_CANFAIL);
if (log->log_num == NULL) {
/* XXX print error message? */
free(log, M_SYSCTLDATA);
return (-1);
}
- memset(log->log_num, 0, 16 * sizeof(int));
+ memset(log->log_num, 0, size0 * sizeof(int));
log->log_root = NULL;
- log->log_size = 16;
- log->log_left = 16;
+ log->log_size = size0;
+ log->log_left = size0;
*logp = log;
} else
log = *logp;
@@ -2578,7 +2612,7 @@
static int
sysctl_realloc(struct sysctlnode *p)
{
- int i, j;
+ int i, j, olen;
struct sysctlnode *n;
assert(p->sysctl_csize == p->sysctl_clen);
@@ -2586,8 +2620,8 @@
/*
* how many do we have...how many should we make?
*/
- i = p->sysctl_clen;
- n = malloc(2 * i * sizeof(struct sysctlnode), M_SYSCTLNODE,
+ olen = p->sysctl_clen;
+ n = malloc(2 * olen * sizeof(struct sysctlnode), M_SYSCTLNODE,
M_WAITOK|M_CANFAIL);
if (n == NULL)
return (ENOMEM);
@@ -2595,9 +2629,9 @@
/*
* move old children over...initialize new children
*/
- memcpy(n, p->sysctl_child, i * sizeof(struct sysctlnode));
- memset(&n[i], 0, i * sizeof(struct sysctlnode));
- p->sysctl_csize = 2 * i;
+ memcpy(n, p->sysctl_child, olen * sizeof(struct sysctlnode));
+ memset(&n[olen], 0, olen * sizeof(struct sysctlnode));
+ p->sysctl_csize = 2 * olen;
/*
* reattach moved (and new) children to parent; if a moved
diff -r 941a23511e7c -r 62a70b906a11 sys/sys/sysctl.h
--- a/sys/sys/sysctl.h Fri Aug 21 22:43:32 2009 +0000
+++ b/sys/sys/sysctl.h Fri Aug 21 22:51:00 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysctl.h,v 1.185 2009/07/22 22:53:41 alc Exp $ */
+/* $NetBSD: sysctl.h,v 1.186 2009/08/21 22:51:00 dyoung Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -1164,6 +1164,7 @@
void sysctl_dump(const struct sysctlnode *);
void sysctl_free(struct sysctlnode *);
void sysctl_teardown(struct sysctllog **);
+void sysctl_log_print(const struct sysctllog *);
#ifdef SYSCTL_INCLUDE_DESCR
#define SYSCTL_DESCR(s) s
Home |
Main Index |
Thread Index |
Old Index