Dear ports@,
The patch below should convert symon to the new sensors API that is now
present in OpenBSD.
Apart from the patch that is attached below, it may also be desirable to
increase the size of the symon's buffer that is used for holding
module's argument, e.g. "wd0", "httpd" or "ipmi0.indicator0". This can
be done by increasing the lib/sylimits.h::SYMON_PS_ARGLEN constant from
16 to, say, 32 (15 characters for sensor device name, 11 for the longest
possible sensor type ATM -- 'illuminance', at least 1 for numt etc).
This change of buffer size is not mandatory, and moreover, would make
your version of symon incompatible with non-modified versions of the
package.
Happy monitoring! :)
Cheers,
Constantine.
diff -ru8dp symon-2.73/platform/OpenBSD/conf.sh
symon-2.73.cnst/platform/OpenBSD/conf.sh
--- symon-2.73/platform/OpenBSD/conf.sh Mon Oct 30 08:32:49 2006
+++ symon-2.73.cnst/platform/OpenBSD/conf.sh Tue Jan 2 22:17:35 2007
@@ -1,19 +1,19 @@
case `grep -csq KERN_MBSTAT /usr/include/sys/sysctl.h` in
1) echo "#define HAS_KERN_MBSTAT 1" ;;
0) echo "#undef HAS_KERN_MBSTAT" ;;
esac;
case `grep -csq KERN_CPTIME2 /usr/include/sys/sysctl.h` in
1) echo "#define HAS_KERN_CPTIME2 1" ;;
0) echo "#undef HAS_KERN_CPTIME2" ;;
esac;
-case `grep -csq "struct sensor" /usr/include/sys/sensors.h` in
-1) echo "#define HAS_SENSORS_H 1" ;;
-0) echo "#undef HAS_SENSORS_H" ;;
+case `grep -csq "struct sensordev" /usr/include/sys/sensors.h` in
+1) echo "#define HAS_SENSORDEV 1" ;;
+0) echo "#undef HAS_SENSORDEV" ;;
esac;
case `grep -csq "ds_rxfer" /usr/include/sys/disk.h` in
1) echo "#define HAS_IO2 1" ;;
0) echo "#undef HAS_IO2" ;;
esac;
if [ -f /usr/include/net/pfvar.h ]; then
echo "#define HAS_PFVAR_H 1"
else
diff -ru8dp symon-2.73/platform/OpenBSD/platform.h
symon-2.73.cnst/platform/OpenBSD/platform.h
--- symon-2.73/platform/OpenBSD/platform.h Mon Oct 30 08:32:49 2006
+++ symon-2.73.cnst/platform/OpenBSD/platform.h Tue Jan 2 22:08:22 2007
@@ -3,16 +3,17 @@
#ifndef _CONF_OPENBSD_H
#define _CONF_OPENBSD_H
#include "conf.h"
#include <sys/dkstat.h>
#include <sys/queue.h>
#include <sys/types.h>
+#include <sys/sensors.h>
#include <sys/socket.h>
#include <net/if.h>
#include "sylimits.h"
#define SYMON_USER "_symon"
#define SEM_ARGS (SEM_A|SEM_R)
#define SA_LEN(x) ((x)->sa_len)
@@ -34,12 +35,18 @@ union stream_parg {
long diff[CPUSTATES];
int states[CPUSTATES];
} cp;
#endif
struct {
char rawdev[SYMON_DFNAMESIZE];
} df;
struct ifreq ifr;
- int sn;
+ struct {
+#ifndef HAS_SENSORDEV
+ int mib[3];
+#else
+ int mib[5];
+#endif
+ } sn;
};
#endif
diff -ru8dp symon-2.73/platform/OpenBSD/sm_sensor.c
symon-2.73.cnst/platform/OpenBSD/sm_sensor.c
--- symon-2.73/platform/OpenBSD/sm_sensor.c Tue Oct 18 20:58:11 2005
+++ symon-2.73.cnst/platform/OpenBSD/sm_sensor.c Thu Jan 18 17:06:38 2007
@@ -1,12 +1,13 @@
/* $Id: sm_sensor.c,v 1.7 2005/10/18 19:58:11 dijkstra Exp $ */
/*
* Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2006/2007 Constantine A. Murenin <[EMAIL PROTECTED]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
@@ -35,94 +36,146 @@
*
* num : value
*
*/
#include "conf.h"
#include <sys/param.h>
+#include <sys/sensors.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "error.h"
#include "symon.h"
-#ifndef HAS_SENSORS_H
-void
-privinit_sensor()
-{
- fatal("sensor support not available");
-}
-void
-init_sensor(struct stream *st)
-{
- fatal("sensor support not available");
-}
-int
-get_sensor(char *symon_buf, int maxlen, struct stream *st)
-{
- fatal("sensor support not available");
- return 0;
-}
-
-#else
-
-#include <sys/sensors.h>
-
/* Globals for this module start with sn_ */
-static int sn_mib[] = {CTL_HW, HW_SENSORS, 0};
static struct sensor sn_sensor;
void
privinit_sensor()
{
/* EMPTY */
}
void
init_sensor(struct stream *st)
{
+#ifndef HAS_SENSORDEV
+
long l = strtol(st->arg, NULL, 10);
- st->parg.sn = (int) (l & SYMON_SENSORMASK);
+ st->parg.sn.mib[0] = CTL_HW;
+ st->parg.sn.mib[1] = HW_SENSORS;
+ st->parg.sn.mib[2] = (int) (l & SYMON_SENSORMASK);
- info("started module sensors(%.200s)", st->arg);
+#else /* HAS_SENSORDEV */
+
+ char *devname, *typename, *bufp, *bufpo;
+ int dev, numt, i;
+ enum sensor_type type;
+ struct sensordev sensordev;
+ size_t sdlen = sizeof(sensordev);
+
+ st->parg.sn.mib[0] = CTL_HW;
+ st->parg.sn.mib[1] = HW_SENSORS;
+
+ bufpo = strdup(st->arg);
+ if (bufpo == NULL)
+ fatal("%s:%d: sensor(%.200s): out of memory",
+ __FILE__, __LINE__, st->arg);
+ bufp = bufpo;
+
+ if ((devname = strsep(&bufp, ".")) == NULL)
+ fatal("%s:%d: sensor(%.200s): incomplete specification",
+ __FILE__, __LINE__, st->arg);
+
+ /* convert sensor device string to an integer */
+ for (dev = 0; dev < MAXSENSORDEVICES; dev++) {
+ st->parg.sn.mib[2] = dev;
+ if (sysctl(st->parg.sn.mib, 3, &sensordev, &sdlen, NULL, 0) == -1)
+ continue;
+ if (strcmp(devname, sensordev.xname) == 0)
+ break;
+ }
+ if (strcmp(devname, sensordev.xname) != 0)
+ fatal("sensor(%.200s): device not found: %.200s",
+ st->arg, devname);
+
+ /* convert sensor_type string to an integer */
+ if ((typename = strsep(&bufp, ".")) == NULL)
+ fatal("%s:%d: sensor(%.200s): incomplete specification",
+ __FILE__, __LINE__, st->arg);
+ numt = -1;
+ for (i = 0; typename[i] != '\0'; i++)
+ if (isdigit(typename[i])) {
+ numt = atoi(&typename[i]);
+ typename[i] = '\0';
+ break;
+ }
+ for (type = 0; type < SENSOR_MAX_TYPES; type++)
+ if (strcmp(typename, sensor_type_s[type]) == 0)
+ break;
+ if (type == SENSOR_MAX_TYPES)
+ fatal("sensor(%.200s): sensor type not recognised: %.200s",
+ st->arg, typename);
+ if (sensordev.maxnumt[type] == 0)
+ fatal("sensor(%.200s): no sensors of such type on this device: %.200s",
+ st->arg, typename);
+ st->parg.sn.mib[3] = type;
+
+ if (numt == -1) {
+ warning("sensor(%.200s): sensor number not specified, using 0",
+ st->arg);
+ numt = 0;
+ }
+ if (!(numt < sensordev.maxnumt[type]))
+ fatal("sensor(%.200s): no such sensor attached to this device:
%.200s%i",
+ st->arg, typename, numt);
+ st->parg.sn.mib[4] = numt;
+
+ free(bufpo);
+
+#endif /* !HAS_SENSORDEV */
+
+ info("started module sensor(%.200s)", st->arg);
}
int
get_sensor(char *symon_buf, int maxlen, struct stream *st)
{
- size_t len;
+ size_t len = sizeof(sn_sensor);
double t;
- bzero((void *) &sn_sensor, sizeof(sn_sensor));
- sn_mib[2] = st->parg.sn;
+ if (sysctl(st->parg.sn.mib,
+ sizeof(st->parg.sn.mib)/sizeof(st->parg.sn.mib[0]),
+ &sn_sensor, &len, NULL, 0) == -1) {
+ if (errno != ENOENT)
+ warning("%s:%d: sensor(%.200s): sysctl error: %.200s",
+ __FILE__, __LINE__, st->arg, strerror(errno));
+ else
+ warning("sensor(%.200s): sensor not found",
+ st->arg);
- len = sizeof(sn_sensor);
-
- if (sysctl(sn_mib, 3, &sn_sensor, &len, NULL, 0) == -1) {
- warning("%s:%d: sensor can't get sensor %.200s -- %.200s",
- __FILE__, __LINE__, st->arg, strerror(errno));
-
return 0;
} else {
switch (sn_sensor.type) {
case SENSOR_TEMP:
- t = (double) (sn_sensor.value / 1000.0 / 1000.0) - 273.16;
+ t = (double) (sn_sensor.value / 1000.0 / 1000.0) - 273.15;
break;
case SENSOR_FANRPM:
t = (double) sn_sensor.value;
break;
case SENSOR_VOLTS_DC:
t = (double) (sn_sensor.value / 1000.0 / 1000.0);
break;
default:
t = (double) sn_sensor.value;
}
return snpack(symon_buf, maxlen, st->arg, MT_SENSOR, t);
}
}
-#endif /* HAS_SENSORS_H */