From 0739963874c598138e042011d5f23e4182383b9c Mon Sep 17 00:00:00 2001 From: Ralf Corsepius Date: Mon, 19 Apr 2004 13:49:10 +0000 Subject: 2004-04-19 Ralf Corsepius * libnetworking/sys/sysctl.h: Partial update from FreeBSD. * libnetworking/kern/kern_sysctl.c: Partial update from FreeBSD. --- cpukit/ChangeLog | 5 ++++ cpukit/libnetworking/kern/kern_sysctl.c | 53 ++++++++++++++++----------------- cpukit/libnetworking/sys/sysctl.h | 11 +++++-- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index b82cbc5ff8..e4bd9a488a 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,8 @@ +2004-04-19 Ralf Corsepius + + * libnetworking/sys/sysctl.h: Partial update from FreeBSD. + * libnetworking/kern/kern_sysctl.c: Partial update from FreeBSD. + 2004-04-17 Ralf Corsepius * libfs/src/imfs/imfs_debug.c, libfs/src/imfs/memfile.c: diff --git a/cpukit/libnetworking/kern/kern_sysctl.c b/cpukit/libnetworking/kern/kern_sysctl.c index c2bbb4aedd..c0ba70cfc4 100644 --- a/cpukit/libnetworking/kern/kern_sysctl.c +++ b/cpukit/libnetworking/kern/kern_sysctl.c @@ -16,10 +16,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -441,7 +437,7 @@ SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0); /* * "Staff-functions" * - * These functions implement a presently undocumented interface + * These functions implement a presently undocumented interface * used by the sysctl program to walk the tree, and get the type * so it can print the value. * This interface is under work and consideration, and should probably @@ -551,7 +547,7 @@ sysctl_sysctl_name(SYSCTL_HANDLER_ARGS) namelen--; name++; - if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE) + if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE) break; if (oid->oid_handler) @@ -568,7 +564,7 @@ sysctl_sysctl_name(SYSCTL_HANDLER_ARGS) SYSCTL_NODE(_sysctl, 1, name, CTLFLAG_RD, sysctl_sysctl_name, ""); static int -sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, +sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, int *next, int *len, int level, struct sysctl_oid **oidpp) { struct sysctl_oid *oidp; @@ -582,13 +578,13 @@ sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, continue; if (!namelen) { - if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) + if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) return 0; - if (oidp->oid_handler) + if (oidp->oid_handler) /* We really should call the handler here...*/ return 0; lsp = (struct sysctl_oid_list *)oidp->oid_arg1; - if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1, + if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1, len, level+1, oidpp)) return 0; goto next; @@ -603,7 +599,7 @@ sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, if (oidp->oid_handler) return 0; lsp = (struct sysctl_oid_list *)oidp->oid_arg1; - if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, + if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, len, level+1, oidpp)) return (0); goto next; @@ -615,7 +611,7 @@ sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, continue; lsp = (struct sysctl_oid_list *)oidp->oid_arg1; - if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, + if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, len, level+1, oidpp)) return (0); next: @@ -661,7 +657,7 @@ name2oid (char *name, int *oid, int *len, struct sysctl_oid **oidpp) *len = 0; - for (p = name; *p && *p != '.'; p++) + for (p = name; *p && *p != '.'; p++) ; i = *p; if (i == '.') @@ -692,7 +688,7 @@ name2oid (char *name, int *oid, int *len, struct sysctl_oid **oidpp) lsp = (struct sysctl_oid_list *)oidp->oid_arg1; oidp = SLIST_FIRST(lsp); name = p+1; - for (p = name; *p && *p != '.'; p++) + for (p = name; *p && *p != '.'; p++) ; i = *p; if (i == '.') @@ -708,7 +704,7 @@ sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS) int error, oid[CTL_MAXNAME], len; struct sysctl_oid *op = 0; - if (!req->newlen) + if (!req->newlen) return ENOENT; if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */ return (ENAMETOOLONG); @@ -734,7 +730,7 @@ sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS) return (error); } -SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0, +SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0, sysctl_sysctl_name2oid, "I", ""); static int @@ -978,19 +974,19 @@ kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old, req.oldfunc = sysctl_old_kernel; req.newfunc = sysctl_new_kernel; - req.lock = 1; + req.lock = REQ_LOCKED; SYSCTL_LOCK(); error = sysctl_root(0, name, namelen, &req); - if (req.lock == 2) + if (req.lock == REQ_WIRED) #ifdef __rtems__ printf ("kern_sysctl: vsunlock needs to be called!\n"); #else vsunlock(req.oldptr, req.oldlen); #endif - + SYSCTL_UNLOCK(); if (error && error != ENOMEM) @@ -1084,11 +1080,12 @@ sysctl_new_user(struct sysctl_req *req, void *p, size_t l) void sysctl_wire_old_buffer(struct sysctl_req *req, size_t len) { - if (req->lock == 1 && req->oldptr && req->oldfunc == sysctl_old_user) { + if (req->lock == REQ_LOCKED && req->oldptr && + req->oldfunc == sysctl_old_user) { #ifndef __rtems__ vslock(req->oldptr, req->oldlen); #endif - req->lock = 2; + req->lock = REQ_WIRED; } } @@ -1105,7 +1102,7 @@ sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, if (oid->oid_number == name[indx]) { indx++; if (oid->oid_kind & CTLFLAG_NOLOCK) - req->lock = 0; + req->lock = REQ_UNLOCKED; if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) { if (oid->oid_handler != NULL || indx == namelen) { @@ -1169,7 +1166,7 @@ sysctl_root(SYSCTL_HANDLER_ARGS) if (error) return (error); } - + /* Is this sysctl writable by only privileged users? */ if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) { int flags; @@ -1183,7 +1180,7 @@ sysctl_root(SYSCTL_HANDLER_ARGS) return (error); } #endif - + if (!oid->oid_handler) return EINVAL; @@ -1284,7 +1281,7 @@ userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, req.oldfunc = sysctl_old_user; req.newfunc = sysctl_new_user; - req.lock = 1; + req.lock = REQ_LOCKED; SYSCTL_LOCK(); @@ -1304,10 +1301,10 @@ userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, req = req2; #ifndef __rtems__ - if (req.lock == 2) + if (req.lock == REQ_WIRED) vsunlock(req.oldptr, req.oldlen); #endif - + SYSCTL_UNLOCK(); if (error && error != ENOMEM) @@ -1440,7 +1437,7 @@ ogetkerninfo(struct thread *td, struct getkerninfo_args *uap) case KINFO_METER: name[0] = CTL_VM; - name[1] = VM_METER; + name[1] = VM_TOTAL; error = userland_sysctl(td, name, 2, uap->where, uap->size, 0, 0, 0, &size); break; diff --git a/cpukit/libnetworking/sys/sysctl.h b/cpukit/libnetworking/sys/sysctl.h index 063f88a880..7cb192f209 100644 --- a/cpukit/libnetworking/sys/sysctl.h +++ b/cpukit/libnetworking/sys/sysctl.h @@ -93,7 +93,7 @@ struct ctlname { * technology. This is the way nearly all new sysctl variables should * be implemented. * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); - */ + */ #define OID_AUTO (-1) /* @@ -106,13 +106,18 @@ struct ctlname { #define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \ struct sysctl_req *req +/* definitions for sysctl_req 'lock' member */ +#define REQ_UNLOCKED 0 /* not locked and not wired */ +#define REQ_LOCKED 1 /* locked and not wired */ +#define REQ_WIRED 2 /* locked and wired */ + /* * This describes the access space for a sysctl request. This is needed * so that we can use the interface from the kernel or from user-space. */ struct sysctl_req { struct thread *td; /* used for access checking */ - int lock; + int lock; /* locking/wiring state */ void *oldptr; size_t oldlen; size_t oldidx; @@ -328,7 +333,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); #define KERN_BOOTTIME 21 /* struct: time kernel was booted */ #define KERN_NISDOMAINNAME 22 /* string: YP domain name */ #define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */ -#define KERN_OSRELDATE 24 /* int: OS release date */ +#define KERN_OSRELDATE 24 /* int: kernel release date */ #define KERN_NTP_PLL 25 /* node: NTP PLL control */ #define KERN_BOOTFILE 26 /* string: name of booted kernel */ #define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */ -- cgit v1.2.3