Deleted Added
full compact
kern_sysctl.c (109246) kern_sysctl.c (109623)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD

--- 23 unchanged lines hidden (view full) ---

32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD

--- 23 unchanged lines hidden (view full) ---

32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
40 * $FreeBSD: head/sys/kern/kern_sysctl.c 109246 2003-01-14 19:35:33Z dillon $
40 * $FreeBSD: head/sys/kern/kern_sysctl.c 109623 2003-01-21 08:56:16Z alfred $
41 */
42
43#include "opt_compat.h"
44#include "opt_mac.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/kernel.h>

--- 170 unchanged lines hidden (view full) ---

219/* Add an entry to the context */
220struct sysctl_ctx_entry *
221sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
222{
223 struct sysctl_ctx_entry *e;
224
225 if (clist == NULL || oidp == NULL)
226 return(NULL);
41 */
42
43#include "opt_compat.h"
44#include "opt_mac.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/kernel.h>

--- 170 unchanged lines hidden (view full) ---

219/* Add an entry to the context */
220struct sysctl_ctx_entry *
221sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
222{
223 struct sysctl_ctx_entry *e;
224
225 if (clist == NULL || oidp == NULL)
226 return(NULL);
227 e = malloc(sizeof(struct sysctl_ctx_entry), M_SYSCTLOID, M_WAITOK);
227 e = malloc(sizeof(struct sysctl_ctx_entry), M_SYSCTLOID, 0);
228 e->entry = oidp;
229 TAILQ_INSERT_HEAD(clist, e, link);
230 return (e);
231}
232
233/* Find an entry in the context */
234struct sysctl_ctx_entry *
235sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)

--- 113 unchanged lines hidden (view full) ---

349 if (clist != NULL)
350 sysctl_ctx_entry_add(clist, oidp);
351 return (oidp);
352 } else {
353 printf("can't re-use a leaf (%s)!\n", name);
354 return (NULL);
355 }
356 }
228 e->entry = oidp;
229 TAILQ_INSERT_HEAD(clist, e, link);
230 return (e);
231}
232
233/* Find an entry in the context */
234struct sysctl_ctx_entry *
235sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)

--- 113 unchanged lines hidden (view full) ---

349 if (clist != NULL)
350 sysctl_ctx_entry_add(clist, oidp);
351 return (oidp);
352 } else {
353 printf("can't re-use a leaf (%s)!\n", name);
354 return (NULL);
355 }
356 }
357 oidp = malloc(sizeof(struct sysctl_oid), M_SYSCTLOID, M_WAITOK|M_ZERO);
357 oidp = malloc(sizeof(struct sysctl_oid), M_SYSCTLOID, M_ZERO);
358 oidp->oid_parent = parent;
359 SLIST_NEXT(oidp, oid_link) = NULL;
360 oidp->oid_number = number;
361 oidp->oid_refcnt = 1;
362 len = strlen(name);
358 oidp->oid_parent = parent;
359 SLIST_NEXT(oidp, oid_link) = NULL;
360 oidp->oid_number = number;
361 oidp->oid_refcnt = 1;
362 len = strlen(name);
363 newname = malloc(len + 1, M_SYSCTLOID, M_WAITOK);
363 newname = malloc(len + 1, M_SYSCTLOID, 0);
364 bcopy(name, newname, len + 1);
365 newname[len] = '\0';
366 oidp->oid_name = newname;
367 oidp->oid_handler = handler;
368 oidp->oid_kind = CTLFLAG_DYN | kind;
369 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
370 /* Allocate space for children */
371 SYSCTL_CHILDREN(oidp) = malloc(sizeof(struct sysctl_oid_list),
364 bcopy(name, newname, len + 1);
365 newname[len] = '\0';
366 oidp->oid_name = newname;
367 oidp->oid_handler = handler;
368 oidp->oid_kind = CTLFLAG_DYN | kind;
369 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
370 /* Allocate space for children */
371 SYSCTL_CHILDREN(oidp) = malloc(sizeof(struct sysctl_oid_list),
372 M_SYSCTLOID, M_WAITOK);
372 M_SYSCTLOID, 0);
373 SLIST_INIT(SYSCTL_CHILDREN(oidp));
374 } else {
375 oidp->oid_arg1 = arg1;
376 oidp->oid_arg2 = arg2;
377 }
378 oidp->oid_fmt = fmt;
379 if (descr) {
380 int len = strlen(descr) + 1;
373 SLIST_INIT(SYSCTL_CHILDREN(oidp));
374 } else {
375 oidp->oid_arg1 = arg1;
376 oidp->oid_arg2 = arg2;
377 }
378 oidp->oid_fmt = fmt;
379 if (descr) {
380 int len = strlen(descr) + 1;
381 oidp->descr = malloc(len, M_SYSCTLOID, M_WAITOK);
381 oidp->descr = malloc(len, M_SYSCTLOID, 0);
382 if (oidp->descr)
383 strcpy((char *)(uintptr_t)(const void *)oidp->descr, descr);
384 }
385 /* Update the context, if used */
386 if (clist != NULL)
387 sysctl_ctx_entry_add(clist, oidp);
388 /* Register this oid */
389 sysctl_register_oid(oidp);

--- 284 unchanged lines hidden (view full) ---

674 int error, oid[CTL_MAXNAME], len;
675 struct sysctl_oid *op = 0;
676
677 if (!req->newlen)
678 return ENOENT;
679 if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */
680 return (ENAMETOOLONG);
681
382 if (oidp->descr)
383 strcpy((char *)(uintptr_t)(const void *)oidp->descr, descr);
384 }
385 /* Update the context, if used */
386 if (clist != NULL)
387 sysctl_ctx_entry_add(clist, oidp);
388 /* Register this oid */
389 sysctl_register_oid(oidp);

--- 284 unchanged lines hidden (view full) ---

674 int error, oid[CTL_MAXNAME], len;
675 struct sysctl_oid *op = 0;
676
677 if (!req->newlen)
678 return ENOENT;
679 if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */
680 return (ENAMETOOLONG);
681
682 p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK);
682 p = malloc(req->newlen+1, M_SYSCTL, 0);
683
684 error = SYSCTL_IN(req, p, req->newlen);
685 if (error) {
686 free(p, M_SYSCTL);
687 return (error);
688 }
689
690 p [req->newlen] = '\0';

--- 127 unchanged lines hidden (view full) ---

818 size_t outlen;
819
820 /*
821 * Attempt to get a coherent snapshot by copying to a
822 * temporary kernel buffer.
823 */
824retry:
825 outlen = strlen((char *)arg1)+1;
683
684 error = SYSCTL_IN(req, p, req->newlen);
685 if (error) {
686 free(p, M_SYSCTL);
687 return (error);
688 }
689
690 p [req->newlen] = '\0';

--- 127 unchanged lines hidden (view full) ---

818 size_t outlen;
819
820 /*
821 * Attempt to get a coherent snapshot by copying to a
822 * temporary kernel buffer.
823 */
824retry:
825 outlen = strlen((char *)arg1)+1;
826 tmparg = malloc(outlen, M_SYSCTLTMP, M_WAITOK);
826 tmparg = malloc(outlen, M_SYSCTLTMP, 0);
827
828 if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) {
829 free(tmparg, M_SYSCTLTMP);
830 goto retry;
831 }
832
833 error = SYSCTL_OUT(req, tmparg, outlen);
834 free(tmparg, M_SYSCTLTMP);

--- 27 unchanged lines hidden (view full) ---

862 * Attempt to get a coherent snapshot, either by wiring the
863 * user space buffer or copying to a temporary kernel buffer
864 * depending on the size of the data.
865 */
866 if (arg2 > PAGE_SIZE) {
867 sysctl_wire_old_buffer(req, arg2);
868 error = SYSCTL_OUT(req, arg1, arg2);
869 } else {
827
828 if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) {
829 free(tmparg, M_SYSCTLTMP);
830 goto retry;
831 }
832
833 error = SYSCTL_OUT(req, tmparg, outlen);
834 free(tmparg, M_SYSCTLTMP);

--- 27 unchanged lines hidden (view full) ---

862 * Attempt to get a coherent snapshot, either by wiring the
863 * user space buffer or copying to a temporary kernel buffer
864 * depending on the size of the data.
865 */
866 if (arg2 > PAGE_SIZE) {
867 sysctl_wire_old_buffer(req, arg2);
868 error = SYSCTL_OUT(req, arg1, arg2);
869 } else {
870 tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
870 tmparg = malloc(arg2, M_SYSCTLTMP, 0);
871 bcopy(arg1, tmparg, arg2);
872 error = SYSCTL_OUT(req, tmparg, arg2);
873 free(tmparg, M_SYSCTLTMP);
874 }
875
876 if (error || !req->newptr)
877 return (error);
878

--- 613 unchanged lines hidden ---
871 bcopy(arg1, tmparg, arg2);
872 error = SYSCTL_OUT(req, tmparg, arg2);
873 free(tmparg, M_SYSCTLTMP);
874 }
875
876 if (error || !req->newptr)
877 return (error);
878

--- 613 unchanged lines hidden ---