sensorsd patch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

sensorsd patch

Nicholas Marriott
Hi,

Patch to allow you to use sensor device/desc, eg lm0.+5V, rather than
hw.sensors.* in sensorsd.conf. Works for me but I can't help thinking
there must be a reason it wasn't done originally...

-- Nicholas.

Index: sensorsd.c
===================================================================
RCS file: /cvs/src/usr.sbin/sensorsd/sensorsd.c,v
retrieving revision 1.20
diff -u -r1.20 sensorsd.c
--- sensorsd.c 6 Feb 2006 21:32:20 -0000 1.20
+++ sensorsd.c 8 Mar 2006 14:02:36 -0000
@@ -54,6 +54,7 @@
  u_int8_t watch;
  int num; /* sensor number */
  enum sensor_type type; /* sensor type */
+ char        name[52];     /* sensor name */
  int64_t lower; /* lower limit */
  int64_t upper; /* upper limit */
  char *command; /* failure command */
@@ -81,6 +82,7 @@
  {
  struct sensor sensor;
  struct limits_t *limit;
+ char *cp;
  size_t len;
  time_t next_report, last_report = 0, next_check;
  int mib[3], i, sleeptime, sensor_cnt, watch_cnt, ch;
@@ -113,6 +115,11 @@
  err(1, "calloc");
  limit->num = i;
  limit->type = sensor.type;
+ snprintf(limit->name, sizeof(limit->name), "%s.%s",
+    sensor.device, sensor.desc);
+ cp = limit->name;
+ while ((cp = strchr(cp, ' ')) != NULL)
+ *cp = '_';
  TAILQ_INSERT_TAIL(&limits, limit, entries);
  sensor_cnt++;
  }
@@ -231,8 +238,8 @@
  if (limit->status_changed <= last_report)
  continue;

- syslog(LOG_ALERT, "hw.sensors.%d: %s limits, value: %s",
-    limit->num,
+ syslog(LOG_ALERT, "hw.sensors.%d/%s: %s limits, value: %s",
+    limit->num, limit->name,
     (limit->status == STATUS_FAIL) ? "exceed" : "within",
     print_sensor(limit->type, limit->last_val));
  if (limit->command) {
@@ -346,7 +353,8 @@
  for (p = TAILQ_FIRST(&limits); p != NULL; p = next) {
  next = TAILQ_NEXT(p, entries);
  snprintf(node, sizeof(node), "hw.sensors.%d", p->num);
- if (cgetent(&buf, cfa, node) != 0)
+ if (cgetent(&buf, cfa, node) != 0 &&
+    cgetent(&buf, cfa, p->name) != 0)
  p->watch = 0;
  else {
  p->watch = 1;
Index: sensorsd.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/sensorsd/sensorsd.conf.5,v
retrieving revision 1.5
diff -u -r1.5 sensorsd.conf.5
--- sensorsd.conf.5 7 Mar 2006 11:14:02 -0000 1.5
+++ sensorsd.conf.5 8 Mar 2006 14:02:36 -0000
@@ -35,6 +35,15 @@
  alert functionality is triggered and a command, if specified, is
  executed.
  .Pp
+Sensors may be specified either using the MIB name output from
+.Xr sysctl 8
+or using the sensor device name and sensor description, separated by a period. For example, the sensor,
+.Bd -ragged -offset indent
+hw.sensors.0=lm0, VCore, volts_dc, 1.66 V
+.Ed
+.Pp
+can be referenced as either hw.sensors.0 or lm0.VCore. The sensor name is case-sensitive and any spaces should be replaced by underscores (_).
+.Pp
  .Nm
  follows the syntax of configuration databases as documented in
  .Xr getcap 3 .