Date: Sun, 9 Sep 2007 18:00:36 GMT From: "Constantine A. Murenin" <cnst@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 126230 for review Message-ID: <200709091800.l89I0aM5060616@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/queue.h> +#ifndef NOSYSCTL8HACK + #include <sys/sysctl.h> +#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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709091800.l89I0aM5060616>