From owner-p4-projects@FreeBSD.ORG Sun Sep 9 18:00:37 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C527416A46C; Sun, 9 Sep 2007 18:00:36 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 82C8716A468 for ; Sun, 9 Sep 2007 18:00:36 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 639CB13C461 for ; Sun, 9 Sep 2007 18:00:36 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l89I0aWm060619 for ; Sun, 9 Sep 2007 18:00:36 GMT (envelope-from cnst@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l89I0aM5060616 for perforce@freebsd.org; Sun, 9 Sep 2007 18:00:36 GMT (envelope-from cnst@FreeBSD.org) Date: Sun, 9 Sep 2007 18:00:36 GMT Message-Id: <200709091800.l89I0aM5060616@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cnst@FreeBSD.org using -f From: "Constantine A. Murenin" To: Perforce Change Reviews Cc: Subject: PERFORCE change 126230 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Sep 2007 18:00:37 -0000 http://perforce.freebsd.org/chv.cgi?CH=126230 Change 126230 by cnst@dale on 2007/09/09 18:00:16 put in a hack for supporting "Sysctl internal magic", and now hw.sensors tree magically works in sysctl(8)! dale# sysctl hw.sensors.{lm0.volt{0,1,2,3},cpu{0,1}} hw.sensors.lm0.volt0: 1.23 VDC (VCore) hw.sensors.lm0.volt1: 12.30 VDC (+12V) hw.sensors.lm0.volt2: 3.33 VDC (+3.3V) hw.sensors.lm0.volt3: 3.31 VDC (+3.3V) hw.sensors.cpu0.temp0: 28.00 degC hw.sensors.cpu1.temp0: 28.00 degC dale# (All other utilities continue working using a cross-platform sysctl(3) interface, compatible with OpenBSD.) Affected files ... .. //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#13 edit .. //depot/projects/soc2007/cnst-sensors/sys.sys/sensors.h#4 edit Differences ... ==== //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#13 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $P4: //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#12 $ */ +/* $P4: //depot/projects/soc2007/cnst-sensors/sys.kern/kern_sensors.c#13 $ */ /* $FreeBSD$ */ /* $OpenBSD: kern_sensors.c,v 1.19 2007/06/04 18:42:05 deraadt Exp $ */ /* $OpenBSD: kern_sysctl.c,v 1.154 2007/06/01 17:29:10 beck Exp $ */ @@ -58,6 +58,11 @@ TAILQ_HEAD(, sensor_task) tasklist = TAILQ_HEAD_INITIALIZER(tasklist); +#ifndef NOSYSCTL8HACK +void sensor_sysctl8magic_install(struct ksensordev *); +void sensor_sysctl8magic_deinstall(struct ksensordev *); +#endif + void sensordev_install(struct ksensordev *sensdev) { @@ -77,6 +82,10 @@ } sensordev_count++; mtx_unlock(&Giant); + +#ifndef NOSYSCTL8HACK + sensor_sysctl8magic_install(sensdev); +#endif } void @@ -122,6 +131,10 @@ sensordev_count--; SLIST_REMOVE(&sensordev_list, sensdev, ksensordev, list); mtx_unlock(&Giant); + +#ifndef NOSYSCTL8HACK + sensor_sysctl8magic_deinstall(sensdev); +#endif } void @@ -270,9 +283,66 @@ int sysctl_handle_sensor(SYSCTL_HANDLER_ARGS); int sysctl_sensors_handler(SYSCTL_HANDLER_ARGS); + +#ifndef NOSYSCTL8HACK + +SYSCTL_NODE(_hw, OID_AUTO, sensors, CTLFLAG_RD, NULL, + "Hardware Sensors sysctl internal magic"); +SYSCTL_NODE(_hw, HW_SENSORS, _sensors, CTLFLAG_RD, sysctl_sensors_handler, + "Hardware Sensors XP MIB interface"); + +#else /* NOSYSCTL8HACK */ + SYSCTL_NODE(_hw, HW_SENSORS, sensors, CTLFLAG_RD, sysctl_sensors_handler, "Hardware Sensors"); +#endif /* !NOSYSCTL8HACK */ + + +#ifndef NOSYSCTL8HACK + +/* + * XXX: + * FreeBSD's sysctl(9) .oid_handler functionality is not accustomed + * for the CTLTYPE_NODE handler to handle the undocumented sysctl + * magic calls. As soon as such functionality is developed, + * sysctl_sensors_handler() should be converted to handle all such + * calls, and these sysctl_add_oid(9) calls should be removed + * "with a big axe". This whole sysctl_add_oid(9) business is solely + * to please sysctl(8). + */ + +void +sensor_sysctl8magic_install(struct ksensordev *sensdev) +{ + struct sysctl_oid_list *ol; + struct sysctl_ctx_list *cl = &sensdev->clist; + struct ksensor *s; + struct ksensors_head *sh = &sensdev->sensors_list; + + sysctl_ctx_init(cl); + ol = SYSCTL_CHILDREN(SYSCTL_ADD_NODE(cl, &SYSCTL_NODE_CHILDREN(_hw, + sensors), sensdev->num, sensdev->xname, CTLFLAG_RD, NULL, "")); + SLIST_FOREACH(s, sh, list) { + char n[32]; + + snprintf(n, sizeof(n), "%s%d", sensor_type_s[s->type], s->numt); + SYSCTL_ADD_PROC(cl, ol, OID_AUTO, n, CTLTYPE_STRUCT | + CTLFLAG_RD, s, 0, sysctl_handle_sensor, "S,sensor", ""); + } +} + +void +sensor_sysctl8magic_deinstall(struct ksensordev *sensdev) +{ + struct sysctl_ctx_list *cl = &sensdev->clist; + + sysctl_ctx_free(cl); +} + +#endif /* !NOSYSCTL8HACK */ + + int sysctl_handle_sensordev(SYSCTL_HANDLER_ARGS) { ==== //depot/projects/soc2007/cnst-sensors/sys.sys/sensors.h#4 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $P4: //depot/projects/soc2007/cnst-sensors/sys.sys/sensors.h#3 $ */ +/* $P4: //depot/projects/soc2007/cnst-sensors/sys.sys/sensors.h#4 $ */ /* $FreeBSD$ */ /* $OpenBSD: sensors.h,v 1.23 2007/03/22 16:55:31 deraadt Exp $ */ @@ -53,7 +53,6 @@ SENSOR_MAX_TYPES }; -#ifndef _KERNEL static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = { "temp", "fan", @@ -72,7 +71,6 @@ "timedelta", "undefined" }; -#endif /* !_KERNEL */ #define SENSOR_DRIVE_EMPTY 1 #define SENSOR_DRIVE_READY 2 @@ -123,6 +121,9 @@ #ifdef _KERNEL #include +#ifndef NOSYSCTL8HACK + #include +#endif /* Sensor data */ struct ksensor { @@ -145,6 +146,12 @@ int maxnumt[SENSOR_MAX_TYPES]; int sensors_count; struct ksensors_head sensors_list; +#ifndef NOSYSCTL8HACK + struct sysctl_ctx_list clist; /* XXX: sysctl(9) .oid_handler() for + * CTLTYPE_NODE type doesn't support + * the undocumented sysctl magic. + */ +#endif /* !NOSYSCTL8HACK */ }; /* struct ksensordev */