NetBSD Problem Report #33102

From yamt@mwd.biglobe.ne.jp  Sun Mar 19 08:24:11 2006
Return-Path: <yamt@mwd.biglobe.ne.jp>
Received: from yamt.dyndns.org (FLA1Abg085.kng.mesh.ad.jp [219.107.209.85])
	by narn.netbsd.org (Postfix) with ESMTP id 1BC4063B8F3
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 19 Mar 2006 08:24:09 +0000 (UTC)
Message-Id: <1142756619.259837.14021.nullmailer@yamt.dyndns.org>
Date: Sun, 19 Mar 2006 17:23:39 +0900
From: yamt@mwd.biglobe.ne.jp
Reply-To: yamt@mwd.biglobe.ne.jp
To: gnats-bugs@netbsd.org
Subject: sysctl(9) suggetions
X-Send-Pr-Version: 3.95

>Number:         33102
>Category:       kern
>Synopsis:       sysctl(9) suggestions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 19 08:25:00 +0000 2006
>Originator:     YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
>Release:        NetBSD 3.99.16
>Organization:

>Environment:


System: NetBSD kaeru 3.99.16 NetBSD 3.99.16 (build.kaeru.xen.nodebug.work) #7: Mon Mar 13 18:41:29 JST 2006 takashi@kaeru:/usr/home/takashi/work/kernel/build.kaeru.xen.nodebug.work i386
Architecture: i386
Machine: i386
>Description:

i have some suggestions related to sysctl helper functions.

1. SYSCTLFN_PROTO/SYSCTLFN_ARGS/SYSCTLFN_CALL are horrible, IMO.
   a structure should be used instead.

   ie.
	typedef struct __sysctlrequest *sysctlrequest_t;
	int sysctl_lookup(sysctlrequest_t);

2. it's better to make sysctl_lookup take a pointer to specify
   where new data is copied in, rather than having a local copy of
   whole "node".

3. abusing const qualifier is a bad idea.
   assuming it's to prevent helper functions from modifying "node", (right?)
   a better way would be hiding the structure definition from
   helper functions, and provide limited accessor functions if
   necessary.  (i think it's possible after the above #2.)

(4. sysctl_lookup is badly named, and confusing with sysctl_locate. :-)


to summarize, an example sysctl helper in sysctl(9) would be:

	static int
	sysctl_helper(sysctlrequest_t req)
	{
		sysctlnode_t node;
		int newvalue;
		int error;

		error = sysctl_lookup(req, &newvalue);
		if (error || !sysctlrequest_modify_p(req)) {
			return error;
		}

		if (newvalue < 0 || newvalue > 20) {
			return EINVAL;
		}

		node = sysctlrequest_node(req);
		sysctlnode_setexternaldata(node, &newvalue);
		return 0;
	}

(sysctlnode_t is a pointer, rather than a structure itself.)

>How-To-Repeat:

>Fix:


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.