Browse Source

Add ./tarball_archive/symon-2.74.tar.gz

Wictor Lund 3 years ago
parent
commit
0b6e06ee0e
73 changed files with 3534 additions and 2808 deletions
  1. 16 1
      symon/CHANGELOG
  2. 2 2
      symon/Makefile.inc
  3. 4 1
      symon/TODO
  4. 6 6
      symon/client/SymuxClient.pm
  5. 353 303
      symon/lib/data.c
  6. 152 144
      symon/lib/data.h
  7. 13 13
      symon/lib/error.c
  8. 2 2
      symon/lib/error.h
  9. 97 96
      symon/lib/lex.c
  10. 41 40
      symon/lib/lex.h
  11. 65 64
      symon/lib/net.c
  12. 4 4
      symon/lib/net.h
  13. 5 4
      symon/lib/sylimits.h
  14. 9 9
      symon/lib/xmalloc.c
  15. 2 2
      symon/lib/xmalloc.h
  16. 6 6
      symon/platform/FreeBSD/platform.h
  17. 19 19
      symon/platform/FreeBSD/sm_cpu.c
  18. 6 6
      symon/platform/FreeBSD/sm_debug.c
  19. 14 14
      symon/platform/FreeBSD/sm_df.c
  20. 24 24
      symon/platform/FreeBSD/sm_if.c
  21. 22 22
      symon/platform/FreeBSD/sm_io.c
  22. 51 51
      symon/platform/FreeBSD/sm_mbuf.c
  23. 20 20
      symon/platform/FreeBSD/sm_mem.c
  24. 33 33
      symon/platform/FreeBSD/sm_pf.c
  25. 69 69
      symon/platform/FreeBSD/sm_pfq.c
  26. 62 62
      symon/platform/FreeBSD/sm_proc.c
  27. 7 7
      symon/platform/Linux/platform.h
  28. 286 286
      symon/platform/Linux/queue.h
  29. 40 40
      symon/platform/Linux/sm_cpu.c
  30. 34 34
      symon/platform/Linux/sm_if.c
  31. 37 37
      symon/platform/Linux/sm_io.c
  32. 21 21
      symon/platform/Linux/sm_mem.c
  33. 7 7
      symon/platform/NetBSD/platform.h
  34. 16 16
      symon/platform/NetBSD/sm_cpu.c
  35. 6 6
      symon/platform/NetBSD/sm_debug.c
  36. 16 15
      symon/platform/NetBSD/sm_df.c
  37. 17 17
      symon/platform/NetBSD/sm_if.c
  38. 19 19
      symon/platform/NetBSD/sm_io.c
  39. 49 49
      symon/platform/NetBSD/sm_mbuf.c
  40. 140 0
      symon/platform/NetBSD/sm_mem.c
  41. 161 0
      symon/platform/NetBSD/sm_pf.c
  42. 240 0
      symon/platform/NetBSD/sm_pfq.c
  43. 37 37
      symon/platform/NetBSD/sm_proc.c
  44. 30 30
      symon/platform/NetBSD/sm_sensor.c
  45. 4 0
      symon/platform/OpenBSD/conf.sh
  46. 9 2
      symon/platform/OpenBSD/platform.h
  47. 38 38
      symon/platform/OpenBSD/sm_cpu.c
  48. 6 6
      symon/platform/OpenBSD/sm_debug.c
  49. 14 14
      symon/platform/OpenBSD/sm_df.c
  50. 17 17
      symon/platform/OpenBSD/sm_if.c
  51. 43 43
      symon/platform/OpenBSD/sm_io.c
  52. 49 49
      symon/platform/OpenBSD/sm_mbuf.c
  53. 23 23
      symon/platform/OpenBSD/sm_mem.c
  54. 33 33
      symon/platform/OpenBSD/sm_pf.c
  55. 69 69
      symon/platform/OpenBSD/sm_pfq.c
  56. 37 37
      symon/platform/OpenBSD/sm_proc.c
  57. 109 34
      symon/platform/OpenBSD/sm_sensor.c
  58. 122 111
      symon/symon/readconf.c
  59. 2 2
      symon/symon/readconf.h
  60. 6 6
      symon/symon/symon.8
  61. 106 106
      symon/symon/symon.c
  62. 3 3
      symon/symon/symon.h
  63. 16 16
      symon/symon/symonnet.c
  64. 2 2
      symon/symon/symonnet.h
  65. 284 284
      symon/symux/readconf.c
  66. 2 2
      symon/symux/readconf.h
  67. 100 100
      symon/symux/share.c
  68. 3 3
      symon/symux/share.h
  69. 24 24
      symon/symux/symux.8
  70. 10 3
      symon/symux/symux.c
  71. 2 2
      symon/symux/symux.h
  72. 139 139
      symon/symux/symuxnet.c
  73. 2 2
      symon/symux/symuxnet.h

+ 16 - 1
symon/CHANGELOG

@@ -1,4 +1,19 @@
+11/02/2007 - 2.74
+
+   - symon can be told what local interface to send data from (Henning Brauer)
+
+   - removed typos in client/SymuxClient.pm (Sandeep Kr Sangwan)
+
+   - OpenBSD sm_sensor upgrade to sensor_dev (Constantine A. Murenin)
+
+   - NetBSD can use OpenBSD sm_pf, sm_mem and sm_pfq with little modifications
+     (Jean-Yves Moulin)
+
+   - symon network protocol version bumped to allow stream arguments upto 63
+     characters.
+
 19/12/2006 - 2.73
+
    - symux stops reporting rrd errors after 5 messages to counter logspam
      (Henning Brauer)
 
@@ -460,4 +475,4 @@
 29/09/2001 - Lexer had trouble dealing with ip-addresses. Cleaned up the number
              parsing code and removed a second comment reader.
 
-$Id: CHANGELOG,v 1.55 2006/12/19 22:31:38 dijkstra Exp $
+$Id: CHANGELOG,v 1.58 2007/02/11 20:12:15 dijkstra Exp $

+ 2 - 2
symon/Makefile.inc

@@ -1,6 +1,6 @@
-# $Id: Makefile.inc,v 1.33 2006/06/30 08:23:42 dijkstra Exp $
+# $Id: Makefile.inc,v 1.34 2007/02/11 20:07:31 dijkstra Exp $
 
-V=2.73
+V=2.74
 OS!=uname -s
 
 AR?=	ar

+ 4 - 1
symon/TODO

@@ -1,6 +1,9 @@
 TODO:
 
 == current problems / short term
+   - symux queues rrd values for a particular time. Cheers to Jean-Gérard
+     Pailloncy for the suggestion.
+
 - rewrite sm_proc.c, don't count shared pages twice
 - remove mon packet limit
 - check shared memory for hackable bugs. (master should only write, clients
@@ -11,4 +14,4 @@ TODO:
 - write a muxer that supports unix pipes
 - test framework
 
-$Id: TODO,v 1.27 2004/08/07 12:21:36 dijkstra Exp $
+$Id: TODO,v 1.28 2007/02/11 20:07:31 dijkstra Exp $

+ 6 - 6
symon/client/SymuxClient.pm

@@ -1,6 +1,6 @@
-# $Id: SymuxClient.pm,v 1.11 2005/10/16 15:26:50 dijkstra Exp $
+# $Id: SymuxClient.pm,v 1.13 2007/02/11 20:07:31 dijkstra Exp $
 #
-# Copyright (c) 2001-2005 Willem Dijkstra
+# Copyright (c) 2001-2007 Willem Dijkstra
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -67,7 +67,7 @@ my $streamitem =
      io     => {total_rxfers => 1, total_wxfers => 2, total_seeks => 3,
 		total_rbytes => 4, total_rbytes => 5 },
      pfq    => {sent_bytes => 1, sent_packets => 2, drop_bytes => 3,
-		drop_packets => 4}
+		drop_packets => 4},
      df     => {blocks => 1, bfree => 2, bavail => 3, files => 4, ffree => 5,
 		syncwrites => 6, asyncwrites => 7}};
 sub new {
@@ -149,7 +149,7 @@ sub parse {
 
     @streams = split(/;/, $self->{rawdata});
     croak "error: expected a symux dataline with ';' delimited streams"
-	if ($#streams < 2);
+	if ($#streams < 1);
 
     $self->{datasource} = shift @streams;
 
@@ -157,7 +157,7 @@ sub parse {
 	($name, $arg, @data) = split(':', $stream);
 
 	croak "error: expected a symux stream with ':' delimited values"
-	    if ($#data < 2);
+	    if ($#data < 1);
 
 	$name .= '('.$arg.')' if ($arg ne '');
 
@@ -252,7 +252,7 @@ and data it receives from that connection. Arguments are:
 Arguments marked with * are optional.
 
 Example:
-    $sc = new SymuxClient(host => 127.0.0.1,
+    $sc = new SymuxClient(host => '127.0.0.1',
 			  port => 2100);
 
 =back

+ 353 - 303
symon/lib/data.c

@@ -1,4 +1,4 @@
-/* $Id: data.c,v 1.29 2006/06/28 06:44:45 dijkstra Exp $ */
+/* $Id: data.c,v 1.31 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -142,11 +142,11 @@ token2type(const int token)
     int i;
 
     for (i = 0; streamtoken[i].type < MT_EOT; i++)
-	if (streamtoken[i].token == token)
-	    return streamtoken[i].type;
+        if (streamtoken[i].token == token)
+            return streamtoken[i].type;
 
     fatal("%s:%d: internal error: token (%d) could not be translated into a stream type",
-	  __FILE__, __LINE__, token);
+          __FILE__, __LINE__, token);
 
     /* NOT REACHED */
     return 0;
@@ -158,11 +158,11 @@ type2str(const int streamtype)
     int i;
 
     for (i = 0; streamtoken[i].type < MT_EOT; i++)
-	if (streamtoken[i].type == streamtype)
-	    return parse_opcode(streamtoken[i].token);
+        if (streamtoken[i].type == streamtype)
+            return parse_opcode(streamtoken[i].token);
 
     fatal("%s:%d: internal error: type (%d) could not be translated into ascii representation",
-	  __FILE__, __LINE__, streamtype);
+          __FILE__, __LINE__, streamtype);
 
     /* NOT REACHED */
     return 0;
@@ -175,7 +175,7 @@ strlentype(int type)
     int sum = 0;
 
     while (streamform[type].form[i])
-	sum += strlenvar(streamform[type].form[i++]);
+        sum += strlenvar(streamform[type].form[i++]);
 
     return sum;
 }
@@ -186,11 +186,11 @@ strlenvar(char var)
     int i;
 
     for (i = 0; streamvar[i].type > '\0'; i++)
-	if (streamvar[i].type == var)
-	    return streamvar[i].strlen;
+        if (streamvar[i].type == var)
+            return streamvar[i].strlen;
 
     fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
-	  __FILE__, __LINE__, var);
+          __FILE__, __LINE__, var);
 
     /* NOT REACHED */
     return 0;
@@ -202,11 +202,11 @@ bytelenvar(char var)
     int i;
 
     for (i = 0; streamvar[i].type > '\0'; i++)
-	if (streamvar[i].type == var)
-	    return streamvar[i].bytelen;
+        if (streamvar[i].type == var)
+            return streamvar[i].bytelen;
 
     fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
-	  __FILE__, __LINE__, var);
+          __FILE__, __LINE__, var);
 
     /* NOT REACHED */
     return 0;
@@ -218,11 +218,11 @@ formatstrvar(char var)
     int i;
 
     for (i = 0; streamvar[i].type > '\0'; i++)
-	if (streamvar[i].type == var)
-	    return streamvar[i].strformat;
+        if (streamvar[i].type == var)
+            return streamvar[i].strformat;
 
     fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
-	  __FILE__, __LINE__, var);
+          __FILE__, __LINE__, var);
 
     /* NOT REACHED */
     return "";
@@ -234,8 +234,8 @@ rrdstrvar(char var)
     int i;
 
     for (i = 0; streamvar[i].type > '\0'; i++)
-	if (streamvar[i].type == var)
-	    return streamvar[i].rrdformat;
+        if (streamvar[i].type == var)
+            return streamvar[i].rrdformat;
 
     fatal("internal error: type spefication for stream var '%c' not found", var);
 
@@ -247,11 +247,11 @@ int
 checklen(int maxlen, int current, int extra)
 {
     if ((current + extra) < maxlen) {
-	return 0;
+        return 0;
     } else {
-	warning("buffer overflow: max=%d, current=%d, extra=%d",
-		maxlen, current, extra);
-	return 1;
+        warning("buffer overflow: max=%d, current=%d, extra=%d",
+                maxlen, current, extra);
+        return 1;
     }
 }
 int
@@ -307,7 +307,43 @@ getheader(char *buf, struct symonpacketheader *hph)
 int
 snpack(char *buf, int maxlen, char *id, int type,...)
 {
+    int result;
     va_list ap;
+
+    /* default to v2 packets */
+    va_start(ap, type);
+    result = snpackx(SYMON_PS_ARGLENV2, buf, maxlen, id, type, ap);
+    va_end(ap);
+
+    return result;
+}
+int
+snpack1(char *buf, int maxlen, char *id, int type, ...)
+{
+    int result;
+    va_list ap;
+
+    va_start(ap, type);
+    result = snpackx(SYMON_PS_ARGLENV1, buf, maxlen, id, type, ap);
+    va_end(ap);
+
+    return result;
+}
+int
+snpack2(char *buf, int maxlen, char *id, int type, ...)
+{
+    int result;
+    va_list ap;
+
+    va_start(ap, type);
+    result = snpackx(SYMON_PS_ARGLENV2, buf, maxlen, id, type, ap);
+    va_end(ap);
+
+    return result;
+}
+int
+snpackx(size_t maxarglen, char *buf, int maxlen, char *id, int type, va_list ap)
+{
     u_int16_t b;
     u_int16_t s;
     u_int16_t c;
@@ -320,93 +356,91 @@ snpack(char *buf, int maxlen, char *id, int type,...)
     int arglen = 0;
 
     if (type > MT_EOT) {
-	warning("stream type (%d) out of range", type);
-	return 0;
+        warning("stream type (%d) out of range", type);
+        return 0;
     }
 
     if (maxlen < 2) {
-	fatal("%s:%d: maxlen too small", __FILE__, __LINE__);
+        fatal("%s:%d: maxlen too small", __FILE__, __LINE__);
     } else {
-	buf[offset++] = type & 0xff;
+        buf[offset++] = type & 0xff;
     }
 
     if (id) {
-	arglen = MIN(strlen(id), SYMON_PS_ARGLEN - 1);
+        arglen = MIN(strlen(id), SYMON_PS_ARGLENV2 - 1);
     } else {
-	id = "\0";
-	arglen = 1;
+        id = "\0";
+        arglen = 1;
     }
 
     if (checklen(maxlen, offset, arglen)) {
-	return offset;
+        return offset;
     } else {
-	strncpy(&buf[offset], id, arglen);
-	offset += arglen + 1;
+        strncpy(&buf[offset], id, arglen);
+        offset += arglen + 1;
     }
 
-    va_start(ap, type);
     while (streamform[type].form[i] != '\0') {
-	if (checklen(maxlen, offset, bytelenvar(streamform[type].form[i])))
-	    return offset;
-
-	/*
-	 * all values smaller than 32 bytes are transferred using ints on the
-	 * stack. This is to ensure that we get the correct value, if the
-	 * compiler decided to upgrade our short to a 32bit int. -- cheers
-	 * dhartmei@openbsd.org
-	 */
-	switch (streamform[type].form[i]) {
-	case 'b':
-	    b = va_arg(ap, int);
-	    buf[offset++] = b;
-	    break;
-
-	case 'c':
-	    D = va_arg(ap, double);
-	    c = (u_int16_t) (D * 100.0);
-	    c = htons(c);
-	    bcopy(&c, buf + offset, sizeof(u_int16_t));
-	    offset += sizeof(u_int16_t);
-	    break;
-
-	case 's':
-	    s = va_arg(ap, int);
-	    s = htons(s);
-	    bcopy(&s, buf + offset, sizeof(u_int16_t));
-	    offset += sizeof(u_int16_t);
-	    break;
-
-	case 'l':
-	    l = va_arg(ap, u_int32_t);
-	    l = htonl(l);
-	    bcopy(&l, buf + offset, sizeof(u_int32_t));
-	    offset += sizeof(u_int32_t);
-	    break;
-
-	case 'L':
-	    q = va_arg(ap, u_int64_t);
-	    q = htonq(q);
-	    bcopy(&q, buf + offset, sizeof(u_int64_t));
-	    offset += sizeof(u_int64_t);
-	    break;
-
-	case 'D':
-	    D = va_arg(ap, double);
-	    d = (int64_t) (D * 1000 * 1000);
-	    d = htonq(d);
-	    bcopy(&d, buf + offset, sizeof(int64_t));
-	    offset += sizeof(int64_t);
-	    break;
-
-	default:
-	    warning("unknown stream format identifier %c in type %d",
-		    streamform[type].form[i],
-		    type);
-	    return 0;
-	}
-	i++;
+        if (checklen(maxlen, offset, bytelenvar(streamform[type].form[i])))
+            return offset;
+
+        /*
+         * all values smaller than 32 bytes are transferred using ints on the
+         * stack. This is to ensure that we get the correct value, if the
+         * compiler decided to upgrade our short to a 32bit int. -- cheers
+         * dhartmei@openbsd.org
+         */
+        switch (streamform[type].form[i]) {
+        case 'b':
+            b = va_arg(ap, int);
+            buf[offset++] = b;
+            break;
+
+        case 'c':
+            D = va_arg(ap, double);
+            c = (u_int16_t) (D * 100.0);
+            c = htons(c);
+            bcopy(&c, buf + offset, sizeof(u_int16_t));
+            offset += sizeof(u_int16_t);
+            break;
+
+        case 's':
+            s = va_arg(ap, int);
+            s = htons(s);
+            bcopy(&s, buf + offset, sizeof(u_int16_t));
+            offset += sizeof(u_int16_t);
+            break;
+
+        case 'l':
+            l = va_arg(ap, u_int32_t);
+            l = htonl(l);
+            bcopy(&l, buf + offset, sizeof(u_int32_t));
+            offset += sizeof(u_int32_t);
+            break;
+
+        case 'L':
+            q = va_arg(ap, u_int64_t);
+            q = htonq(q);
+            bcopy(&q, buf + offset, sizeof(u_int64_t));
+            offset += sizeof(u_int64_t);
+            break;
+
+        case 'D':
+            D = va_arg(ap, double);
+            d = (int64_t) (D * 1000 * 1000);
+            d = htonq(d);
+            bcopy(&d, buf + offset, sizeof(int64_t));
+            offset += sizeof(int64_t);
+            break;
+
+        default:
+            warning("unknown stream format identifier %c in type %d",
+                    streamform[type].form[i],
+                    type);
+            return 0;
+        }
+        i++;
     }
-    va_end(ap);
 
     return offset;
 }
@@ -419,7 +453,23 @@ snpack(char *buf, int maxlen, char *id, int type,...)
  * description corresponds to the amount of bytes that will fit inside the
  * packedstream structure.  */
 int
-sunpack(char *buf, struct packedstream * ps)
+sunpack(char *buf, struct packedstream *ps)
+{
+    /* default to version 2 */
+    return sunpackx(SYMON_PS_ARGLENV2, buf, ps);
+}
+int
+sunpack1(char *buf, struct packedstream *ps)
+{
+    return sunpackx(SYMON_PS_ARGLENV1, buf, ps);
+}
+int
+sunpack2(char *buf, struct packedstream *ps)
+{
+    return sunpackx(SYMON_PS_ARGLENV2, buf, ps);
+}
+int
+sunpackx(size_t arglen, char *buf, struct packedstream *ps)
 {
     char *in, *out;
     int i = 0;
@@ -435,78 +485,78 @@ sunpack(char *buf, struct packedstream * ps)
     in = buf;
 
     if ((*in) > MT_EOT) {
-	warning("unpack failure: stream type (%d) out of range", (*in));
-	return -1;
+        warning("unpack failure: stream type (%d) out of range", (*in));
+        return -1;
     }
 
     type = ps->type = (*in);
     in++;
     if ((*in) != '\0') {
-	strncpy(ps->arg, in, sizeof(ps->arg));
-	ps->arg[sizeof(ps->arg) - 1] = '\0';
-	in += strlen(ps->arg) + 1;
+        strncpy(ps->arg, in, arglen);
+        ps->arg[arglen - 1] = '\0';
+        in += strlen(ps->arg) + 1;
     } else {
-	ps->arg[0] = '\0';
-	in++;
+        ps->arg[0] = '\0';
+        in++;
     }
 
     out = (char *) (&ps->data);
 
     while (streamform[type].form[i] != '\0') {
-	switch (streamform[type].form[i]) {
-	case 'b':
-	    bcopy((void *) in, (void *) out, sizeof(u_int8_t));
-	    in++;
-	    out++;
-	    break;
-
-	case 'c':
-	    bcopy((void *) in, &c, sizeof(u_int16_t));
-	    c = ntohs(c);
-	    bcopy(&c, (void *) out, sizeof(u_int16_t));
-	    in += sizeof(u_int16_t);
-	    out += sizeof(u_int16_t);
-	    break;
-
-	case 's':
-	    bcopy((void *) in, &s, sizeof(u_int16_t));
-	    s = ntohs(s);
-	    bcopy(&s, (void *) out, sizeof(u_int16_t));
-	    in += sizeof(u_int16_t);
-	    out += sizeof(u_int16_t);
-	    break;
-
-	case 'l':
-	    bcopy((void *) in, &l, sizeof(u_int32_t));
-	    l = ntohl(l);
-	    bcopy(&l, (void *) out, sizeof(u_int32_t));
-	    in += sizeof(u_int32_t);
-	    out += sizeof(u_int32_t);
-	    break;
-
-	case 'L':
-	    bcopy((void *) in, &q, sizeof(u_int64_t));
-	    q = ntohq(q);
-	    bcopy(&q, (void *) out, sizeof(u_int64_t));
-	    in += sizeof(u_int64_t);
-	    out += sizeof(u_int64_t);
-	    break;
-
-	case 'D':
-	    bcopy((void *) in, &d, sizeof(int64_t));
-	    d = ntohq(d);
-	    bcopy(&d, (void *) out, sizeof(int64_t));
-	    in += sizeof(int64_t);
-	    out += sizeof(int64_t);
-	    break;
-
-	default:
-	    warning("unknown stream format identifier %c in type %d",
-		    streamform[type].form[i],
-		    type);
-	    return 0;
-	}
-	i++;
+        switch (streamform[type].form[i]) {
+        case 'b':
+            bcopy((void *) in, (void *) out, sizeof(u_int8_t));
+            in++;
+            out++;
+            break;
+
+        case 'c':
+            bcopy((void *) in, &c, sizeof(u_int16_t));
+            c = ntohs(c);
+            bcopy(&c, (void *) out, sizeof(u_int16_t));
+            in += sizeof(u_int16_t);
+            out += sizeof(u_int16_t);
+            break;
+
+        case 's':
+            bcopy((void *) in, &s, sizeof(u_int16_t));
+            s = ntohs(s);
+            bcopy(&s, (void *) out, sizeof(u_int16_t));
+            in += sizeof(u_int16_t);
+            out += sizeof(u_int16_t);
+            break;
+
+        case 'l':
+            bcopy((void *) in, &l, sizeof(u_int32_t));
+            l = ntohl(l);
+            bcopy(&l, (void *) out, sizeof(u_int32_t));
+            in += sizeof(u_int32_t);
+            out += sizeof(u_int32_t);
+            break;
+
+        case 'L':
+            bcopy((void *) in, &q, sizeof(u_int64_t));
+            q = ntohq(q);
+            bcopy(&q, (void *) out, sizeof(u_int64_t));
+            in += sizeof(u_int64_t);
+            out += sizeof(u_int64_t);
+            break;
+
+        case 'D':
+            bcopy((void *) in, &d, sizeof(int64_t));
+            d = ntohq(d);
+            bcopy(&d, (void *) out, sizeof(int64_t));
+            in += sizeof(int64_t);
+            out += sizeof(int64_t);
+            break;
+
+        default:
+            warning("unknown stream format identifier %c in type %d",
+                    streamform[type].form[i],
+                    type);
+            return 0;
+        }
+        i++;
     }
     return (in - buf);
 }
@@ -530,68 +580,68 @@ ps2strn(struct packedstream * ps, char *buf, const int maxlen, int pretty)
     out = (char *) buf;
 
     while ((vartype = streamform[ps->type].form[i]) != '\0') {
-	/* check buffer overflow */
-	if (checklen(maxlen, (out - buf), strlenvar(vartype)))
-	    return 0;
-
-	switch (pretty) {
-	case PS2STR_PRETTY:
-	    formatstr = formatstrvar(vartype);
-	    break;
-	case PS2STR_RRD:
-	    formatstr = rrdstrvar(vartype);
-	    break;
-	default:
-	    warning("%s:%d: unknown pretty identifier", __FILE__, __LINE__);
-	    return 0;
-	}
-
-	switch (vartype) {
-	case 'b':
-	    bcopy(in, &b, sizeof(u_int8_t));
-	    snprintf(out, strlenvar(vartype), formatstr, b);
-	    in++;
-	    break;
-
-	case 'c':
-	    bcopy(in, &c, sizeof(u_int16_t));
-	    D = (double) c / 100.0;
-	    snprintf(out, strlenvar(vartype), formatstr, D);
-	    in += sizeof(u_int16_t);
-	    break;
-
-	case 's':
-	    bcopy(in, &s, sizeof(u_int16_t));
-	    snprintf(out, strlenvar(vartype), formatstr, s);
-	    in += sizeof(u_int16_t);
-	    break;
-
-	case 'l':
-	    bcopy(in, &l, sizeof(u_int32_t));
-	    snprintf(out, strlenvar(vartype), formatstr, l);
-	    in += sizeof(u_int32_t);
-	    break;
-
-	case 'L':
-	    bcopy(in, &q, sizeof(u_int64_t));
-	    snprintf(out, strlenvar(vartype), formatstr, q);
-	    in += sizeof(u_int64_t);
-	    break;
-
-	case 'D':
-	    bcopy(in, &d, sizeof(int64_t));
-	    D = (double) (d / 1000.0 / 1000.0);
-	    snprintf(out, strlenvar(vartype), formatstr, D);
-	    in += sizeof(int64_t);
-	    break;
-
-
-	default:
-	    warning("unknown stream format identifier %c", vartype);
-	    return 0;
-	}
-	out += strlen(out);
-	i++;
+        /* check buffer overflow */
+        if (checklen(maxlen, (out - buf), strlenvar(vartype)))
+            return 0;
+
+        switch (pretty) {
+        case PS2STR_PRETTY:
+            formatstr = formatstrvar(vartype);
+            break;
+        case PS2STR_RRD:
+            formatstr = rrdstrvar(vartype);
+            break;
+        default:
+            warning("%s:%d: unknown pretty identifier", __FILE__, __LINE__);
+            return 0;
+        }
+
+        switch (vartype) {
+        case 'b':
+            bcopy(in, &b, sizeof(u_int8_t));
+            snprintf(out, strlenvar(vartype), formatstr, b);
+            in++;
+            break;
+
+        case 'c':
+            bcopy(in, &c, sizeof(u_int16_t));
+            D = (double) c / 100.0;
+            snprintf(out, strlenvar(vartype), formatstr, D);
+            in += sizeof(u_int16_t);
+            break;
+
+        case 's':
+            bcopy(in, &s, sizeof(u_int16_t));
+            snprintf(out, strlenvar(vartype), formatstr, s);
+            in += sizeof(u_int16_t);
+            break;
+
+        case 'l':
+            bcopy(in, &l, sizeof(u_int32_t));
+            snprintf(out, strlenvar(vartype), formatstr, l);
+            in += sizeof(u_int32_t);
+            break;
+
+        case 'L':
+            bcopy(in, &q, sizeof(u_int64_t));
+            snprintf(out, strlenvar(vartype), formatstr, q);
+            in += sizeof(u_int64_t);
+            break;
+
+        case 'D':
+            bcopy(in, &d, sizeof(int64_t));
+            D = (double) (d / 1000.0 / 1000.0);
+            snprintf(out, strlenvar(vartype), formatstr, D);
+            in += sizeof(int64_t);
+            break;
+
+
+        default:
+            warning("unknown stream format identifier %c", vartype);
+            return 0;
+        }
+        out += strlen(out);
+        i++;
     }
     return (out - buf);
 }
@@ -601,14 +651,14 @@ create_stream(int type, char *args)
     struct stream *p;
 
     if (type < 0 || type >= MT_EOT)
-	fatal("%s:%d: internal error: stream type unknown", __FILE__, __LINE__);
+        fatal("%s:%d: internal error: stream type unknown", __FILE__, __LINE__);
 
     p = (struct stream *) xmalloc(sizeof(struct stream));
     bzero(p, sizeof(struct stream));
     p->type = type;
 
     if (args != NULL)
-	p->arg = xstrdup(args);
+        p->arg = xstrdup(args);
 
     return p;
 }
@@ -619,13 +669,13 @@ find_source_stream(struct source * source, int type, char *args)
     struct stream *p;
 
     if (source == NULL || args == NULL)
-	return NULL;
+        return NULL;
 
     SLIST_FOREACH(p, &source->sl, streams) {
-	if (((void *) p != NULL) && (p->type == type)
-	    && (((void *) args != (void *) p)
-		&& strncmp(args, p->arg, _POSIX2_LINE_MAX) == 0))
-	    return p;
+        if (((void *) p != NULL) && (p->type == type)
+            && (((void *) args != (void *) p)
+                && strncmp(args, p->arg, _POSIX2_LINE_MAX) == 0))
+            return p;
     }
 
     return NULL;
@@ -637,10 +687,10 @@ add_source_stream(struct source * source, int type, char *args)
     struct stream *p;
 
     if (source == NULL)
-	return NULL;
+        return NULL;
 
     if (find_source_stream(source, type, args) != NULL)
-	return NULL;
+        return NULL;
 
     p = create_stream(type, args);
 
@@ -655,13 +705,13 @@ find_mux_stream(struct mux * mux, int type, char *args)
     struct stream *p;
 
     if (mux == NULL || args == NULL)
-	return NULL;
+        return NULL;
 
     SLIST_FOREACH(p, &mux->sl, streams) {
-	if (((void *) p != NULL) && (p->type == type)
-	    && (((void *) args != (void *) p)
-		&& strncmp(args, p->arg, _POSIX2_LINE_MAX) == 0))
-	    return p;
+        if (((void *) p != NULL) && (p->type == type)
+            && (((void *) args != (void *) p)
+                && strncmp(args, p->arg, _POSIX2_LINE_MAX) == 0))
+            return p;
     }
 
     return NULL;
@@ -673,10 +723,10 @@ add_mux_stream(struct mux * mux, int type, char *args)
     struct stream *p;
 
     if (mux == NULL)
-	return NULL;
+        return NULL;
 
     if (find_mux_stream(mux, type, args) != NULL)
-	return NULL;
+        return NULL;
 
     p = create_stream(type, args);
 
@@ -691,12 +741,12 @@ find_source(struct sourcelist * sol, char *name)
     struct source *p;
 
     if (sol == NULL || SLIST_EMPTY(sol) || name == NULL)
-	return NULL;
+        return NULL;
 
     SLIST_FOREACH(p, sol, sources) {
-	if (((void *) p != NULL) && ((void *) name != (void *) p)
-	    && strncmp(name, p->addr, _POSIX2_LINE_MAX) == 0)
-	    return p;
+        if (((void *) p != NULL) && ((void *) name != (void *) p)
+            && strncmp(name, p->addr, _POSIX2_LINE_MAX) == 0)
+            return p;
     }
 
     return NULL;
@@ -708,11 +758,11 @@ find_source_sockaddr(struct sourcelist * sol, struct sockaddr * addr)
     struct source *p;
 
     if (sol == NULL || SLIST_EMPTY(sol))
-	return NULL;
+        return NULL;
 
     SLIST_FOREACH(p, sol, sources) {
-	if (cmpsock_addr((struct sockaddr *) & p->sockaddr, addr))
-	    return p;
+        if (cmpsock_addr((struct sockaddr *) & p->sockaddr, addr))
+            return p;
     }
 
     return NULL;
@@ -724,10 +774,10 @@ add_source(struct sourcelist * sol, char *name)
     struct source *p;
 
     if (sol == NULL)
-	return NULL;
+        return NULL;
 
     if (find_source(sol, name) != NULL)
-	return NULL;
+        return NULL;
 
     p = (struct source *) xmalloc(sizeof(struct source));
     bzero(p, sizeof(struct source));
@@ -744,12 +794,12 @@ find_mux(struct muxlist * mul, char *name)
     struct mux *p;
 
     if (mul == NULL || SLIST_EMPTY(mul) || name == NULL)
-	return NULL;
+        return NULL;
 
     SLIST_FOREACH(p, mul, muxes) {
-	if (((void *) p != NULL) && ((void *) name != (void *) p)
-	    && strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
-	    return p;
+        if (((void *) p != NULL) && ((void *) name != (void *) p)
+            && strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
+            return p;
     }
 
     return NULL;
@@ -761,10 +811,10 @@ add_mux(struct muxlist * mul, char *name)
     struct mux *p;
 
     if (mul == NULL)
-	return NULL;
+        return NULL;
 
     if (find_mux(mul, name) != NULL)
-	return NULL;
+        return NULL;
 
     p = (struct mux *) xmalloc(sizeof(struct mux));
     bzero(p, sizeof(struct mux));
@@ -779,13 +829,13 @@ struct mux *
 rename_mux(struct muxlist * mul, struct mux * mux, char *name)
 {
     if (mul == NULL || mux == NULL)
-	return NULL;
+        return NULL;
 
     if (find_mux(mul, name) != NULL)
-	return NULL;
+        return NULL;
 
     if (mux->name != NULL)
-	xfree(mux->name);
+        xfree(mux->name);
 
     mux->name = xstrdup(name);
 
@@ -798,31 +848,31 @@ free_muxlist(struct muxlist * mul)
     int i;
 
     if (mul == NULL || SLIST_EMPTY(mul))
-	return;
+        return;
 
     p = SLIST_FIRST(mul);
 
     while (p) {
-	np = SLIST_NEXT(p, muxes);
-
-	if (p->name != NULL)
-	    xfree(p->name);
-	if (p->addr != NULL)
-	    xfree(p->addr);
-	if (p->port != NULL)
-	    xfree(p->port);
-
-	close(p->clientsocket);
-	close(p->symuxsocket);
-	for (i = 0; i < AF_MAX; i++)
-	    if (p->symonsocket[i])
-		close(p->symonsocket[i]);
-
-	free_streamlist(&p->sl);
-	free_sourcelist(&p->sol);
-	xfree(p);
-
-	p = np;
+        np = SLIST_NEXT(p, muxes);
+
+        if (p->name != NULL)
+            xfree(p->name);
+        if (p->addr != NULL)
+            xfree(p->addr);
+        if (p->port != NULL)
+            xfree(p->port);
+
+        close(p->clientsocket);
+        close(p->symuxsocket);
+        for (i = 0; i < AF_MAX; i++)
+            if (p->symonsocket[i])
+                close(p->symonsocket[i]);
+
+        free_streamlist(&p->sl);
+        free_sourcelist(&p->sol);
+        xfree(p);
+
+        p = np;
     }
 }
 void
@@ -831,20 +881,20 @@ free_streamlist(struct streamlist * sl)
     struct stream *p, *np;
 
     if (sl == NULL || SLIST_EMPTY(sl))
-	return;
+        return;
 
     p = SLIST_FIRST(sl);
 
     while (p) {
-	np = SLIST_NEXT(p, streams);
+        np = SLIST_NEXT(p, streams);
 
-	if (p->arg != NULL)
-	    xfree(p->arg);
-	if (p->file != NULL)
-	    xfree(p->file);
-	xfree(p);
+        if (p->arg != NULL)
+            xfree(p->arg);
+        if (p->file != NULL)
+            xfree(p->file);
+        xfree(p);
 
-	p = np;
+        p = np;
     }
 }
 void
@@ -853,20 +903,20 @@ free_sourcelist(struct sourcelist * sol)
     struct source *p, *np;
 
     if (sol == NULL || SLIST_EMPTY(sol))
-	return;
+        return;
 
     p = SLIST_FIRST(sol);
 
     while (p) {
-	np = SLIST_NEXT(p, sources);
+        np = SLIST_NEXT(p, sources);
 
-	if (p->addr != NULL)
-	    xfree(p->addr);
+        if (p->addr != NULL)
+            xfree(p->addr);
 
-	free_streamlist(&p->sl);
-	xfree(p);
+        free_streamlist(&p->sl);
+        xfree(p);
 
-	p = np;
+        p = np;
     }
 }
 /* Calculate maximum buffer space needed for a single symon hit */
@@ -887,16 +937,16 @@ calculate_churnbuffer(struct sourcelist * sol)
 
     /* determine maximum string size for a single source */
     SLIST_FOREACH(source, sol, sources) {
-	len = snprintf(&buf[0], _POSIX2_LINE_MAX, "%s;", source->addr);
-	SLIST_FOREACH(stream, &source->sl, streams) {
-	    len += strlen(type2str(stream->type)) + strlen(":");
-	    len += strlen(stream->arg) + strlen(":");
-	    len += (sizeof(time_t) * 3) + strlen(":"); /* 3 > ln(255) / ln(10) */
-	    len += strlentype(stream->type);
-	    n++;
-	}
-	if (len > maxlen)
-	    maxlen = len;
+        len = snprintf(&buf[0], _POSIX2_LINE_MAX, "%s;", source->addr);
+        SLIST_FOREACH(stream, &source->sl, streams) {
+            len += strlen(type2str(stream->type)) + strlen(":");
+            len += strlen(stream->arg) + strlen(":");
+            len += (sizeof(time_t) * 3) + strlen(":"); /* 3 > ln(255) / ln(10) */
+            len += strlentype(stream->type);
+            n++;
+        }
+        if (len > maxlen)
+            maxlen = len;
     }
     return maxlen;
 }
@@ -909,7 +959,7 @@ crc32(const void *buf, unsigned int len)
 
     crc = 0xffffffff;
     for (p = (u_int8_t *) buf; len > 0; ++p, --len)
-	crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
+        crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
 
     return ~crc;
 }
@@ -921,9 +971,9 @@ init_crc32()
     u_int32_t c;
 
     for (i = 0; i < 256; ++i) {
-	c = i << 24;
-	for (j = 8; j > 0; --j)
-	    c = c & 0x80000000 ? (c << 1) ^ SYMON_CRCPOLY : (c << 1);
-	crc32_table[i] = c;
+        c = i << 24;
+        for (j = 8; j > 0; --j)
+            c = c & 0x80000000 ? (c << 1) ^ SYMON_CRCPOLY : (c << 1);
+        crc32_table[i] = c;
     }
 }

+ 152 - 144
symon/lib/data.h

@@ -1,7 +1,7 @@
-/* $Id: data.h,v 1.28 2006/06/28 06:44:45 dijkstra Exp $ */
+/* $Id: data.h,v 1.30 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,7 @@
 
 #include "platform.h"
 
+#include <stdarg.h>
 #include <netinet/in.h>
 #include <limits.h>
 
@@ -70,15 +71,16 @@ static inline u_int64_t
 #endif /* ntohq */
 
 /* Symon packet version
- * version 1:
+ * version 1 and 2:
  * symon_version:timestamp:length:crc:n*packedstream
+ * packedstream = type:arg[<SYMON_PS_ARGLENVx]:data
  *
- * Note that the data portion is limited. The current (31/03/2002) largest
- * streamtype (if) needs 42 bytes without arguments. My _POSIX2_LINE_MAX is 2k,
- * so that works out to about 38 packedstreams in a single symon packet.
+ * Note that the data portion is limited. The current (20/01/2007) largest
+ * streamtype (pf) needs 88 bytes without arguments. _POSIX2_LINE_MAX is 2k, so
+ * that works out to about 23 packedstreams in a single symon packet.
  */
-#define SYMON_PACKET_VER  1
-#define SYMON_UNKMUX   "<unknown mux>"	/* mux nodes without host addr */
+#define SYMON_PACKET_VER  2
+#define SYMON_UNKMUX   "<unknown mux>"  /* mux nodes without host addr */
 
 /* Sending structures over the network is dangerous as the compiler might have
  * added extra padding between items. symonpacketheader below is therefore also
@@ -125,11 +127,12 @@ struct mux {
     char *name;
     char *addr;
     char *port;
+    char *localaddr;
     struct sourcelist sol;
     int offset;
-    int clientsocket;		/* symux; incoming tcp connections */
-    int symonsocket[AF_MAX];	/* symux; incoming symon data */
-    int symuxsocket;		/* symon; outgoing data to mux */
+    int clientsocket;           /* symux; incoming tcp connections */
+    int symonsocket[AF_MAX];    /* symux; incoming symon data */
+    int symuxsocket;            /* symon; outgoing data to mux */
     struct symonpacket packet;
     struct sockaddr_storage sockaddr;
     struct streamlist sl;
@@ -154,7 +157,7 @@ SLIST_HEAD(muxlist, mux);
 #define MT_SENSOR 8
 #define MT_IO2    9
 #define MT_PFQ    10
-#define MT_DF	  11
+#define MT_DF     11
 #define MT_TEST   12
 #define MT_EOT    13
 
@@ -166,136 +169,136 @@ SLIST_HEAD(muxlist, mux);
 struct packedstream {
     int type;
     int padding;
-    char arg[SYMON_PS_ARGLEN];
+    char arg[SYMON_PS_ARGLENV2]; /* V2 > V1 */
     union {
-	struct symonpacketheader header;
-	struct {
-	    u_int64_t mtotal_transfers;
-	    u_int64_t mtotal_seeks;
-	    u_int64_t mtotal_bytes;
-	}      ps_io;
-	struct {
-	    u_int16_t muser;
-	    u_int16_t mnice;
-	    u_int16_t msystem;
-	    u_int16_t minterrupt;
-	    u_int16_t midle;
-	}      ps_cpu;
-	struct {
-	    u_int32_t mreal_active;
-	    u_int32_t mreal_total;
-	    u_int32_t mfree;
-	    u_int32_t mswap_used;
-	    u_int32_t mswap_total;
-	}      ps_mem;
-	struct {
-	    u_int32_t mipackets;
-	    u_int32_t mopackets;
-	    u_int32_t mibytes;
-	    u_int32_t mobytes;
-	    u_int32_t mimcasts;
-	    u_int32_t momcasts;
-	    u_int32_t mierrors;
-	    u_int32_t moerrors;
-	    u_int32_t mcolls;
-	    u_int32_t mdrops;
-	}      ps_if;
-	struct {
-	    u_int64_t bytes_v4_in;
-	    u_int64_t bytes_v4_out;
-	    u_int64_t bytes_v6_in;
-	    u_int64_t bytes_v6_out;
-	    u_int64_t packets_v4_in_pass;
-	    u_int64_t packets_v4_in_drop;
-	    u_int64_t packets_v4_out_pass;
-	    u_int64_t packets_v4_out_drop;
-	    u_int64_t packets_v6_in_pass;
-	    u_int64_t packets_v6_in_drop;
-	    u_int64_t packets_v6_out_pass;
-	    u_int64_t packets_v6_out_drop;
-	    u_int64_t states_entries;
-	    u_int64_t states_searches;
-	    u_int64_t states_inserts;
-	    u_int64_t states_removals;
-	    u_int64_t counters_match;
-	    u_int64_t counters_badoffset;
-	    u_int64_t counters_fragment;
-	    u_int64_t counters_short;
-	    u_int64_t counters_normalize;
-	    u_int64_t counters_memory;
-	}      ps_pf;
-	struct {
-	    u_int32_t debug0;
-	    u_int32_t debug1;
-	    u_int32_t debug2;
-	    u_int32_t debug3;
-	    u_int32_t debug4;
-	    u_int32_t debug5;
-	    u_int32_t debug6;
-	    u_int32_t debug7;
-	    u_int32_t debug8;
-	    u_int32_t debug9;
-	    u_int32_t debug10;
-	    u_int32_t debug11;
-	    u_int32_t debug12;
-	    u_int32_t debug13;
-	    u_int32_t debug14;
-	    u_int32_t debug15;
-	    u_int32_t debug16;
-	    u_int32_t debug17;
-	    u_int32_t debug18;
-	    u_int32_t debug19;
-	}      ps_debug;
-	struct {
-	    u_int32_t totmbufs;
-	    u_int32_t mt_data;
-	    u_int32_t mt_oobdata;
-	    u_int32_t mt_control;
-	    u_int32_t mt_header;
-	    u_int32_t mt_ftable;
-	    u_int32_t mt_soname;
-	    u_int32_t mt_soopts;
-	    u_int32_t pgused;
-	    u_int32_t pgtotal;
-	    u_int32_t totmem;
-	    u_int32_t totpct;
-	    u_int32_t m_drops;
-	    u_int32_t m_wait;
-	    u_int32_t m_drain;
-	}      ps_mbuf;
-	struct {
-	    int64_t value;
-	}      ps_sensor;
-	struct {
-	    u_int64_t mtotal_rtransfers;
-	    u_int64_t mtotal_wtransfers;
-	    u_int64_t mtotal_seeks2;
-	    u_int64_t mtotal_rbytes;
-	    u_int64_t mtotal_wbytes;
-	}      ps_io2;
-	struct {
-	    u_int64_t sent_bytes;
-	    u_int64_t sent_packets;
-	    u_int64_t drop_bytes;
-	    u_int64_t drop_packets;
-	}      ps_pfq;
-	struct {
-	    u_int64_t L[4];
-	    int64_t D[4];
-	    u_int32_t l[4];
-	    u_int16_t s[4];
-	    u_int16_t c[4];
-	    u_int8_t b[4];
-	}      ps_test;
-	struct {
-	    u_int64_t blocks;
-	    u_int64_t bfree;
-	    u_int64_t bavail;
-	    u_int64_t files;
-	    u_int64_t ffree;
-	    u_int64_t syncwrites;
-	    u_int64_t asyncwrites;
-	}      ps_df;
+        struct symonpacketheader header;
+        struct {
+            u_int64_t mtotal_transfers;
+            u_int64_t mtotal_seeks;
+            u_int64_t mtotal_bytes;
+        }      ps_io;
+        struct {
+            u_int16_t muser;
+            u_int16_t mnice;
+            u_int16_t msystem;
+            u_int16_t minterrupt;
+            u_int16_t midle;
+        }      ps_cpu;
+        struct {
+            u_int32_t mreal_active;
+            u_int32_t mreal_total;
+            u_int32_t mfree;
+            u_int32_t mswap_used;
+            u_int32_t mswap_total;
+        }      ps_mem;
+        struct {
+            u_int32_t mipackets;
+            u_int32_t mopackets;
+            u_int32_t mibytes;
+            u_int32_t mobytes;
+            u_int32_t mimcasts;
+            u_int32_t momcasts;
+            u_int32_t mierrors;
+            u_int32_t moerrors;
+            u_int32_t mcolls;
+            u_int32_t mdrops;
+        }      ps_if;
+        struct {
+            u_int64_t bytes_v4_in;
+            u_int64_t bytes_v4_out;
+            u_int64_t bytes_v6_in;
+            u_int64_t bytes_v6_out;
+            u_int64_t packets_v4_in_pass;
+            u_int64_t packets_v4_in_drop;
+            u_int64_t packets_v4_out_pass;
+            u_int64_t packets_v4_out_drop;
+            u_int64_t packets_v6_in_pass;
+            u_int64_t packets_v6_in_drop;
+            u_int64_t packets_v6_out_pass;
+            u_int64_t packets_v6_out_drop;
+            u_int64_t states_entries;
+            u_int64_t states_searches;
+            u_int64_t states_inserts;
+            u_int64_t states_removals;
+            u_int64_t counters_match;
+            u_int64_t counters_badoffset;
+            u_int64_t counters_fragment;
+            u_int64_t counters_short;
+            u_int64_t counters_normalize;
+            u_int64_t counters_memory;
+        }      ps_pf;
+        struct {
+            u_int32_t debug0;
+            u_int32_t debug1;
+            u_int32_t debug2;
+            u_int32_t debug3;
+            u_int32_t debug4;
+            u_int32_t debug5;
+            u_int32_t debug6;
+            u_int32_t debug7;
+            u_int32_t debug8;
+            u_int32_t debug9;
+            u_int32_t debug10;
+            u_int32_t debug11;
+            u_int32_t debug12;
+            u_int32_t debug13;
+            u_int32_t debug14;
+            u_int32_t debug15;
+            u_int32_t debug16;
+            u_int32_t debug17;
+            u_int32_t debug18;
+            u_int32_t debug19;
+        }      ps_debug;
+        struct {
+            u_int32_t totmbufs;
+            u_int32_t mt_data;
+            u_int32_t mt_oobdata;
+            u_int32_t mt_control;
+            u_int32_t mt_header;
+            u_int32_t mt_ftable;
+            u_int32_t mt_soname;
+            u_int32_t mt_soopts;
+            u_int32_t pgused;
+            u_int32_t pgtotal;
+            u_int32_t totmem;
+            u_int32_t totpct;
+            u_int32_t m_drops;
+            u_int32_t m_wait;
+            u_int32_t m_drain;
+        }      ps_mbuf;
+        struct {
+            int64_t value;
+        }      ps_sensor;
+        struct {
+            u_int64_t mtotal_rtransfers;
+            u_int64_t mtotal_wtransfers;
+            u_int64_t mtotal_seeks2;
+            u_int64_t mtotal_rbytes;
+            u_int64_t mtotal_wbytes;
+        }      ps_io2;
+        struct {
+            u_int64_t sent_bytes;
+            u_int64_t sent_packets;
+            u_int64_t drop_bytes;
+            u_int64_t drop_packets;
+        }      ps_pfq;
+        struct {
+            u_int64_t L[4];
+            int64_t D[4];
+            u_int32_t l[4];
+            u_int16_t s[4];
+            u_int16_t c[4];
+            u_int8_t b[4];
+        }      ps_test;
+        struct {
+            u_int64_t blocks;
+            u_int64_t bfree;
+            u_int64_t bavail;
+            u_int64_t files;
+            u_int64_t ffree;
+            u_int64_t syncwrites;
+            u_int64_t asyncwrites;
+        }      ps_df;
     }     data;
 };
 
@@ -307,9 +310,14 @@ int calculate_churnbuffer(struct sourcelist *);
 int getheader(char *, struct symonpacketheader *);
 int ps2strn(struct packedstream *, char *, int, int);
 int setheader(char *, struct symonpacketheader *);
-int snpack(char *, int, char *, int,...);
+int snpack(char *, int, char *, int, ...);
+int snpack1(char *, int, char *, int, ...);
+int snpack2(char *, int, char *, int, ...);
+int snpackx(size_t, char *, int, char *, int, va_list);
 int strlentype(int);
-int sunpack(char *, struct packedstream *);
+int sunpack1(char *, struct packedstream *);
+int sunpack2(char *, struct packedstream *);
+int sunpackx(size_t, char *, struct packedstream *);
 struct mux *add_mux(struct muxlist *, char *);
 struct mux *find_mux(struct muxlist *, char *);
 struct mux *rename_mux(struct muxlist *, struct mux *, char *);
@@ -326,4 +334,4 @@ void free_sourcelist(struct sourcelist *);
 void free_streamlist(struct streamlist *);
 void init_crc32();
 __END_DECLS
-#endif				/* _SYMON_LIB_DATA_H */
+#endif                          /* _SYMON_LIB_DATA_H */

+ 13 - 13
symon/lib/error.c

@@ -1,4 +1,4 @@
-/* $Id: error.c,v 1.13 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: error.c,v 1.14 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -81,29 +81,29 @@ output_message(int level, char *fmt, va_list args)
     int loglevel;
 
     if (level == SYMON_LOG_DEBUG && flag_debug == 0)
-	return;
+        return;
 
     vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
 
     for (loglevel = 0; logmapping[loglevel].type != -1; loglevel++) {
-	if (logmapping[loglevel].type == level)
-	    break;
+        if (logmapping[loglevel].type == level)
+            break;
     }
 
     if (logmapping[loglevel].type == -1)
-	fatal("%s:%d:internal error: illegal loglevel encountered",
-	      __FILE__, __LINE__);
+        fatal("%s:%d:internal error: illegal loglevel encountered",
+              __FILE__, __LINE__);
 
     if (flag_daemon) {
-	syslog(logmapping[loglevel].priority, msgbuf);
+        syslog(logmapping[loglevel].priority, msgbuf);
     } else {
-	if (strlen(logmapping[loglevel].errtxt) > 0) {
-	    fprintf(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout, "%.200s: %.200s\n",
-		    logmapping[loglevel].errtxt, msgbuf);
-	} else
-	    fprintf(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout, "%.200s\n", msgbuf);
+        if (strlen(logmapping[loglevel].errtxt) > 0) {
+            fprintf(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout, "%.200s: %.200s\n",
+                    logmapping[loglevel].errtxt, msgbuf);
+        } else
+            fprintf(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout, "%.200s\n", msgbuf);
 
-	fflush(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout);
+        fflush(logmapping[loglevel].stream == SYMON_OUT_STDERR ? stderr : stdout);
     }
 }
 /* Output error and exit */

+ 2 - 2
symon/lib/error.h

@@ -1,4 +1,4 @@
-/* $Id: error.h,v 1.10 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: error.h,v 1.11 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -46,4 +46,4 @@ void info(char *,...);
 void debug(char *,...);
 __END_DECLS
 
-#endif				/* _SYMON_LIB_ERROR_H */
+#endif                          /* _SYMON_LIB_ERROR_H */

+ 97 - 96
symon/lib/lex.c

@@ -1,7 +1,7 @@
-/* $Id: lex.c,v 1.27 2006/06/28 06:44:45 dijkstra Exp $ */
+/* $Id: lex.c,v 1.28 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -74,6 +74,7 @@ static struct {
     { "debug", LXT_DEBUG },
     { "df", LXT_DF },
     { "every", LXT_EVERY },
+    { "from", LXT_FROM },
     { "if", LXT_IF },
     { "in", LXT_IN },
     { "io", LXT_IO },
@@ -105,8 +106,8 @@ parse_token(const char *cp)
     u_int i;
 
     for (i = 0; keywords[i].name; i++)
-	if (strcasecmp(cp, keywords[i].name) == 0)
-	    return keywords[i].opcode;
+        if (strcasecmp(cp, keywords[i].name) == 0)
+            return keywords[i].opcode;
 
     return LXT_BADTOKEN;
 }
@@ -117,8 +118,8 @@ parse_opcode(const int op)
     u_int i;
 
     for (i = 0; keywords[i].name; i++)
-	if (keywords[i].opcode == op)
-	    return (char *) keywords[i].name;
+        if (keywords[i].opcode == op)
+            return (char *) keywords[i].name;
 
     return NULL;
 }
@@ -129,17 +130,17 @@ lex_readline(struct lex *l)
     char *bp;
 
     if (l == NULL)
-	return 0;
+        return 0;
 
     bp = l->buffer;
 
     if (l->buffer) {
-	l->curpos = 0;
-	l->endpos = 0;
+        l->curpos = 0;
+        l->endpos = 0;
     } else {
-	l->bsize = _POSIX2_LINE_MAX;
-	l->buffer = xmalloc(l->bsize);
-	bp = l->buffer;
+        l->bsize = _POSIX2_LINE_MAX;
+        l->buffer = xmalloc(l->bsize);
+        bp = l->buffer;
     }
 
     l->endpos = read(l->fh, bp, (l->buffer + l->bsize) - bp);
@@ -151,14 +152,14 @@ void
 lex_copychar(struct lex *l)
 {
     if (l == NULL)
-	return;
+        return;
 
     l->token[l->tokpos] = l->buffer[l->curpos];
 
     if (++l->tokpos >= _POSIX2_LINE_MAX) {
-	l->token[_POSIX2_LINE_MAX - 1] = '\0';
-	fatal("%.200s:%d: parse error at '%.200s'", l->filename, l->cline, l->token);
-	/* NOT REACHED */
+        l->token[_POSIX2_LINE_MAX - 1] = '\0';
+        fatal("%.200s:%d: parse error at '%.200s'", l->filename, l->cline, l->token);
+        /* NOT REACHED */
     }
 }
 /* Get next char, read next line if needed */
@@ -166,16 +167,16 @@ int
 lex_nextchar(struct lex *l)
 {
     if (l == NULL)
-	return 0;
+        return 0;
 
     l->curpos++;
 
     if (l->curpos >= l->endpos)
-	if (!lex_readline(l))
-	    return 0;
+        if (!lex_readline(l))
+            return 0;
 
     if (l->buffer[l->curpos] == '\n')
-	l->cline++;
+        l->cline++;
 
     return 1;
 }
@@ -184,7 +185,7 @@ void
 lex_termtoken(struct lex *l)
 {
     if (l == NULL)
-	return;
+        return;
 
     l->token[l->tokpos] = l->token[_POSIX2_LINE_MAX - 1] = '\0';
     l->tokpos = 0;
@@ -194,7 +195,7 @@ void
 lex_ungettoken(struct lex *l)
 {
     if (l == NULL)
-	return;
+        return;
 
     l->unget = 1;
 }
@@ -203,12 +204,12 @@ int
 lex_nexttoken(struct lex *l)
 {
     if (l == NULL)
-	return 0;
+        return 0;
 
     /* return same token as last time if it has been pushed back */
     if (l->unget) {
-	l->unget = 0;
-	return 1;
+        l->unget = 0;
+        return 1;
     }
 
     l->op = LXT_BADTOKEN;
@@ -217,88 +218,88 @@ lex_nexttoken(struct lex *l)
 
     /* find first non whitespace */
     while (l->buffer[l->curpos] == ' ' ||
-	   l->buffer[l->curpos] == '\t' ||
-	   l->buffer[l->curpos] == '\r' ||
-	   l->buffer[l->curpos] == '\n' ||
-	   l->buffer[l->curpos] == '\0' ||
-	   l->buffer[l->curpos] == '#') {
-	/* flush rest of line if comment */
-	if (l->buffer[l->curpos] == '#') {
-	    while (l->buffer[l->curpos] != '\n')
-		if (!lex_nextchar(l))
-		    return 0;
-	} else if (!lex_nextchar(l))
-	    return 0;
+           l->buffer[l->curpos] == '\t' ||
+           l->buffer[l->curpos] == '\r' ||
+           l->buffer[l->curpos] == '\n' ||
+           l->buffer[l->curpos] == '\0' ||
+           l->buffer[l->curpos] == '#') {
+        /* flush rest of line if comment */
+        if (l->buffer[l->curpos] == '#') {
+            while (l->buffer[l->curpos] != '\n')
+                if (!lex_nextchar(l))
+                    return 0;
+        } else if (!lex_nextchar(l))
+            return 0;
     }
 
     l->type = LXY_STRING;
 
     /* "delimited string" */
     if (l->buffer[l->curpos] == '"') {
-	if (!lex_nextchar(l)) {
-	    warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
-	    return 0;
-	}
-	while (l->buffer[l->curpos] != '"') {
-	    lex_copychar(l);
-	    if (!lex_nextchar(l)) {
-		warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
-		return 0;
-	    }
-	}
-	lex_termtoken(l);
-	lex_nextchar(l);
-	return 1;
+        if (!lex_nextchar(l)) {
+            warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
+            return 0;
+        }
+        while (l->buffer[l->curpos] != '"') {
+            lex_copychar(l);
+            if (!lex_nextchar(l)) {
+                warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
+                return 0;
+            }
+        }
+        lex_termtoken(l);
+        lex_nextchar(l);
+        return 1;
     }
 
     /* 'delimited string' */
     if (l->buffer[l->curpos] == '\'') {
-	if (!lex_nextchar(l)) {
-	    warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
-	    return 0;
-	}
-	while (l->buffer[l->curpos] != '\'') {
-	    lex_copychar(l);
-	    if (!lex_nextchar(l)) {
-		warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
-		return 0;
-	    }
-	}
-	lex_termtoken(l);
-	lex_nextchar(l);
-	return 1;
+        if (!lex_nextchar(l)) {
+            warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
+            return 0;
+        }
+        while (l->buffer[l->curpos] != '\'') {
+            lex_copychar(l);
+            if (!lex_nextchar(l)) {
+                warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
+                return 0;
+            }
+        }
+        lex_termtoken(l);
+        lex_nextchar(l);
+        return 1;
     }
 
     /* one char keyword */
     if (strchr(KW_OPS, l->buffer[l->curpos])) {
-	lex_copychar(l);
-	lex_termtoken(l);
-	l->op = parse_token(l->token);
-	lex_nextchar(l);
-	return 1;
+        lex_copychar(l);
+        lex_termtoken(l);
+        l->op = parse_token(l->token);
+        lex_nextchar(l);
+        return 1;
     }
 
     /* single keyword */
     while (l->buffer[l->curpos] != ' ' &&
-	   l->buffer[l->curpos] != '\t' &&
-	   l->buffer[l->curpos] != '\r' &&
-	   l->buffer[l->curpos] != '\n' &&
-	   l->buffer[l->curpos] != '\0' &&
-	   l->buffer[l->curpos] != '#' &&
-	   (strchr(KW_OPS, l->buffer[l->curpos]) == NULL)) {
-	lex_copychar(l);
-	if (!lex_nextchar(l))
-	    break;
+           l->buffer[l->curpos] != '\t' &&
+           l->buffer[l->curpos] != '\r' &&
+           l->buffer[l->curpos] != '\n' &&
+           l->buffer[l->curpos] != '\0' &&
+           l->buffer[l->curpos] != '#' &&
+           (strchr(KW_OPS, l->buffer[l->curpos]) == NULL)) {
+        lex_copychar(l);
+        if (!lex_nextchar(l))
+            break;
     }
     lex_termtoken(l);
     l->op = parse_token(l->token);
 
     /* number */
     if (l->token[0] >= '0' && l->token[0] <= '9') {
-	if (strlen(l->token) == strspn(l->token, "0123456789")) {
-	    l->type = LXY_NUMBER;
-	    l->value = strtol(l->token, NULL, 10);
-	}
+        if (strlen(l->token) == strspn(l->token, "0123456789")) {
+            l->type = LXY_NUMBER;
+            l->value = strtol(l->token, NULL, 10);
+        }
     }
     return 1;
 }
@@ -315,10 +316,10 @@ open_lex(const char *filename)
     l->token = xmalloc(_POSIX2_LINE_MAX);
 
     if ((l->fh = open(l->filename, O_RDONLY)) < 0) {
-	warning("could not open file \"%.200s\":%.200s",
-		l->filename, strerror(errno));
-	close_lex(l);
-	return NULL;
+        warning("could not open file \"%.200s\":%.200s",
+                l->filename, strerror(errno));
+        close_lex(l);
+        return NULL;
     }
 
     lex_readline(l);
@@ -331,13 +332,13 @@ rewind_lex(struct lex *l)
     off_t filepos;
 
     if (l == NULL)
-	return;
+        return;
 
     reset_lex(l);
 
     if ((filepos = lseek(l->fh, (off_t)0, SEEK_SET)) == -1) {
-	warning("could not rewind file '%.200s':%.200s",
-		l->filename, strerror(errno));
+        warning("could not rewind file '%.200s':%.200s",
+                l->filename, strerror(errno));
     }
 }
 /* Reset lexer to start of file defaults */
@@ -345,7 +346,7 @@ void
 reset_lex(struct lex *l)
 {
     if (l == NULL)
-	return;
+        return;
 
     l->cline = 1;
     l->curpos = 0;
@@ -361,14 +362,14 @@ void
 close_lex(struct lex *l)
 {
     if (l == NULL)
-	return;
+        return;
 
     if (l->fh)
-	close(l->fh);
+        close(l->fh);
     if (l->buffer)
-	xfree(l->buffer);
+        xfree(l->buffer);
     if (l->token)
-	xfree(l->token);
+        xfree(l->token);
     xfree(l);
 }
 /* Signal a parse error */
@@ -376,5 +377,5 @@ void
 parse_error(struct lex *l, const char *s)
 {
     warning("%.200s:%d: expected '%.200s' found '%.8s'",
-	    l->filename, l->cline, s, l->token);
+            l->filename, l->cline, s, l->token);
 }

+ 41 - 40
symon/lib/lex.h

@@ -1,7 +1,7 @@
-/* $Id: lex.h,v 1.23 2006/06/28 06:44:45 dijkstra Exp $ */
+/* $Id: lex.h,v 1.24 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2001-2007 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -54,44 +54,45 @@
 #define LXT_DF         8
 #define LXT_END        9
 #define LXT_EVERY     10
-#define LXT_IF        11
-#define LXT_IN        12
-#define LXT_IO        13
-#define LXT_IO1       14
-#define LXT_MBUF      15
-#define LXT_MEM       16
-#define LXT_MONITOR   17
-#define LXT_MUX       18
-#define LXT_OPEN      19
-#define LXT_PF        20
-#define LXT_PFQ       21
-#define LXT_PORT      22
-#define LXT_PROC      23
-#define LXT_SECOND    24
-#define LXT_SECONDS   25
-#define LXT_SENSOR    26
-#define LXT_SOURCE    27
-#define LXT_STREAM    28
-#define LXT_TO        29
-#define LXT_WRITE     30
+#define LXT_FROM      11
+#define LXT_IF        12
+#define LXT_IN        13
+#define LXT_IO        14
+#define LXT_IO1       15
+#define LXT_MBUF      16
+#define LXT_MEM       17
+#define LXT_MONITOR   18
+#define LXT_MUX       19
+#define LXT_OPEN      20
+#define LXT_PF        21
+#define LXT_PFQ       22
+#define LXT_PORT      23
+#define LXT_PROC      24
+#define LXT_SECOND    25
+#define LXT_SECONDS   26
+#define LXT_SENSOR    27
+#define LXT_SOURCE    28
+#define LXT_STREAM    29
+#define LXT_TO        30
+#define LXT_WRITE     31
 
 struct lex {
-    char *buffer;		/* current line(s) */
+    char *buffer;               /* current line(s) */
     const char *filename;
     int fh;
-    char *token;		/* last token seen */
-    long value;			/* value of last token seen, if num */
-    int bsize;			/* size of buffer  */
-    int cline;			/* current lineno */
-    int curpos;			/* current position in buffer */
-    int endpos;			/* current maxpos in buffer */
-    int op;			/* opcode of token, if string */
-    int unget;			/* bool; token pushed back */
-    int tokpos;			/* current position in token buffer */
+    char *token;                /* last token seen */
+    long value;                 /* value of last token seen, if num */
+    int bsize;                  /* size of buffer  */
+    int cline;                  /* current lineno */
+    int curpos;                 /* current position in buffer */
+    int endpos;                 /* current maxpos in buffer */
+    int op;                     /* opcode of token, if string */
+    int unget;                  /* bool; token pushed back */
+    int tokpos;                 /* current position in token buffer */
     enum {
-	LXY_STRING, LXY_NUMBER, LXY_UNKNOWN
+        LXY_STRING, LXY_NUMBER, LXY_UNKNOWN
     }
-	 type;			/* type of token in buffer */
+         type;                  /* type of token in buffer */
 };
 
 __BEGIN_DECLS
@@ -108,11 +109,11 @@ __END_DECLS
 
 /* EXPECT(l,x) = next token in l must be opcode x or error.  */
 #define EXPECT(l, x)    do {                      \
-	lex_nexttoken((l));                       \
-	if ((l)->op != (x)) {                     \
-	    parse_error((l), parse_opcode((x)));  \
-	    return 0;                             \
-	}                                         \
+        lex_nexttoken((l));                       \
+        if ((l)->op != (x)) {                     \
+            parse_error((l), parse_opcode((x)));  \
+            return 0;                             \
+        }                                         \
     } while (0);
 
-#endif				/* _SYMON_LIB_LEX_H */
+#endif                          /* _SYMON_LIB_LEX_H */

+ 65 - 64
symon/lib/net.c

@@ -1,4 +1,4 @@
-/* $Id: net.c,v 1.13 2005/02/16 20:24:51 dijkstra Exp $ */
+/* $Id: net.c,v 1.14 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -65,38 +65,38 @@ getip(char *name, int family)
     hints.ai_flags = AI_NUMERICHOST;
     hints.ai_family = family;
     if (getaddrinfo(name, NULL, &hints, &res) != 0) {
-	hints.ai_flags = 0;
-	if ((error = getaddrinfo(name, NULL, &hints, &res)) < 0) {
-	    debug("getaddrinfo(%.200s, %d): %.200s", name, family, gai_strerror(error));
-	    return 0;
-	}
+        hints.ai_flags = 0;
+        if ((error = getaddrinfo(name, NULL, &hints, &res)) < 0) {
+            debug("getaddrinfo(%.200s, %d): %.200s", name, family, gai_strerror(error));
+            return 0;
+        }
     }
 
     if (res && hints.ai_flags & AI_NUMERICHOST) {
-	strncpy(res_host, name, NI_MAXHOST);
-	res_host[NI_MAXHOST - 1] = 0;
+        strncpy(res_host, name, NI_MAXHOST);
+        res_host[NI_MAXHOST - 1] = 0;
 
-	cpysock(res->ai_addr, &res_addr);
+        cpysock(res->ai_addr, &res_addr);
 
-	freeaddrinfo(res);
-	return 1;
+        freeaddrinfo(res);
+        return 1;
     } else {
-	if (res && res->ai_addr) {
-	    if ((error = getnameinfo(res->ai_addr, res->ai_addrlen,
-				     res_host, NI_MAXHOST,
-				     NULL, 0, NI_NUMERICHOST)) == 0) {
-		res_host[NI_MAXHOST - 1] = 0;
-
-		cpysock(res->ai_addr, &res_addr);
-
-		freeaddrinfo(res);
-		return 1;
-	    } else {
-		debug("getnameinfo(%.200s, %d): %.200s", name, family, gai_strerror(error));
-	    }
-	} else {
-	    debug("getip(%.200s, family): could not get numeric host via getaddrinfo nor getnameinfo", name, family);
-	}
+        if (res && res->ai_addr) {
+            if ((error = getnameinfo(res->ai_addr, res->ai_addrlen,
+                                     res_host, NI_MAXHOST,
+                                     NULL, 0, NI_NUMERICHOST)) == 0) {
+                res_host[NI_MAXHOST - 1] = 0;
+
+                cpysock(res->ai_addr, &res_addr);
+
+                freeaddrinfo(res);
+                return 1;
+            } else {
+                debug("getnameinfo(%.200s, %d): %.200s", name, family, gai_strerror(error));
+            }
+        } else {
+            debug("getip(%.200s, family): could not get numeric host via getaddrinfo nor getnameinfo", name, family);
+        }
     }
 
     return 0;
@@ -122,16 +122,16 @@ getaddr(char *name, char *service, int socktype, int flags)
     /* don't lookup if not necessary */
     hints.ai_flags |= AI_NUMERICHOST;
     if (getaddrinfo(name, service, &hints, &res) != 0) {
-	hints.ai_flags = flags;
-	if ((error = getaddrinfo(name, service, &hints, &res)) < 0) {
-	    warning("getaddrinfo(%.200s): %.200s", name, gai_strerror(error));
-	    return 0;
-	}
+        hints.ai_flags = flags;
+        if ((error = getaddrinfo(name, service, &hints, &res)) < 0) {
+            warning("getaddrinfo(%.200s): %.200s", name, gai_strerror(error));
+            return 0;
+        }
     }
 
     if (res->ai_addrlen > sizeof(res_addr))
-	fatal("%s:%d: internal error: getaddr returned bigger sockaddr than expected (%d>%d)",
-	      __FILE__, __LINE__, res->ai_addrlen, sizeof(res_addr));
+        fatal("%s:%d: internal error: getaddr returned bigger sockaddr than expected (%d>%d)",
+              __FILE__, __LINE__, res->ai_addrlen, sizeof(res_addr));
 
     cpysock(res->ai_addr, &res_addr);
 
@@ -144,9 +144,9 @@ get_numeric_name(struct sockaddr_storage * source)
     snprintf(res_service, sizeof(res_service), "<unknown>");
 
     return getnameinfo((struct sockaddr *)source, SS_LEN(source),
-		       res_host, sizeof(res_host),
-		       res_service, sizeof(res_service),
-		       NI_NUMERICHOST | NI_NUMERICSERV);
+                       res_host, sizeof(res_host),
+                       res_service, sizeof(res_service),
+                       NI_NUMERICHOST | NI_NUMERICSERV);
 }
 void
 cpysock(struct sockaddr * source, struct sockaddr_storage * dest)
@@ -164,48 +164,49 @@ cmpsock_addr(struct sockaddr * first, struct sockaddr * second)
 {
 
     if (first == NULL || second == NULL)
-	return 0;
+        return 0;
 
     if ((SA_LEN(first) != SA_LEN(second)) ||
-	(first->sa_family != second->sa_family))
-	return 0;
+        (first->sa_family != second->sa_family))
+        return 0;
 
     if (first->sa_family == PF_INET) {
-	if (bcmp((void *) &((struct sockaddr_in *) first)->sin_addr,
-		 (void *) &((struct sockaddr_in *) second)->sin_addr,
-		 sizeof(struct in_addr)) == 0)
-	    return 1;
-	else
-	    return 0;
+        if (bcmp((void *) &((struct sockaddr_in *) first)->sin_addr,
+                 (void *) &((struct sockaddr_in *) second)->sin_addr,
+                 sizeof(struct in_addr)) == 0)
+            return 1;
+        else
+            return 0;
     }
 
     if (first->sa_family == PF_INET6) {
-	if (bcmp((void *) &((struct sockaddr_in6 *) first)->sin6_addr,
-		 (void *) &((struct sockaddr_in6 *) second)->sin6_addr,
-		 sizeof(struct in6_addr)) == 0)
-	    return 1;
-	else
-	    return 0;
+        if (bcmp((void *) &((struct sockaddr_in6 *) first)->sin6_addr,
+                 (void *) &((struct sockaddr_in6 *) second)->sin6_addr,
+                 sizeof(struct in6_addr)) == 0)
+            return 1;
+        else
+            return 0;
     }
 
-    /* don't know what to compare for this family */
+    /* do not know what to compare for this family */
     return 0;
 }
-/* generate INADDR_ANY info */
+/* generate sockaddr based on family, type and getaddrinfo flags  */
 void
-get_inaddrany_sockaddr(struct sockaddr_storage * sockaddr, int family, int socktype, char *port)
+get_sockaddr(struct sockaddr_storage * sockaddr, int family, int socktype,
+    int flags, char * host, char * port)
 {
     struct addrinfo hints, *res;
 
     bzero((void *) &hints, sizeof(struct addrinfo));
     hints.ai_family = family;
     hints.ai_socktype = socktype;
-    hints.ai_flags = AI_PASSIVE;
-    if (getaddrinfo(NULL, port, &hints, &res) != 0)
-	fatal("could not get inaddr address");
+    hints.ai_flags = flags;
+    if (getaddrinfo(host, port, &hints, &res) != 0)
+        fatal("could not get sockaddr address");
     else {
-	cpysock((struct sockaddr *) res->ai_addr, sockaddr);
-	freeaddrinfo(res);
+        cpysock((struct sockaddr *) res->ai_addr, sockaddr);
+        freeaddrinfo(res);
     }
 }
 /* fill a source->sockaddr with a sockaddr for use in address compares */
@@ -213,8 +214,8 @@ int
 get_source_sockaddr(struct source * source, int family)
 {
     if (getip(source->addr, family)) {
-	cpysock((struct sockaddr *) &res_addr, &source->sockaddr);
-	return 1;
+        cpysock((struct sockaddr *) &res_addr, &source->sockaddr);
+        return 1;
     }
 
     return 0;
@@ -224,8 +225,8 @@ void
 get_mux_sockaddr(struct mux * mux, int socktype)
 {
     if (getaddr(mux->addr, mux->port, socktype, AI_PASSIVE) == 0)
-	fatal("could not get address information for %.200s %.200s",
-	      mux->addr, mux->port);
+        fatal("could not get address information for %.200s %.200s",
+              mux->addr, mux->port);
 
     cpysock((struct sockaddr *) &res_addr, &mux->sockaddr);
 }

+ 4 - 4
symon/lib/net.h

@@ -1,4 +1,4 @@
-/* $Id: net.h,v 1.14 2005/02/16 20:24:51 dijkstra Exp $ */
+/* $Id: net.h,v 1.15 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -37,7 +37,7 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 
-#define SYMUX_PORT  "2100"	/* default symux port */
+#define SYMUX_PORT  "2100"      /* default symux port */
 
 extern char res_host[];
 extern char res_service[];
@@ -50,9 +50,9 @@ int getaddr(char *, char *, int, int);
 int getip(char *, int);
 int lookup(char *);
 void cpysock(struct sockaddr *, struct sockaddr_storage *);
-void get_inaddrany_sockaddr(struct sockaddr_storage *, int, int, char *);
+void get_sockaddr(struct sockaddr_storage *, int, int, int, char*, char *);
 void get_mux_sockaddr(struct mux *, int);
 int get_source_sockaddr(struct source *, int);
 __END_DECLS
 
-#endif				/* _SYMON_LIB_NET_H */
+#endif                          /* _SYMON_LIB_NET_H */

+ 5 - 4
symon/lib/sylimits.h

@@ -1,13 +1,14 @@
-/* $Id: sylimits.h,v 1.4 2006/09/10 19:51:32 dijkstra Exp $ */
+/* $Id: sylimits.h,v 1.6 2007/02/11 20:07:31 dijkstra Exp $ */
 
 #ifndef _LIB_LIMITS_H
 #define _LIB_LIMITS_H
 
-#define SYMON_PS_ARGLEN        16       /* maximum argument length */
-#define SYMON_PS_ARGLENSTR     "15"     /* maximum number of chars in an argument, as str */
+#define SYMON_PS_ARGLENV1      16       /* maximum argument length in a v1 packet */
+#define SYMON_PS_ARGLENV2      64       /* maximum argument length in a v2 packet */
+#define SYMON_PS_ARGLENSTRV2   "63"     /* maximum number of chars in an v2 argument, as str */
 #define SYMON_WARN_SENDERR     50       /* warn every x errors */
 #define SYMON_MAX_DOBJECTS     10000    /* max dynamic allocation; local limit per
-					 * measurement module */
+                                         * measurement module */
 #define SYMON_MAX_OBJSIZE      (_POSIX2_LINE_MAX)
 #define SYMON_SENSORMASK       0xFF     /* sensors 0-255 are allowed */
 #define SYMON_MAXDEBUGID       20       /* = CTL_DEBUG_MAXID; depends lib/data.h */

+ 9 - 9
symon/lib/xmalloc.c

@@ -1,4 +1,4 @@
-/* $Id: xmalloc.c,v 1.7 2004/08/07 12:21:36 dijkstra Exp $ */
+/* $Id: xmalloc.c,v 1.8 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -27,12 +27,12 @@ xmalloc(size_t size)
     void *ptr;
 
     if (size == 0)
-	fatal("xmalloc: zero size");
+        fatal("xmalloc: zero size");
 
     ptr = malloc(size);
 
     if (ptr == NULL)
-	fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
+        fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
 
     return ptr;
 }
@@ -43,15 +43,15 @@ xrealloc(void *ptr, size_t new_size)
     void *new_ptr;
 
     if (new_size == 0)
-	fatal("xrealloc: zero size");
+        fatal("xrealloc: zero size");
 
     if (ptr == NULL)
-	new_ptr = malloc(new_size);
+        new_ptr = malloc(new_size);
     else
-	new_ptr = realloc(ptr, new_size);
+        new_ptr = realloc(ptr, new_size);
 
     if (new_ptr == NULL)
-	fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
+        fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
 
     return new_ptr;
 }
@@ -60,7 +60,7 @@ void
 xfree(void *ptr)
 {
     if (ptr == NULL)
-	fatal("xfree: NULL pointer given as argument");
+        fatal("xfree: NULL pointer given as argument");
 
     free(ptr);
 }
@@ -72,7 +72,7 @@ char
     char *cp;
 
     if (len == 0)
-	fatal("xstrdup: zero size");
+        fatal("xstrdup: zero size");
 
     cp = xmalloc(len);
     strlcpy(cp, str, len);

+ 2 - 2
symon/lib/xmalloc.h

@@ -1,4 +1,4 @@
-/* $Id: xmalloc.h,v 1.6 2002/11/29 10:50:29 dijkstra Exp $ */
+/* $Id: xmalloc.h,v 1.7 2007/02/11 20:07:31 dijkstra Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -26,4 +26,4 @@ void *xrealloc(void *, size_t);
 void xfree(void *);
 char *xstrdup(const char *);
 __END_DECLS
-#endif				/* _SYMON_LIB_XMALLOC_H */
+#endif                          /* _SYMON_LIB_XMALLOC_H */

+ 6 - 6
symon/platform/FreeBSD/platform.h

@@ -1,4 +1,4 @@
-/* $Id: platform.h,v 1.5 2006/11/07 08:00:18 dijkstra Exp $ */
+/* $Id: platform.h,v 1.6 2007/02/11 20:07:31 dijkstra Exp $ */
 
 #ifndef _CONF_FREEBSD_H
 #define _CONF_FREEBSD_H
@@ -22,13 +22,13 @@
 
 union stream_parg {
     struct {
-	long time[CPUSTATES];
-	long old[CPUSTATES];
-	long diff[CPUSTATES];
-	int states[CPUSTATES];
+        long time[CPUSTATES];
+        long old[CPUSTATES];
+        long diff[CPUSTATES];
+        int states[CPUSTATES];
     } cp;
     struct {
-	char rawdev[SYMON_DFNAMESIZE];
+        char rawdev[SYMON_DFNAMESIZE];
     } df;
     struct ifreq ifr;
     int sn;

+ 19 - 19
symon/platform/FreeBSD/sm_cpu.c

@@ -1,4 +1,4 @@
-/* $Id: sm_cpu.c,v 1.4 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_cpu.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /* The author of this code is Matthew Gream.
  *
@@ -97,22 +97,22 @@ percentages(int cnt, int *out, register long *new, register long *old, long *dif
 
     /* calculate changes for each state and the overall change */
     for (i = 0; i < cnt; i++) {
-	if (*new < *old)
-	    change = (ULONG_MAX - *old) + *new;
-	else
-	    change = *new - *old;
-	total_change += (*dp++ = change);
-	*old++ = *new++;
+        if (*new < *old)
+            change = (ULONG_MAX - *old) + *new;
+        else
+            change = *new - *old;
+        total_change += (*dp++ = change);
+        *old++ = *new++;
     }
 
     /* avoid divide by zero potential */
     if (total_change == 0)
-	total_change = 1;
+        total_change = 1;
 
     /* calculate percentages based on overall change, rounding up */
     half_total = total_change / 2;
     for (i = 0; i < cnt; i++)
-	*out++ = ((*diffs++ * 1000 + half_total) / total_change);
+        *out++ = ((*diffs++ * 1000 + half_total) / total_change);
 
     /* return the total in case the caller wants to use it */
     return total_change;
@@ -125,8 +125,8 @@ init_cpu(struct stream *st)
 
     cp_time_len = CTL_MAXNAME;
     if (sysctlnametomib(cp_time_mib_str, cp_time_mib, &cp_time_len) < 0) {
-	warning("sysctlnametomib for cpu failed");
-	cp_time_len = 0;
+        warning("sysctlnametomib for cpu failed");
+        cp_time_len = 0;
     }
 
     cp_size = sizeof(st->parg.cp.time);
@@ -145,21 +145,21 @@ int
 get_cpu(char *symon_buf, int maxlen, struct stream *st)
 {
     if (!cp_time_len) {
-	return 0;
+        return 0;
     }
 
     if (sysctl(cp_time_mib, cp_time_len, &st->parg.cp.time, &cp_size, NULL, 0) < 0) {
-	warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
-	return 0;
+        warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
+        return 0;
     }
 
     /* convert cp_time counts to percentages */
     (void)percentages(CPUSTATES, st->parg.cp.states, st->parg.cp.time, st->parg.cp.old, st->parg.cp.diff);
 
     return snpack(symon_buf, maxlen, st->arg, MT_CPU,
-		  (double) (st->parg.cp.states[CP_USER] / 10.0),
-		  (double) (st->parg.cp.states[CP_NICE] / 10.0),
-		  (double) (st->parg.cp.states[CP_SYS] / 10.0),
-		  (double) (st->parg.cp.states[CP_INTR] / 10.0),
-		  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
+                  (double) (st->parg.cp.states[CP_USER] / 10.0),
+                  (double) (st->parg.cp.states[CP_NICE] / 10.0),
+                  (double) (st->parg.cp.states[CP_SYS] / 10.0),
+                  (double) (st->parg.cp.states[CP_INTR] / 10.0),
+                  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
 }

+ 6 - 6
symon/platform/FreeBSD/sm_debug.c

@@ -1,4 +1,4 @@
-/* $Id: sm_debug.c,v 1.3 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_debug.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c)      2004 Matthew Gream
@@ -67,14 +67,14 @@ get_debug(char *symon_buf, int maxlen, struct stream *st)
     len = sizeof(int);
 
     for (i = 0; i < SYMON_MAXDEBUGID; i++) {
-	db_mib[1] = i;
+        db_mib[1] = i;
 
-	sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
+        sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_DEBUG,
-		  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
-		  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
-		  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
+                  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
+                  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
+                  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
 
 }

+ 14 - 14
symon/platform/FreeBSD/sm_df.c

@@ -1,4 +1,4 @@
-/* $Id: sm_df.c,v 1.2 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_df.c,v 1.1 2007/02/11 20:08:19 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Marc Balmer
@@ -72,7 +72,7 @@ void
 gets_df()
 {
     if ((df_parts = getmntinfo(&df_stats, MNT_NOWAIT)) == 0) {
-	warning("df failed");
+        warning("df failed");
     }
 }
 
@@ -82,8 +82,8 @@ gets_df()
  * Attempts to avoid overflow for large filesystems.
  */
 #define fsbtoblk(num, fsbs, bs) \
-	(((fsbs) != 0 && (fsbs) < (bs)) ? \
-		(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
+        (((fsbs) != 0 && (fsbs) < (bs)) ? \
+                (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
 
 int
 get_df(char *symon_buf, int maxlen, struct stream *st)
@@ -91,16 +91,16 @@ get_df(char *symon_buf, int maxlen, struct stream *st)
     int n;
 
     for (n = 0; n < df_parts; n++) {
-	if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
-	    return snpack(symon_buf, maxlen, st->arg, MT_DF,
-			  (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)df_stats[n].f_files,
-			  (u_int64_t)df_stats[n].f_ffree,
-			  (u_int64_t)df_stats[n].f_syncwrites,
-			  (u_int64_t)df_stats[n].f_asyncwrites);
-	}
+        if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
+            return snpack(symon_buf, maxlen, st->arg, MT_DF,
+                          (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)df_stats[n].f_files,
+                          (u_int64_t)df_stats[n].f_ffree,
+                          (u_int64_t)df_stats[n].f_syncwrites,
+                          (u_int64_t)df_stats[n].f_asyncwrites);
+        }
     }
 
     warning("df(%.200s) failed (no such device)", st->arg);

+ 24 - 24
symon/platform/FreeBSD/sm_if.c

@@ -1,4 +1,4 @@
-/* $Id: sm_if.c,v 1.3 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_if.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Fredrik Soderblom
@@ -76,9 +76,9 @@ get_ifcount(void)
     len = sizeof(int);
 
     if (sysctl(name, 5, &count, &len, NULL, 0) != -1) {
-	return count;
+        return count;
     } else {
-	return -1;
+        return -1;
     }
 }
 
@@ -103,19 +103,19 @@ gets_if()
 
     /* increase buffers if necessary */
     if (if_cur > if_max) {
-	if_max = if_cur;
+        if_max = if_cur;
 
-	if (if_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for ifmibdata structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (if_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for ifmibdata structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	if_md = xrealloc(if_md, if_max * sizeof(struct ifmibdata));
+        if_md = xrealloc(if_md, if_max * sizeof(struct ifmibdata));
     }
 
     /* read data */
     for (i = 1; i <= if_cur; i++) {
-	get_ifmib_general(i, &if_md[i - 1]);
+        get_ifmib_general(i, &if_md[i - 1]);
     }
 }
 
@@ -126,20 +126,20 @@ get_if(char *symon_buf, int maxlen, struct stream *st)
     struct if_data ifdata;
 
     for (i = 1; i <= if_cur; i++) {
-	if (!strcmp(if_md[i - 1].ifmd_name, st->arg)) {
-	    ifdata = if_md[i - 1].ifmd_data;
-	    return snpack(symon_buf, maxlen, st->arg, MT_IF,
-			  ifdata.ifi_ipackets,
-			  ifdata.ifi_opackets,
-			  ifdata.ifi_ibytes,
-			  ifdata.ifi_obytes,
-			  ifdata.ifi_imcasts,
-			  ifdata.ifi_omcasts,
-			  ifdata.ifi_ierrors,
-			  ifdata.ifi_oerrors,
-			  ifdata.ifi_collisions,
-			  ifdata.ifi_iqdrops);
-	}
+        if (!strcmp(if_md[i - 1].ifmd_name, st->arg)) {
+            ifdata = if_md[i - 1].ifmd_data;
+            return snpack(symon_buf, maxlen, st->arg, MT_IF,
+                          ifdata.ifi_ipackets,
+                          ifdata.ifi_opackets,
+                          ifdata.ifi_ibytes,
+                          ifdata.ifi_obytes,
+                          ifdata.ifi_imcasts,
+                          ifdata.ifi_omcasts,
+                          ifdata.ifi_ierrors,
+                          ifdata.ifi_oerrors,
+                          ifdata.ifi_collisions,
+                          ifdata.ifi_iqdrops);
+        }
     }
 
     return 0;

+ 22 - 22
symon/platform/FreeBSD/sm_io.c

@@ -1,4 +1,4 @@
-/* $Id: sm_io.c,v 1.4 2006/06/27 18:53:58 dijkstra Exp $ */
+/* $Id: sm_io.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 J. Martin Petersen
@@ -70,7 +70,7 @@ init_io(struct stream *st)
 {
     io_stats.dinfo = malloc(sizeof(struct devinfo));
     if (io_stats.dinfo == NULL) {
-	fatal("io: could not allocate memory");
+        fatal("io: could not allocate memory");
     }
 
     io_stats.dinfo->mem_ptr = NULL;
@@ -87,11 +87,11 @@ gets_io()
 #endif
 
     if (io_numdevs == -1) {
-	fatal("io: numdevs error");
+        fatal("io: numdevs error");
     }
 
     if (io_stats.dinfo->mem_ptr != NULL) {
-	free(io_stats.dinfo->mem_ptr);
+        free(io_stats.dinfo->mem_ptr);
     }
 
     /* clear the devinfo struct, as getdevs expects it to be all zeroes */
@@ -111,29 +111,29 @@ get_io(char *symon_buf, int maxlen, struct stream *st)
     struct devstat *ds;
 
     for (i=0; i < io_numdevs; i++) {
-	ds = &io_stats.dinfo->devices[i];
+        ds = &io_stats.dinfo->devices[i];
 
-	if (strncmp(ds->device_name, st->arg, strlen(ds->device_name)) == 0 &&
-	    strlen(ds->device_name) < strlen(st->arg) &&
-	    isdigit(st->arg[strlen(ds->device_name)]) &&
-	    atoi(&st->arg[strlen(ds->device_name)]) == ds->unit_number) {
+        if (strncmp(ds->device_name, st->arg, strlen(ds->device_name)) == 0 &&
+            strlen(ds->device_name) < strlen(st->arg) &&
+            isdigit(st->arg[strlen(ds->device_name)]) &&
+            atoi(&st->arg[strlen(ds->device_name)]) == ds->unit_number) {
 #if DEVSTAT_USER_API_VER >= 5
-	    return snpack(symon_buf, maxlen, st->arg, MT_IO2,
-			  ds->operations[DEVSTAT_READ],
-			  ds->operations[DEVSTAT_WRITE],
-			  (uint64_t) 0, /* don't know how to find #seeks */
-			  ds->bytes[DEVSTAT_READ],
-			  ds->bytes[DEVSTAT_WRITE]);
+            return snpack(symon_buf, maxlen, st->arg, MT_IO2,
+                          ds->operations[DEVSTAT_READ],
+                          ds->operations[DEVSTAT_WRITE],
+                          (uint64_t) 0, /* don't know how to find #seeks */
+                          ds->bytes[DEVSTAT_READ],
+                          ds->bytes[DEVSTAT_WRITE]);
 
 #else
-	    return snpack(symon_buf, maxlen, st->arg, MT_IO2,
-			  ds->num_reads,
-			  ds->num_writes,
-			  (uint64_t) 0, /* don't know how to find #seeks */
-			  ds->bytes_read,
-			  ds->bytes_written);
+            return snpack(symon_buf, maxlen, st->arg, MT_IO2,
+                          ds->num_reads,
+                          ds->num_writes,
+                          (uint64_t) 0, /* don't know how to find #seeks */
+                          ds->bytes_read,
+                          ds->bytes_written);
 #endif
-	}
+        }
     }
 
     return 0;

+ 51 - 51
symon/platform/FreeBSD/sm_mbuf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mbuf.c,v 1.5 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_mbuf.c,v 1.6 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004 Matthew Gream
@@ -51,8 +51,8 @@ init_mbuf(struct stream *st)
 {
     mbstat_len = CTL_MAXNAME;
     if (sysctlnametomib(mbstat_mib_str, mbstat_mib, &mbstat_len) < 0) {
-	warning("sysctlnametomib for mbuf failed");
-	mbstat_len = 0;
+        warning("sysctlnametomib for mbuf failed");
+        mbstat_len = 0;
     }
 
     info("started module mbuf(%.200s)", st->arg);
@@ -74,12 +74,12 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     u_int32_t stats[15];
 
     if (!mbstat_len)
-	return 0;
+        return 0;
 
     size = sizeof(mbstat);
     if (sysctl(mbstat_mib, mbstat_len, &mbstat, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return (0);
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return (0);
     }
 
 #ifdef KERN_POOL
@@ -88,40 +88,40 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     mib[2] = KERN_POOL_NPOOLS;
     size = sizeof(npools);
     if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return (0);
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return (0);
     }
 
     for (i = 1; npools; ++i) {
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_POOL;
-	mib[2] = KERN_POOL_POOL;
-	mib[3] = i;
-	size = sizeof(pool);
-	if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return (0);
-	}
-	npools--;
-	mib[2] = KERN_POOL_NAME;
-	size = sizeof(name);
-	if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return (0);
-	}
-	if (!strcmp(name, "mbpl")) {
-	    bcopy(&pool, &mbpool, sizeof(pool));
-	    flag |= 1;
-	} else if (!strcmp(name, "mclpl")) {
-	    bcopy(&pool, &mclpool, sizeof(pool));
-	    flag |= 2;
-	}
-	if (flag == 3)
-	    break;
+        mib[0] = CTL_KERN;
+        mib[1] = KERN_POOL;
+        mib[2] = KERN_POOL_POOL;
+        mib[3] = i;
+        size = sizeof(pool);
+        if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return (0);
+        }
+        npools--;
+        mib[2] = KERN_POOL_NAME;
+        size = sizeof(name);
+        if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return (0);
+        }
+        if (!strcmp(name, "mbpl")) {
+            bcopy(&pool, &mbpool, sizeof(pool));
+            flag |= 1;
+        } else if (!strcmp(name, "mclpl")) {
+            bcopy(&pool, &mclpool, sizeof(pool));
+            flag |= 2;
+        }
+        if (flag == 3)
+            break;
     }
     if (flag != 3) {
-	warning("mbuf(%.200s) failed (flag != 3)", st->arg);
-	return (0);
+        warning("mbuf(%.200s) failed (flag != 3)", st->arg);
+        return (0);
     }
 #endif
 
@@ -129,7 +129,7 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
 #ifdef KERN_POOL
     totmem = (mbpool.pr_npages + mclpool.pr_npages) * page_size;
     totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
-	(mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
+        (mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
 #else
     totmem = 0;
     totused = 0;
@@ -169,19 +169,19 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     stats[14] = mbstat.m_drain;
 
     return snpack(symon_buf, maxlen, st->arg, MT_MBUF,
-		  stats[0],
-		  stats[1],
-		  stats[2],
-		  stats[3],
-		  stats[4],
-		  stats[5],
-		  stats[6],
-		  stats[7],
-		  stats[8],
-		  stats[9],
-		  stats[10],
-		  stats[11],
-		  stats[12],
-		  stats[13],
-		  stats[14]);
+                  stats[0],
+                  stats[1],
+                  stats[2],
+                  stats[3],
+                  stats[4],
+                  stats[5],
+                  stats[6],
+                  stats[7],
+                  stats[8],
+                  stats[9],
+                  stats[10],
+                  stats[11],
+                  stats[12],
+                  stats[13],
+                  stats[14]);
 }

+ 20 - 20
symon/platform/FreeBSD/sm_mem.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mem.c,v 1.9 2006/06/27 18:53:58 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.10 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -79,20 +79,20 @@ init_mem(struct stream *st)
     me_pagesize = sysconf(_SC_PAGESIZE);
     me_pageshift = 0;
     while (me_pagesize > 1) {
-	me_pageshift++;
-	me_pagesize >>= 1;
+        me_pageshift++;
+        me_pagesize >>= 1;
     }
 
     me_vmnswp_mib_len = CTL_MAXNAME;
     if (sysctlnametomib(me_vmnswp_mib_str, me_vmnswp_mib_nam, &me_vmnswp_mib_len) < 0) {
-	warning("sysctlnametomib for nswapdev failed");
-	me_vmnswp_mib_len = 0;
+        warning("sysctlnametomib for nswapdev failed");
+        me_vmnswp_mib_len = 0;
     }
 
     me_vmiswp_mib_len = CTL_MAXNAME;
     if (sysctlnametomib(me_vmiswp_mib_str, me_vmiswp_mib_nam, &me_vmiswp_mib_len) < 0) {
-	warning("sysctlnametomib for swap_info failed");
-	me_vmiswp_mib_len = 0;
+        warning("sysctlnametomib for swap_info failed");
+        me_vmiswp_mib_len = 0;
     }
 
     info("started module mem(%.200s)", st->arg);
@@ -113,8 +113,8 @@ get_mem(char *symon_buf, int maxlen, struct stream *st)
 #endif
 
     if (sysctl(me_vm_mib, 2, &me_vmtotal, &me_vmsize, NULL, 0) < 0) {
-	warning("%s:%d: sysctl failed", __FILE__, __LINE__);
-	bzero(&me_vmtotal, sizeof(me_vmtotal));
+        warning("%s:%d: sysctl failed", __FILE__, __LINE__);
+        bzero(&me_vmtotal, sizeof(me_vmtotal));
     }
 
     /* convert memory stats to Kbytes */
@@ -126,21 +126,21 @@ get_mem(char *symon_buf, int maxlen, struct stream *st)
 #ifdef HAS_XSWDEV
     vmnswp_siz = sizeof (int);
     if (sysctl(me_vmnswp_mib_nam, me_vmnswp_mib_len, &vmnswp_dat, (void *)&vmnswp_siz, NULL, 0) < 0) {
-	warning("%s:%d: sysctl nswapdev failed", __FILE__, __LINE__);
-	vmnswp_dat = 0;
+        warning("%s:%d: sysctl nswapdev failed", __FILE__, __LINE__);
+        vmnswp_dat = 0;
     }
     for (i = 0; i < vmnswp_dat; i++) {
-	struct xswdev vmiswp_dat;
-	int vmiswp_siz = sizeof(vmiswp_dat);
-	me_vmiswp_mib_nam[me_vmiswp_mib_len] = i;
-	if (sysctl(me_vmiswp_mib_nam, me_vmiswp_mib_len + 1, &vmiswp_dat, (void *)&vmiswp_siz, NULL, 0) < 0)
-		continue;
-	me_stats[3] += pagetob(vmiswp_dat.xsw_used);
-	me_stats[4] += pagetob(vmiswp_dat.xsw_nblks);
+        struct xswdev vmiswp_dat;
+        int vmiswp_siz = sizeof(vmiswp_dat);
+        me_vmiswp_mib_nam[me_vmiswp_mib_len] = i;
+        if (sysctl(me_vmiswp_mib_nam, me_vmiswp_mib_len + 1, &vmiswp_dat, (void *)&vmiswp_siz, NULL, 0) < 0)
+                continue;
+        me_stats[3] += pagetob(vmiswp_dat.xsw_used);
+        me_stats[4] += pagetob(vmiswp_dat.xsw_nblks);
     }
 #endif
 
     return snpack(symon_buf, maxlen, st->arg, MT_MEM,
-		  me_stats[0], me_stats[1], me_stats[2],
-		  me_stats[3], me_stats[4]);
+                  me_stats[0], me_stats[1], me_stats[2],
+                  me_stats[3], me_stats[4]);
 }

+ 33 - 33
symon/platform/FreeBSD/sm_pf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_pf.c,v 1.5 2006/11/07 08:00:18 dijkstra Exp $ */
+/* $Id: sm_pf.c,v 1.6 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2002 Daniel Hartmeier
@@ -96,7 +96,7 @@ void
 privinit_pf()
 {
     if ((pf_dev = open("/dev/pf", O_RDONLY)) == -1) {
-	warning("could not open \"/dev/pf\", %.200s", strerror(errno));
+        warning("could not open \"/dev/pf\", %.200s", strerror(errno));
     }
 }
 
@@ -104,7 +104,7 @@ void
 init_pf(struct stream *st)
 {
     if (pf_dev == -1) {
-	privinit_pf();
+        privinit_pf();
     }
 
     info("started module pf()");
@@ -114,15 +114,15 @@ void
 gets_pf()
 {
     if (pf_dev == -1) {
-	warning("could not get pf stats (dev == -1)");
-	pf_stat.running = 0;
-	return;
+        warning("could not get pf stats (dev == -1)");
+        pf_stat.running = 0;
+        return;
     }
 
     if (ioctl(pf_dev, DIOCGETSTATUS, &pf_stat)) {
-	warning("could not get pf stats (ioctl error)");
-	pf_stat.running = 0;
-	return;
+        warning("could not get pf stats (ioctl error)");
+        pf_stat.running = 0;
+        return;
     }
 }
 
@@ -132,33 +132,33 @@ get_pf(char *symon_buf, int maxlen, struct stream *st)
     u_int64_t n;
 
     if (!pf_stat.running) {
-	return 0;
+        return 0;
     }
 
     n = pf_stat.states;
     return snpack(symon_buf, maxlen, st->arg, MT_PF,
-		  pf_stat.bcounters[0][0],
-		  pf_stat.bcounters[0][1],
-		  pf_stat.bcounters[1][0],
-		  pf_stat.bcounters[1][1],
-		  pf_stat.pcounters[0][0][PF_PASS],
-		  pf_stat.pcounters[0][0][PF_DROP],
-		  pf_stat.pcounters[0][1][PF_PASS],
-		  pf_stat.pcounters[0][1][PF_DROP],
-		  pf_stat.pcounters[1][0][PF_PASS],
-		  pf_stat.pcounters[1][0][PF_DROP],
-		  pf_stat.pcounters[1][1][PF_PASS],
-		  pf_stat.pcounters[1][1][PF_DROP],
-		  n,
-		  pf_stat.fcounters[0],
-		  pf_stat.fcounters[1],
-		  pf_stat.fcounters[2],
-		  pf_stat.counters[0],
-		  pf_stat.counters[1],
-		  pf_stat.counters[2],
-		  pf_stat.counters[3],
-		  pf_stat.counters[4],
-		  pf_stat.counters[5]
-	);
+                  pf_stat.bcounters[0][0],
+                  pf_stat.bcounters[0][1],
+                  pf_stat.bcounters[1][0],
+                  pf_stat.bcounters[1][1],
+                  pf_stat.pcounters[0][0][PF_PASS],
+                  pf_stat.pcounters[0][0][PF_DROP],
+                  pf_stat.pcounters[0][1][PF_PASS],
+                  pf_stat.pcounters[0][1][PF_DROP],
+                  pf_stat.pcounters[1][0][PF_PASS],
+                  pf_stat.pcounters[1][0][PF_DROP],
+                  pf_stat.pcounters[1][1][PF_PASS],
+                  pf_stat.pcounters[1][1][PF_DROP],
+                  n,
+                  pf_stat.fcounters[0],
+                  pf_stat.fcounters[1],
+                  pf_stat.fcounters[2],
+                  pf_stat.counters[0],
+                  pf_stat.counters[1],
+                  pf_stat.counters[2],
+                  pf_stat.counters[3],
+                  pf_stat.counters[4],
+                  pf_stat.counters[5]
+        );
 }
 #endif /* HAS_PFVAR_H */

+ 69 - 69
symon/platform/FreeBSD/sm_pfq.c

@@ -1,4 +1,4 @@
-/* $Id: sm_pfq.c,v 1.3 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_pfq.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 J. Martin Petersen
@@ -117,7 +117,7 @@ void
 privinit_pfq()
 {
     if ((pfq_dev = open("/dev/pf", O_RDONLY)) == -1) {
-	warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
+        warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
     }
 }
 
@@ -125,7 +125,7 @@ void
 init_pfq(struct stream *st)
 {
     if (pfq_dev == -1) {
-	privinit_pfq();
+        privinit_pfq();
     }
 
     info("started module pfq(%.200s)", st->arg);
@@ -145,78 +145,78 @@ gets_pfq()
     bzero(&q, sizeof(q));
 
     if (ioctl(pfq_dev, DIOCGETALTQS, &qs)) {
-	fatal("pfq: DIOCGETALTQS failed");
+        fatal("pfq: DIOCGETALTQS failed");
     }
     nqs = qs.nr;
 
     /* Allocate memory for info for the nqs queues */
     if (nqs > pfq_max) {
-	if (pfq_stats) {
-	    xfree(pfq_stats);
-	}
+        if (pfq_stats) {
+            xfree(pfq_stats);
+        }
 
-	pfq_max = 2 * nqs;
+        pfq_max = 2 * nqs;
 
-	if (pfq_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for pf queue structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (pfq_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for pf queue structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	pfq_stats = xmalloc(pfq_max * sizeof(struct altq_stats));
+        pfq_stats = xmalloc(pfq_max * sizeof(struct altq_stats));
     }
 
     pfq_cur = 0;
 
     /* Loop through the queues, copy info */
     for (i = 0; i < nqs; i++) {
-	qs.nr = i;
-	if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
-	    fatal("pfq: DIOCGETALTQ failed");
-	}
-
-	/* only process the non-empty queues */
-	if (qs.altq.qid > 0) {
-	    stats.nr = qs.nr;
-	    stats.ticket = qs.ticket;
-	    stats.buf = &q;
-	    stats.nbytes = sizeof(q);
-
-	    if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
-		fatal("pfq: DIOCGETQSTATS failed");
-	    }
-
-	    /* We're now ready to copy the data we want. */
-	    snprintf(pfq_stats[pfq_cur].qname, sizeof(pfq_stats[0].qname),
-		     "%s/%s", qs.altq.ifname, qs.altq.qname);
-
-	    switch (qs.altq.scheduler) {
-	    case ALTQT_CBQ:
-		pfq_stats[pfq_cur].sent_bytes = q.cbq.xmit_cnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.cbq.xmit_cnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.cbq.drop_cnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.cbq.drop_cnt.packets;
-		break;
-
-	    case ALTQT_PRIQ:
-		pfq_stats[pfq_cur].sent_bytes = q.priq.xmitcnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.priq.xmitcnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.priq.dropcnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.priq.dropcnt.packets;
-		break;
-
-	    case ALTQT_HFSC:
-		pfq_stats[pfq_cur].sent_bytes = q.hfsc.xmit_cnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.hfsc.xmit_cnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.hfsc.drop_cnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.hfsc.drop_cnt.packets;
-		break;
-
-	    default:
-		warning("pfq: unknown altq scheduler type encountered");
-		break;
-	    }
-	    pfq_cur++;
-	}
+        qs.nr = i;
+        if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
+            fatal("pfq: DIOCGETALTQ failed");
+        }
+
+        /* only process the non-empty queues */
+        if (qs.altq.qid > 0) {
+            stats.nr = qs.nr;
+            stats.ticket = qs.ticket;
+            stats.buf = &q;
+            stats.nbytes = sizeof(q);
+
+            if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
+                fatal("pfq: DIOCGETQSTATS failed");
+            }
+
+            /* We're now ready to copy the data we want. */
+            snprintf(pfq_stats[pfq_cur].qname, sizeof(pfq_stats[0].qname),
+                     "%s/%s", qs.altq.ifname, qs.altq.qname);
+
+            switch (qs.altq.scheduler) {
+            case ALTQT_CBQ:
+                pfq_stats[pfq_cur].sent_bytes = q.cbq.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.cbq.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.cbq.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.cbq.drop_cnt.packets;
+                break;
+
+            case ALTQT_PRIQ:
+                pfq_stats[pfq_cur].sent_bytes = q.priq.xmitcnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.priq.xmitcnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.priq.dropcnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.priq.dropcnt.packets;
+                break;
+
+            case ALTQT_HFSC:
+                pfq_stats[pfq_cur].sent_bytes = q.hfsc.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.hfsc.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.hfsc.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.hfsc.drop_cnt.packets;
+                break;
+
+            default:
+                warning("pfq: unknown altq scheduler type encountered");
+                break;
+            }
+            pfq_cur++;
+        }
     }
 }
 
@@ -226,14 +226,14 @@ get_pfq(char *symon_buf, int maxlen, struct stream *st)
     unsigned int i;
 
     for (i = 0; i < pfq_cur; i++) {
-	if (strncmp(pfq_stats[i].qname, st->arg, sizeof(pfq_stats[0].qname)) == 0) {
-	    return snpack(symon_buf, maxlen, st->arg, MT_PFQ,
-			  pfq_stats[i].sent_bytes,
-			  pfq_stats[i].sent_packets,
-			  pfq_stats[i].drop_bytes,
-			  pfq_stats[i].drop_packets
-		);
-	}
+        if (strncmp(pfq_stats[i].qname, st->arg, sizeof(pfq_stats[0].qname)) == 0) {
+            return snpack(symon_buf, maxlen, st->arg, MT_PFQ,
+                          pfq_stats[i].sent_bytes,
+                          pfq_stats[i].sent_packets,
+                          pfq_stats[i].drop_bytes,
+                          pfq_stats[i].drop_packets
+                );
+        }
     }
 
     return 0;

+ 62 - 62
symon/platform/FreeBSD/sm_proc.c

@@ -1,4 +1,4 @@
-/* $Id: sm_proc.c,v 1.7 2005/10/18 19:58:06 dijkstra Exp $ */
+/* $Id: sm_proc.c,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -84,20 +84,20 @@ gets_proc()
     mib[1] = KERN_MAXPROC;
     size = sizeof(procs);
     if (sysctl(mib, 2, &procs, &size, NULL, 0) < 0) {
-	fatal("%s:%d: sysctl failed: can't get kern.nproc",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: sysctl failed: can't get kern.nproc",
+              __FILE__, __LINE__);
     }
 
     /* increase buffers if necessary */
     if (procs > proc_max) {
-	proc_max = (procs * 5) / 4;
+        proc_max = (procs * 5) / 4;
 
-	if (proc_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (proc_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
+        proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
     }
 
     /* read data in anger */
@@ -106,17 +106,17 @@ gets_proc()
     mib[2] = KERN_PROC_ALL;
     size = proc_max * sizeof(struct kinfo_proc);
     if (sysctl(mib, 3, proc_ps, &size, NULL, 0) < 0) {
-	warning("proc probe cannot get processes");
-	proc_cur = 0;
-	return;
+        warning("proc probe cannot get processes");
+        proc_cur = 0;
+        return;
     }
 
     if (size % sizeof(struct kinfo_proc) != 0) {
-	warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
-		size, sizeof(struct kinfo_proc));
-	proc_cur = 0;
+        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
+                size, sizeof(struct kinfo_proc));
+        proc_cur = 0;
     } else {
-	proc_cur = size / sizeof(struct kinfo_proc);
+        proc_cur = size / sizeof(struct kinfo_proc);
     }
 }
 
@@ -128,7 +128,7 @@ privinit_proc()
 
     proc_kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
     if (proc_kd == NULL) {
-	warning("while opening kvm (chrooted?): %s", errbuf);
+        warning("while opening kvm (chrooted?): %s", errbuf);
     }
 #endif
 }
@@ -142,7 +142,7 @@ init_proc(struct stream *st)
 
     /* get clockrate */
     if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1) {
-	fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
+        fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
     }
 
     proc_stathz = cinf.stathz;
@@ -151,8 +151,8 @@ init_proc(struct stream *st)
     proc_pagesize = sysconf(_SC_PAGESIZE);
     proc_pageshift = 0;
     while (proc_pagesize > 1) {
-	proc_pageshift++;
-	proc_pagesize >>= 1;
+        proc_pageshift++;
+        proc_pagesize >>= 1;
     }
 
     info("started module proc(%.200s)", st->arg);
@@ -179,50 +179,50 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
 
     for (pp = proc_ps, i = 0; i < proc_cur; pp++, i++) {
 #ifdef HAS_KI_PADDR
-	if (strncmp(st->arg, pp->ki_comm, strlen(st->arg)) == 0) {
-	    /* cpu time - accumulated */
-	    if (proc_kd) {
-		if (kvm_read(proc_kd, (unsigned long)pp->ki_paddr, &pproc,
-			     sizeof(pproc)) == sizeof(pproc)) {
+        if (strncmp(st->arg, pp->ki_comm, strlen(st->arg)) == 0) {
+            /* cpu time - accumulated */
+            if (proc_kd) {
+                if (kvm_read(proc_kd, (unsigned long)pp->ki_paddr, &pproc,
+                             sizeof(pproc)) == sizeof(pproc)) {
 #ifdef HAS_RUSAGE_EXT
-		    cpu_uticks += pproc.p_rux.rux_uticks;  /* user */
-		    cpu_sticks += pproc.p_rux.rux_sticks;  /* sys  */
-		    cpu_iticks += pproc.p_rux.rux_iticks;  /* int  */
+                    cpu_uticks += pproc.p_rux.rux_uticks;  /* user */
+                    cpu_sticks += pproc.p_rux.rux_sticks;  /* sys  */
+                    cpu_iticks += pproc.p_rux.rux_iticks;  /* int  */
 #else
-		    cpu_uticks += pproc.p_uticks;  /* user */
-		    cpu_sticks += pproc.p_sticks;  /* sys  */
-		    cpu_iticks += pproc.p_iticks;  /* int  */
+                    cpu_uticks += pproc.p_uticks;  /* user */
+                    cpu_sticks += pproc.p_sticks;  /* sys  */
+                    cpu_iticks += pproc.p_iticks;  /* int  */
 #endif
-		} else {
-		    warning("while reading kvm: %s", kvm_geterr(proc_kd));
-		}
-	    }
-	    /* cpu time - percentage since last measurement */
-	    cpu_pct = pctdouble(pp->ki_pctcpu) * 100.0;
-	    cpu_pcti += cpu_pct;
-	    /* memory size - shared pages are counted multiple times */
-	    mem_procsize += pagetob(pp->ki_tsize + /* text pages */
-				    pp->ki_dsize + /* data */
-				    pp->ki_ssize); /* stack */
-	    mem_rss += pagetob(pp->ki_rssize);     /* rss  */
+                } else {
+                    warning("while reading kvm: %s", kvm_geterr(proc_kd));
+                }
+            }
+            /* cpu time - percentage since last measurement */
+            cpu_pct = pctdouble(pp->ki_pctcpu) * 100.0;
+            cpu_pcti += cpu_pct;
+            /* memory size - shared pages are counted multiple times */
+            mem_procsize += pagetob(pp->ki_tsize + /* text pages */
+                                    pp->ki_dsize + /* data */
+                                    pp->ki_ssize); /* stack */
+            mem_rss += pagetob(pp->ki_rssize);     /* rss  */
 #else
-	if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
-	    /* cpu time - accumulated */
-	    cpu_uticks += pp->kp_proc.p_uticks;  /* user */
-	    cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
-	    cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
-
-	    /* cpu time - percentage since last measurement */
-	    cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
-	    cpu_pcti += cpu_pct;
-	    /* memory size - shared pages are counted multiple times */
-	    mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
-				    pp->kp_eproc.e_vm.vm_dsize + /* data */
-				    pp->kp_eproc.e_vm.vm_ssize); /* stack */
-	    mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
+        if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
+            /* cpu time - accumulated */
+            cpu_uticks += pp->kp_proc.p_uticks;  /* user */
+            cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
+            cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
+
+            /* cpu time - percentage since last measurement */
+            cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
+            cpu_pcti += cpu_pct;
+            /* memory size - shared pages are counted multiple times */
+            mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
+                                    pp->kp_eproc.e_vm.vm_dsize + /* data */
+                                    pp->kp_eproc.e_vm.vm_ssize); /* stack */
+            mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
 #endif
-	    n++;
-	}
+            n++;
+        }
     }
 
     /* calc total cpu_secs spent */
@@ -230,7 +230,7 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     cpu_secs = cpu_ticks / proc_stathz;
 
     return snpack(symon_buf, maxlen, st->arg, MT_PROC,
-		  n,
-		  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
-		  mem_procsize, mem_rss );
+                  n,
+                  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
+                  mem_procsize, mem_rss );
 }

+ 7 - 7
symon/platform/Linux/platform.h

@@ -1,4 +1,4 @@
-/* $Id: platform.h,v 1.3 2005/10/21 14:58:44 dijkstra Exp $ */
+/* $Id: platform.h,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 #ifndef _CONF_LINUX_H
 #define _CONF_LINUX_H
@@ -16,7 +16,7 @@
 #define strlcpy(x,y,z)  snprintf((x),(z),"%s", (y))
 
 union semun {
-	int val;
+        int val;
 };
 
 #define CPUSTATES 4
@@ -27,11 +27,11 @@ union semun {
 
 union stream_parg {
     struct {
-	long time[CPUSTATES];
-	long old[CPUSTATES];
-	long diff[CPUSTATES];
-	int states[CPUSTATES];
-	char name[6];
+        long time[CPUSTATES];
+        long old[CPUSTATES];
+        long diff[CPUSTATES];
+        int states[CPUSTATES];
+        char name[6];
     } cp;
 };
 

+ 286 - 286
symon/platform/Linux/queue.h

@@ -1,9 +1,9 @@
-/*	$OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $	*/
-/*	$NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $	*/
+/*      $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $       */
+/*      $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $       */
 
 /*
  * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
+ *      The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,11 +29,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	@(#)queue.h	8.5 (Berkeley) 8/20/94
+ *      @(#)queue.h     8.5 (Berkeley) 8/20/94
  */
 
-#ifndef	_SYS_QUEUE_H_
-#define	_SYS_QUEUE_H_
+#ifndef _SYS_QUEUE_H_
+#define _SYS_QUEUE_H_
 
 /*
  * This file defines five types of data structures: singly-linked lists,
@@ -85,424 +85,424 @@
 /*
  * Singly-linked List definitions.
  */
-#define SLIST_HEAD(name, type)						\
-struct name {								\
-	struct type *slh_first;	/* first element */			\
+#define SLIST_HEAD(name, type)                                          \
+struct name {                                                           \
+        struct type *slh_first; /* first element */                     \
 }
 
-#define	SLIST_HEAD_INITIALIZER(head)					\
-	{ NULL }
+#define SLIST_HEAD_INITIALIZER(head)                                    \
+        { NULL }
 
-#define SLIST_ENTRY(type)						\
-struct {								\
-	struct type *sle_next;	/* next element */			\
+#define SLIST_ENTRY(type)                                               \
+struct {                                                                \
+        struct type *sle_next;  /* next element */                      \
 }
 
 /*
  * Singly-linked List access methods.
  */
-#define	SLIST_FIRST(head)	((head)->slh_first)
-#define	SLIST_END(head)		NULL
-#define	SLIST_EMPTY(head)	(SLIST_FIRST(head) == SLIST_END(head))
-#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
+#define SLIST_FIRST(head)       ((head)->slh_first)
+#define SLIST_END(head)         NULL
+#define SLIST_EMPTY(head)       (SLIST_FIRST(head) == SLIST_END(head))
+#define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
 
-#define	SLIST_FOREACH(var, head, field)					\
-	for((var) = SLIST_FIRST(head);					\
-	    (var) != SLIST_END(head);					\
-	    (var) = SLIST_NEXT(var, field))
+#define SLIST_FOREACH(var, head, field)                                 \
+        for((var) = SLIST_FIRST(head);                                  \
+            (var) != SLIST_END(head);                                   \
+            (var) = SLIST_NEXT(var, field))
 
-#define	SLIST_FOREACH_PREVPTR(var, varp, head, field)			\
-	for ((varp) = &SLIST_FIRST((head));				\
-	    ((var) = *(varp)) != SLIST_END(head);			\
-	    (varp) = &SLIST_NEXT((var), field))
+#define SLIST_FOREACH_PREVPTR(var, varp, head, field)                   \
+        for ((varp) = &SLIST_FIRST((head));                             \
+            ((var) = *(varp)) != SLIST_END(head);                       \
+            (varp) = &SLIST_NEXT((var), field))
 
 /*
  * Singly-linked List functions.
  */
-#define	SLIST_INIT(head) {						\
-	SLIST_FIRST(head) = SLIST_END(head);				\
+#define SLIST_INIT(head) {                                              \
+        SLIST_FIRST(head) = SLIST_END(head);                            \
 }
 
-#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\
-	(elm)->field.sle_next = (slistelm)->field.sle_next;		\
-	(slistelm)->field.sle_next = (elm);				\
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do {                   \
+        (elm)->field.sle_next = (slistelm)->field.sle_next;             \
+        (slistelm)->field.sle_next = (elm);                             \
 } while (0)
 
-#define	SLIST_INSERT_HEAD(head, elm, field) do {			\
-	(elm)->field.sle_next = (head)->slh_first;			\
-	(head)->slh_first = (elm);					\
+#define SLIST_INSERT_HEAD(head, elm, field) do {                        \
+        (elm)->field.sle_next = (head)->slh_first;                      \
+        (head)->slh_first = (elm);                                      \
 } while (0)
 
-#define	SLIST_REMOVE_NEXT(head, elm, field) do {			\
-	(elm)->field.sle_next = (elm)->field.sle_next->field.sle_next;	\
+#define SLIST_REMOVE_NEXT(head, elm, field) do {                        \
+        (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next;  \
 } while (0)
 
-#define	SLIST_REMOVE_HEAD(head, field) do {				\
-	(head)->slh_first = (head)->slh_first->field.sle_next;		\
+#define SLIST_REMOVE_HEAD(head, field) do {                             \
+        (head)->slh_first = (head)->slh_first->field.sle_next;          \
 } while (0)
 
-#define SLIST_REMOVE(head, elm, type, field) do {			\
-	if ((head)->slh_first == (elm)) {				\
-		SLIST_REMOVE_HEAD((head), field);			\
-	}								\
-	else {								\
-		struct type *curelm = (head)->slh_first;		\
-		while( curelm->field.sle_next != (elm) )		\
-			curelm = curelm->field.sle_next;		\
-		curelm->field.sle_next =				\
-		    curelm->field.sle_next->field.sle_next;		\
-	}								\
+#define SLIST_REMOVE(head, elm, type, field) do {                       \
+        if ((head)->slh_first == (elm)) {                               \
+                SLIST_REMOVE_HEAD((head), field);                       \
+        }                                                               \
+        else {                                                          \
+                struct type *curelm = (head)->slh_first;                \
+                while( curelm->field.sle_next != (elm) )                \
+                        curelm = curelm->field.sle_next;                \
+                curelm->field.sle_next =                                \
+                    curelm->field.sle_next->field.sle_next;             \
+        }                                                               \
 } while (0)
 
 /*
  * List definitions.
  */
-#define LIST_HEAD(name, type)						\
-struct name {								\
-	struct type *lh_first;	/* first element */			\
+#define LIST_HEAD(name, type)                                           \
+struct name {                                                           \
+        struct type *lh_first;  /* first element */                     \
 }
 
-#define LIST_HEAD_INITIALIZER(head)					\
-	{ NULL }
+#define LIST_HEAD_INITIALIZER(head)                                     \
+        { NULL }
 
-#define LIST_ENTRY(type)						\
-struct {								\
-	struct type *le_next;	/* next element */			\
-	struct type **le_prev;	/* address of previous next element */	\
+#define LIST_ENTRY(type)                                                \
+struct {                                                                \
+        struct type *le_next;   /* next element */                      \
+        struct type **le_prev;  /* address of previous next element */  \
 }
 
 /*
  * List access methods
  */
-#define	LIST_FIRST(head)		((head)->lh_first)
-#define	LIST_END(head)			NULL
-#define	LIST_EMPTY(head)		(LIST_FIRST(head) == LIST_END(head))
-#define	LIST_NEXT(elm, field)		((elm)->field.le_next)
+#define LIST_FIRST(head)                ((head)->lh_first)
+#define LIST_END(head)                  NULL
+#define LIST_EMPTY(head)                (LIST_FIRST(head) == LIST_END(head))
+#define LIST_NEXT(elm, field)           ((elm)->field.le_next)
 
-#define LIST_FOREACH(var, head, field)					\
-	for((var) = LIST_FIRST(head);					\
-	    (var)!= LIST_END(head);					\
-	    (var) = LIST_NEXT(var, field))
+#define LIST_FOREACH(var, head, field)                                  \
+        for((var) = LIST_FIRST(head);                                   \
+            (var)!= LIST_END(head);                                     \
+            (var) = LIST_NEXT(var, field))
 
 /*
  * List functions.
  */
-#define	LIST_INIT(head) do {						\
-	LIST_FIRST(head) = LIST_END(head);				\
+#define LIST_INIT(head) do {                                            \
+        LIST_FIRST(head) = LIST_END(head);                              \
 } while (0)
 
-#define LIST_INSERT_AFTER(listelm, elm, field) do {			\
-	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\
-		(listelm)->field.le_next->field.le_prev =		\
-		    &(elm)->field.le_next;				\
-	(listelm)->field.le_next = (elm);				\
-	(elm)->field.le_prev = &(listelm)->field.le_next;		\
+#define LIST_INSERT_AFTER(listelm, elm, field) do {                     \
+        if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
+                (listelm)->field.le_next->field.le_prev =               \
+                    &(elm)->field.le_next;                              \
+        (listelm)->field.le_next = (elm);                               \
+        (elm)->field.le_prev = &(listelm)->field.le_next;               \
 } while (0)
 
-#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
-	(elm)->field.le_prev = (listelm)->field.le_prev;		\
-	(elm)->field.le_next = (listelm);				\
-	*(listelm)->field.le_prev = (elm);				\
-	(listelm)->field.le_prev = &(elm)->field.le_next;		\
+#define LIST_INSERT_BEFORE(listelm, elm, field) do {                    \
+        (elm)->field.le_prev = (listelm)->field.le_prev;                \
+        (elm)->field.le_next = (listelm);                               \
+        *(listelm)->field.le_prev = (elm);                              \
+        (listelm)->field.le_prev = &(elm)->field.le_next;               \
 } while (0)
 
-#define LIST_INSERT_HEAD(head, elm, field) do {				\
-	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\
-		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
-	(head)->lh_first = (elm);					\
-	(elm)->field.le_prev = &(head)->lh_first;			\
+#define LIST_INSERT_HEAD(head, elm, field) do {                         \
+        if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
+                (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
+        (head)->lh_first = (elm);                                       \
+        (elm)->field.le_prev = &(head)->lh_first;                       \
 } while (0)
 
-#define LIST_REMOVE(elm, field) do {					\
-	if ((elm)->field.le_next != NULL)				\
-		(elm)->field.le_next->field.le_prev =			\
-		    (elm)->field.le_prev;				\
-	*(elm)->field.le_prev = (elm)->field.le_next;			\
+#define LIST_REMOVE(elm, field) do {                                    \
+        if ((elm)->field.le_next != NULL)                               \
+                (elm)->field.le_next->field.le_prev =                   \
+                    (elm)->field.le_prev;                               \
+        *(elm)->field.le_prev = (elm)->field.le_next;                   \
 } while (0)
 
-#define LIST_REPLACE(elm, elm2, field) do {				\
-	if (((elm2)->field.le_next = (elm)->field.le_next) != NULL)	\
-		(elm2)->field.le_next->field.le_prev =			\
-		    &(elm2)->field.le_next;				\
-	(elm2)->field.le_prev = (elm)->field.le_prev;			\
-	*(elm2)->field.le_prev = (elm2);				\
+#define LIST_REPLACE(elm, elm2, field) do {                             \
+        if (((elm2)->field.le_next = (elm)->field.le_next) != NULL)     \
+                (elm2)->field.le_next->field.le_prev =                  \
+                    &(elm2)->field.le_next;                             \
+        (elm2)->field.le_prev = (elm)->field.le_prev;                   \
+        *(elm2)->field.le_prev = (elm2);                                \
 } while (0)
 
 /*
  * Simple queue definitions.
  */
-#define SIMPLEQ_HEAD(name, type)					\
-struct name {								\
-	struct type *sqh_first;	/* first element */			\
-	struct type **sqh_last;	/* addr of last next element */		\
+#define SIMPLEQ_HEAD(name, type)                                        \
+struct name {                                                           \
+        struct type *sqh_first; /* first element */                     \
+        struct type **sqh_last; /* addr of last next element */         \
 }
 
-#define SIMPLEQ_HEAD_INITIALIZER(head)					\
-	{ NULL, &(head).sqh_first }
+#define SIMPLEQ_HEAD_INITIALIZER(head)                                  \
+        { NULL, &(head).sqh_first }
 
-#define SIMPLEQ_ENTRY(type)						\
-struct {								\
-	struct type *sqe_next;	/* next element */			\
+#define SIMPLEQ_ENTRY(type)                                             \
+struct {                                                                \
+        struct type *sqe_next;  /* next element */                      \
 }
 
 /*
  * Simple queue access methods.
  */
-#define	SIMPLEQ_FIRST(head)	    ((head)->sqh_first)
-#define	SIMPLEQ_END(head)	    NULL
-#define	SIMPLEQ_EMPTY(head)	    (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
-#define	SIMPLEQ_NEXT(elm, field)    ((elm)->field.sqe_next)
+#define SIMPLEQ_FIRST(head)         ((head)->sqh_first)
+#define SIMPLEQ_END(head)           NULL
+#define SIMPLEQ_EMPTY(head)         (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
+#define SIMPLEQ_NEXT(elm, field)    ((elm)->field.sqe_next)
 
-#define SIMPLEQ_FOREACH(var, head, field)				\
-	for((var) = SIMPLEQ_FIRST(head);				\
-	    (var) != SIMPLEQ_END(head);					\
-	    (var) = SIMPLEQ_NEXT(var, field))
+#define SIMPLEQ_FOREACH(var, head, field)                               \
+        for((var) = SIMPLEQ_FIRST(head);                                \
+            (var) != SIMPLEQ_END(head);                                 \
+            (var) = SIMPLEQ_NEXT(var, field))
 
 /*
  * Simple queue functions.
  */
-#define	SIMPLEQ_INIT(head) do {						\
-	(head)->sqh_first = NULL;					\
-	(head)->sqh_last = &(head)->sqh_first;				\
+#define SIMPLEQ_INIT(head) do {                                         \
+        (head)->sqh_first = NULL;                                       \
+        (head)->sqh_last = &(head)->sqh_first;                          \
 } while (0)
 
-#define SIMPLEQ_INSERT_HEAD(head, elm, field) do {			\
-	if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)	\
-		(head)->sqh_last = &(elm)->field.sqe_next;		\
-	(head)->sqh_first = (elm);					\
+#define SIMPLEQ_INSERT_HEAD(head, elm, field) do {                      \
+        if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)        \
+                (head)->sqh_last = &(elm)->field.sqe_next;              \
+        (head)->sqh_first = (elm);                                      \
 } while (0)
 
-#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {			\
-	(elm)->field.sqe_next = NULL;					\
-	*(head)->sqh_last = (elm);					\
-	(head)->sqh_last = &(elm)->field.sqe_next;			\
+#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {                      \
+        (elm)->field.sqe_next = NULL;                                   \
+        *(head)->sqh_last = (elm);                                      \
+        (head)->sqh_last = &(elm)->field.sqe_next;                      \
 } while (0)
 
-#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\
-	if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
-		(head)->sqh_last = &(elm)->field.sqe_next;		\
-	(listelm)->field.sqe_next = (elm);				\
+#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
+        if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
+                (head)->sqh_last = &(elm)->field.sqe_next;              \
+        (listelm)->field.sqe_next = (elm);                              \
 } while (0)
 
-#define SIMPLEQ_REMOVE_HEAD(head, field) do {			\
-	if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
-		(head)->sqh_last = &(head)->sqh_first;			\
+#define SIMPLEQ_REMOVE_HEAD(head, field) do {                   \
+        if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
+                (head)->sqh_last = &(head)->sqh_first;                  \
 } while (0)
 
 /*
  * Tail queue definitions.
  */
-#define TAILQ_HEAD(name, type)						\
-struct name {								\
-	struct type *tqh_first;	/* first element */			\
-	struct type **tqh_last;	/* addr of last next element */		\
+#define TAILQ_HEAD(name, type)                                          \
+struct name {                                                           \
+        struct type *tqh_first; /* first element */                     \
+        struct type **tqh_last; /* addr of last next element */         \
 }
 
-#define TAILQ_HEAD_INITIALIZER(head)					\
-	{ NULL, &(head).tqh_first }
+#define TAILQ_HEAD_INITIALIZER(head)                                    \
+        { NULL, &(head).tqh_first }
 
-#define TAILQ_ENTRY(type)						\
-struct {								\
-	struct type *tqe_next;	/* next element */			\
-	struct type **tqe_prev;	/* address of previous next element */	\
+#define TAILQ_ENTRY(type)                                               \
+struct {                                                                \
+        struct type *tqe_next;  /* next element */                      \
+        struct type **tqe_prev; /* address of previous next element */  \
 }
 
 /*
  * tail queue access methods
  */
-#define	TAILQ_FIRST(head)		((head)->tqh_first)
-#define	TAILQ_END(head)			NULL
-#define	TAILQ_NEXT(elm, field)		((elm)->field.tqe_next)
-#define TAILQ_LAST(head, headname)					\
-	(*(((struct headname *)((head)->tqh_last))->tqh_last))
+#define TAILQ_FIRST(head)               ((head)->tqh_first)
+#define TAILQ_END(head)                 NULL
+#define TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname)                                      \
+        (*(((struct headname *)((head)->tqh_last))->tqh_last))
 /* XXX */
-#define TAILQ_PREV(elm, headname, field)				\
-	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
-#define	TAILQ_EMPTY(head)						\
-	(TAILQ_FIRST(head) == TAILQ_END(head))
+#define TAILQ_PREV(elm, headname, field)                                \
+        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define TAILQ_EMPTY(head)                                               \
+        (TAILQ_FIRST(head) == TAILQ_END(head))
 
-#define TAILQ_FOREACH(var, head, field)					\
-	for((var) = TAILQ_FIRST(head);					\
-	    (var) != TAILQ_END(head);					\
-	    (var) = TAILQ_NEXT(var, field))
+#define TAILQ_FOREACH(var, head, field)                                 \
+        for((var) = TAILQ_FIRST(head);                                  \
+            (var) != TAILQ_END(head);                                   \
+            (var) = TAILQ_NEXT(var, field))
 
-#define TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
-	for((var) = TAILQ_LAST(head, headname);				\
-	    (var) != TAILQ_END(head);					\
-	    (var) = TAILQ_PREV(var, headname, field))
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
+        for((var) = TAILQ_LAST(head, headname);                         \
+            (var) != TAILQ_END(head);                                   \
+            (var) = TAILQ_PREV(var, headname, field))
 
 /*
  * Tail queue functions.
  */
-#define	TAILQ_INIT(head) do {						\
-	(head)->tqh_first = NULL;					\
-	(head)->tqh_last = &(head)->tqh_first;				\
+#define TAILQ_INIT(head) do {                                           \
+        (head)->tqh_first = NULL;                                       \
+        (head)->tqh_last = &(head)->tqh_first;                          \
 } while (0)
 
-#define TAILQ_INSERT_HEAD(head, elm, field) do {			\
-	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\
-		(head)->tqh_first->field.tqe_prev =			\
-		    &(elm)->field.tqe_next;				\
-	else								\
-		(head)->tqh_last = &(elm)->field.tqe_next;		\
-	(head)->tqh_first = (elm);					\
-	(elm)->field.tqe_prev = &(head)->tqh_first;			\
+#define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
+        if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)        \
+                (head)->tqh_first->field.tqe_prev =                     \
+                    &(elm)->field.tqe_next;                             \
+        else                                                            \
+                (head)->tqh_last = &(elm)->field.tqe_next;              \
+        (head)->tqh_first = (elm);                                      \
+        (elm)->field.tqe_prev = &(head)->tqh_first;                     \
 } while (0)
 
-#define TAILQ_INSERT_TAIL(head, elm, field) do {			\
-	(elm)->field.tqe_next = NULL;					\
-	(elm)->field.tqe_prev = (head)->tqh_last;			\
-	*(head)->tqh_last = (elm);					\
-	(head)->tqh_last = &(elm)->field.tqe_next;			\
+#define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
+        (elm)->field.tqe_next = NULL;                                   \
+        (elm)->field.tqe_prev = (head)->tqh_last;                       \
+        *(head)->tqh_last = (elm);                                      \
+        (head)->tqh_last = &(elm)->field.tqe_next;                      \
 } while (0)
 
-#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
-	if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
-		(elm)->field.tqe_next->field.tqe_prev =			\
-		    &(elm)->field.tqe_next;				\
-	else								\
-		(head)->tqh_last = &(elm)->field.tqe_next;		\
-	(listelm)->field.tqe_next = (elm);				\
-	(elm)->field.tqe_prev = &(listelm)->field.tqe_next;		\
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
+        if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+                (elm)->field.tqe_next->field.tqe_prev =                 \
+                    &(elm)->field.tqe_next;                             \
+        else                                                            \
+                (head)->tqh_last = &(elm)->field.tqe_next;              \
+        (listelm)->field.tqe_next = (elm);                              \
+        (elm)->field.tqe_prev = &(listelm)->field.tqe_next;             \
 } while (0)
 
-#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
-	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\
-	(elm)->field.tqe_next = (listelm);				\
-	*(listelm)->field.tqe_prev = (elm);				\
-	(listelm)->field.tqe_prev = &(elm)->field.tqe_next;		\
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
+        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
+        (elm)->field.tqe_next = (listelm);                              \
+        *(listelm)->field.tqe_prev = (elm);                             \
+        (listelm)->field.tqe_prev = &(elm)->field.tqe_next;             \
 } while (0)
 
-#define TAILQ_REMOVE(head, elm, field) do {				\
-	if (((elm)->field.tqe_next) != NULL)				\
-		(elm)->field.tqe_next->field.tqe_prev =			\
-		    (elm)->field.tqe_prev;				\
-	else								\
-		(head)->tqh_last = (elm)->field.tqe_prev;		\
-	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\
+#define TAILQ_REMOVE(head, elm, field) do {                             \
+        if (((elm)->field.tqe_next) != NULL)                            \
+                (elm)->field.tqe_next->field.tqe_prev =                 \
+                    (elm)->field.tqe_prev;                              \
+        else                                                            \
+                (head)->tqh_last = (elm)->field.tqe_prev;               \
+        *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
 } while (0)
 
-#define TAILQ_REPLACE(head, elm, elm2, field) do {			\
-	if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL)	\
-		(elm2)->field.tqe_next->field.tqe_prev =		\
-		    &(elm2)->field.tqe_next;				\
-	else								\
-		(head)->tqh_last = &(elm2)->field.tqe_next;		\
-	(elm2)->field.tqe_prev = (elm)->field.tqe_prev;			\
-	*(elm2)->field.tqe_prev = (elm2);				\
+#define TAILQ_REPLACE(head, elm, elm2, field) do {                      \
+        if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL)   \
+                (elm2)->field.tqe_next->field.tqe_prev =                \
+                    &(elm2)->field.tqe_next;                            \
+        else                                                            \
+                (head)->tqh_last = &(elm2)->field.tqe_next;             \
+        (elm2)->field.tqe_prev = (elm)->field.tqe_prev;                 \
+        *(elm2)->field.tqe_prev = (elm2);                               \
 } while (0)
 
 /*
  * Circular queue definitions.
  */
-#define CIRCLEQ_HEAD(name, type)					\
-struct name {								\
-	struct type *cqh_first;		/* first element */		\
-	struct type *cqh_last;		/* last element */		\
+#define CIRCLEQ_HEAD(name, type)                                        \
+struct name {                                                           \
+        struct type *cqh_first;         /* first element */             \
+        struct type *cqh_last;          /* last element */              \
 }
 
-#define CIRCLEQ_HEAD_INITIALIZER(head)					\
-	{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
+#define CIRCLEQ_HEAD_INITIALIZER(head)                                  \
+        { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
 
-#define CIRCLEQ_ENTRY(type)						\
-struct {								\
-	struct type *cqe_next;		/* next element */		\
-	struct type *cqe_prev;		/* previous element */		\
+#define CIRCLEQ_ENTRY(type)                                             \
+struct {                                                                \
+        struct type *cqe_next;          /* next element */              \
+        struct type *cqe_prev;          /* previous element */          \
 }
 
 /*
  * Circular queue access methods
  */
-#define	CIRCLEQ_FIRST(head)		((head)->cqh_first)
-#define	CIRCLEQ_LAST(head)		((head)->cqh_last)
-#define	CIRCLEQ_END(head)		((void *)(head))
-#define	CIRCLEQ_NEXT(elm, field)	((elm)->field.cqe_next)
-#define	CIRCLEQ_PREV(elm, field)	((elm)->field.cqe_prev)
-#define	CIRCLEQ_EMPTY(head)						\
-	(CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
-
-#define CIRCLEQ_FOREACH(var, head, field)				\
-	for((var) = CIRCLEQ_FIRST(head);				\
-	    (var) != CIRCLEQ_END(head);					\
-	    (var) = CIRCLEQ_NEXT(var, field))
-
-#define CIRCLEQ_FOREACH_REVERSE(var, head, field)			\
-	for((var) = CIRCLEQ_LAST(head);					\
-	    (var) != CIRCLEQ_END(head);					\
-	    (var) = CIRCLEQ_PREV(var, field))
+#define CIRCLEQ_FIRST(head)             ((head)->cqh_first)
+#define CIRCLEQ_LAST(head)              ((head)->cqh_last)
+#define CIRCLEQ_END(head)               ((void *)(head))
+#define CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
+#define CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
+#define CIRCLEQ_EMPTY(head)                                             \
+        (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
+
+#define CIRCLEQ_FOREACH(var, head, field)                               \
+        for((var) = CIRCLEQ_FIRST(head);                                \
+            (var) != CIRCLEQ_END(head);                                 \
+            (var) = CIRCLEQ_NEXT(var, field))
+
+#define CIRCLEQ_FOREACH_REVERSE(var, head, field)                       \
+        for((var) = CIRCLEQ_LAST(head);                                 \
+            (var) != CIRCLEQ_END(head);                                 \
+            (var) = CIRCLEQ_PREV(var, field))
 
 /*
  * Circular queue functions.
  */
-#define	CIRCLEQ_INIT(head) do {						\
-	(head)->cqh_first = CIRCLEQ_END(head);				\
-	(head)->cqh_last = CIRCLEQ_END(head);				\
+#define CIRCLEQ_INIT(head) do {                                         \
+        (head)->cqh_first = CIRCLEQ_END(head);                          \
+        (head)->cqh_last = CIRCLEQ_END(head);                           \
 } while (0)
 
-#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\
-	(elm)->field.cqe_next = (listelm)->field.cqe_next;		\
-	(elm)->field.cqe_prev = (listelm);				\
-	if ((listelm)->field.cqe_next == CIRCLEQ_END(head))		\
-		(head)->cqh_last = (elm);				\
-	else								\
-		(listelm)->field.cqe_next->field.cqe_prev = (elm);	\
-	(listelm)->field.cqe_next = (elm);				\
+#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do {            \
+        (elm)->field.cqe_next = (listelm)->field.cqe_next;              \
+        (elm)->field.cqe_prev = (listelm);                              \
+        if ((listelm)->field.cqe_next == CIRCLEQ_END(head))             \
+                (head)->cqh_last = (elm);                               \
+        else                                                            \
+                (listelm)->field.cqe_next->field.cqe_prev = (elm);      \
+        (listelm)->field.cqe_next = (elm);                              \
 } while (0)
 
-#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {		\
-	(elm)->field.cqe_next = (listelm);				\
-	(elm)->field.cqe_prev = (listelm)->field.cqe_prev;		\
-	if ((listelm)->field.cqe_prev == CIRCLEQ_END(head))		\
-		(head)->cqh_first = (elm);				\
-	else								\
-		(listelm)->field.cqe_prev->field.cqe_next = (elm);	\
-	(listelm)->field.cqe_prev = (elm);				\
+#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do {           \
+        (elm)->field.cqe_next = (listelm);                              \
+        (elm)->field.cqe_prev = (listelm)->field.cqe_prev;              \
+        if ((listelm)->field.cqe_prev == CIRCLEQ_END(head))             \
+                (head)->cqh_first = (elm);                              \
+        else                                                            \
+                (listelm)->field.cqe_prev->field.cqe_next = (elm);      \
+        (listelm)->field.cqe_prev = (elm);                              \
 } while (0)
 
-#define CIRCLEQ_INSERT_HEAD(head, elm, field) do {			\
-	(elm)->field.cqe_next = (head)->cqh_first;			\
-	(elm)->field.cqe_prev = CIRCLEQ_END(head);			\
-	if ((head)->cqh_last == CIRCLEQ_END(head))			\
-		(head)->cqh_last = (elm);				\
-	else								\
-		(head)->cqh_first->field.cqe_prev = (elm);		\
-	(head)->cqh_first = (elm);					\
+#define CIRCLEQ_INSERT_HEAD(head, elm, field) do {                      \
+        (elm)->field.cqe_next = (head)->cqh_first;                      \
+        (elm)->field.cqe_prev = CIRCLEQ_END(head);                      \
+        if ((head)->cqh_last == CIRCLEQ_END(head))                      \
+                (head)->cqh_last = (elm);                               \
+        else                                                            \
+                (head)->cqh_first->field.cqe_prev = (elm);              \
+        (head)->cqh_first = (elm);                                      \
 } while (0)
 
-#define CIRCLEQ_INSERT_TAIL(head, elm, field) do {			\
-	(elm)->field.cqe_next = CIRCLEQ_END(head);			\
-	(elm)->field.cqe_prev = (head)->cqh_last;			\
-	if ((head)->cqh_first == CIRCLEQ_END(head))			\
-		(head)->cqh_first = (elm);				\
-	else								\
-		(head)->cqh_last->field.cqe_next = (elm);		\
-	(head)->cqh_last = (elm);					\
+#define CIRCLEQ_INSERT_TAIL(head, elm, field) do {                      \
+        (elm)->field.cqe_next = CIRCLEQ_END(head);                      \
+        (elm)->field.cqe_prev = (head)->cqh_last;                       \
+        if ((head)->cqh_first == CIRCLEQ_END(head))                     \
+                (head)->cqh_first = (elm);                              \
+        else                                                            \
+                (head)->cqh_last->field.cqe_next = (elm);               \
+        (head)->cqh_last = (elm);                                       \
 } while (0)
 
-#define	CIRCLEQ_REMOVE(head, elm, field) do {				\
-	if ((elm)->field.cqe_next == CIRCLEQ_END(head))			\
-		(head)->cqh_last = (elm)->field.cqe_prev;		\
-	else								\
-		(elm)->field.cqe_next->field.cqe_prev =			\
-		    (elm)->field.cqe_prev;				\
-	if ((elm)->field.cqe_prev == CIRCLEQ_END(head))			\
-		(head)->cqh_first = (elm)->field.cqe_next;		\
-	else								\
-		(elm)->field.cqe_prev->field.cqe_next =			\
-		    (elm)->field.cqe_next;				\
+#define CIRCLEQ_REMOVE(head, elm, field) do {                           \
+        if ((elm)->field.cqe_next == CIRCLEQ_END(head))                 \
+                (head)->cqh_last = (elm)->field.cqe_prev;               \
+        else                                                            \
+                (elm)->field.cqe_next->field.cqe_prev =                 \
+                    (elm)->field.cqe_prev;                              \
+        if ((elm)->field.cqe_prev == CIRCLEQ_END(head))                 \
+                (head)->cqh_first = (elm)->field.cqe_next;              \
+        else                                                            \
+                (elm)->field.cqe_prev->field.cqe_next =                 \
+                    (elm)->field.cqe_next;                              \
 } while (0)
 
-#define CIRCLEQ_REPLACE(head, elm, elm2, field) do {			\
-	if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==		\
-	    CIRCLEQ_END(head))						\
-		(head).cqh_last = (elm2);				\
-	else								\
-		(elm2)->field.cqe_next->field.cqe_prev = (elm2);	\
-	if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==		\
-	    CIRCLEQ_END(head))						\
-		(head).cqh_first = (elm2);				\
-	else								\
-		(elm2)->field.cqe_prev->field.cqe_next = (elm2);	\
+#define CIRCLEQ_REPLACE(head, elm, elm2, field) do {                    \
+        if (((elm2)->field.cqe_next = (elm)->field.cqe_next) ==         \
+            CIRCLEQ_END(head))                                          \
+                (head).cqh_last = (elm2);                               \
+        else                                                            \
+                (elm2)->field.cqe_next->field.cqe_prev = (elm2);        \
+        if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) ==         \
+            CIRCLEQ_END(head))                                          \
+                (head).cqh_first = (elm2);                              \
+        else                                                            \
+                (elm2)->field.cqe_prev->field.cqe_next = (elm2);        \
 } while (0)
 
-#endif	/* !_SYS_QUEUE_H_ */
+#endif  /* !_SYS_QUEUE_H_ */

+ 40 - 40
symon/platform/Linux/sm_cpu.c

@@ -1,4 +1,4 @@
-/* $Id: sm_cpu.c,v 1.4 2005/10/21 14:58:44 dijkstra Exp $ */
+/* $Id: sm_cpu.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /* The author of this code is Willem Dijkstra (wpd@xs4all.nl).
  *
@@ -99,22 +99,22 @@ percentages(int cnt, int *out, register long *new, register long *old, long *dif
 
     /* calculate changes for each state and the overall change */
     for (i = 0; i < cnt; i++) {
-	if ((change = *new - *old) < 0) {
-	    /* this only happens when the counter wraps */
-	    change = ((unsigned int) *new - (unsigned int) *old);
-	}
-	total_change += (*dp++ = change);
-	*old++ = *new++;
+        if ((change = *new - *old) < 0) {
+            /* this only happens when the counter wraps */
+            change = ((unsigned int) *new - (unsigned int) *old);
+        }
+        total_change += (*dp++ = change);
+        *old++ = *new++;
     }
 
     /* avoid divide by zero potential */
     if (total_change == 0)
-	total_change = 1;
+        total_change = 1;
 
     /* calculate percentages based on overall change, rounding up */
     half_total = total_change / 2l;
     for (i = 0; i < cnt; i++)
-	*out++ = ((*diffs++ * 1000 + half_total) / total_change);
+        *out++ = ((*diffs++ * 1000 + half_total) / total_change);
 
     /* return the total in case the caller wants to use it */
     return total_change;
@@ -126,14 +126,14 @@ init_cpu(struct stream *st)
     char buf[SYMON_MAX_OBJSIZE];
 
     if (cp_buf == NULL) {
-	cp_maxsize = SYMON_MAX_OBJSIZE;
-	cp_buf = xmalloc(cp_maxsize);
+        cp_maxsize = SYMON_MAX_OBJSIZE;
+        cp_buf = xmalloc(cp_maxsize);
     }
 
     if (st->arg != NULL && isdigit(*st->arg)) {
-	snprintf(st->parg.cp.name, sizeof(st->parg.cp.name), "cpu%s", st->arg);
+        snprintf(st->parg.cp.name, sizeof(st->parg.cp.name), "cpu%s", st->arg);
     } else {
-	snprintf(st->parg.cp.name, sizeof(st->parg.cp.name), "cpu");
+        snprintf(st->parg.cp.name, sizeof(st->parg.cp.name), "cpu");
     }
 
     gets_cpu();
@@ -148,8 +148,8 @@ gets_cpu()
     int fd;
 
     if ((fd = open("/proc/stat", O_RDONLY)) < 0) {
-	warning("cannot access /proc/stat: %.200s", strerror(errno));
-	return;
+        warning("cannot access /proc/stat: %.200s", strerror(errno));
+        return;
     }
 
     bzero(cp_buf, cp_maxsize);
@@ -157,19 +157,19 @@ gets_cpu()
     close(fd);
 
     if (cp_size == cp_maxsize) {
-	/* buffer is too small to hold all interface data */
-	cp_maxsize += SYMON_MAX_OBJSIZE;
-	if (cp_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for cp data",
-		  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
-	}
-	cp_buf = xrealloc(cp_buf, cp_maxsize);
-	gets_cpu();
-	return;
+        /* buffer is too small to hold all interface data */
+        cp_maxsize += SYMON_MAX_OBJSIZE;
+        if (cp_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for cp data",
+                  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
+        }
+        cp_buf = xrealloc(cp_buf, cp_maxsize);
+        gets_cpu();
+        return;
     }
 
     if (cp_size == -1) {
-	warning("could not read if statistics from /proc/stat: %.200s", strerror(errno));
+        warning("could not read if statistics from /proc/stat: %.200s", strerror(errno));
     }
 }
 
@@ -179,31 +179,31 @@ get_cpu(char *symon_buf, int maxlen, struct stream *st)
     char *line;
 
     if (cp_size <= 0) {
-	return 0;
+        return 0;
     }
 
     if ((line = strstr(cp_buf, st->parg.cp.name)) == NULL) {
-	warning("could not find %s", st->parg.cp.name);
-	return 0;
+        warning("could not find %s", st->parg.cp.name);
+        return 0;
     }
 
     line += strlen(st->parg.cp.name);
     if (4 > sscanf(line, "%lu %lu %lu %lu\n",
-		   &st->parg.cp.time[CP_USER],
-		   &st->parg.cp.time[CP_NICE],
-		   &st->parg.cp.time[CP_SYS],
-		   &st->parg.cp.time[CP_IDLE])) {
-	warning("could not parse cpu statistics for %.200s", &st->parg.cp.name);
-	return 0;
+                   &st->parg.cp.time[CP_USER],
+                   &st->parg.cp.time[CP_NICE],
+                   &st->parg.cp.time[CP_SYS],
+                   &st->parg.cp.time[CP_IDLE])) {
+        warning("could not parse cpu statistics for %.200s", &st->parg.cp.name);
+        return 0;
     }
 
     percentages(CPUSTATES, st->parg.cp.states, st->parg.cp.time,
-		st->parg.cp.old, st->parg.cp.diff);
+                st->parg.cp.old, st->parg.cp.diff);
 
     return snpack(symon_buf, maxlen, st->arg, MT_CPU,
-		  (double) (st->parg.cp.states[CP_USER] / 10.0),
-		  (double) (st->parg.cp.states[CP_NICE] / 10.0),
-		  (double) (st->parg.cp.states[CP_SYS] / 10.0),
-		  (double) (0),
-		  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
+                  (double) (st->parg.cp.states[CP_USER] / 10.0),
+                  (double) (st->parg.cp.states[CP_NICE] / 10.0),
+                  (double) (st->parg.cp.states[CP_SYS] / 10.0),
+                  (double) (0),
+                  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
 }

+ 34 - 34
symon/platform/Linux/sm_if.c

@@ -1,4 +1,4 @@
-/* $Id: sm_if.c,v 1.6 2005/10/19 20:06:05 dijkstra Exp $ */
+/* $Id: sm_if.c,v 1.7 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -78,8 +78,8 @@ void
 init_if(struct stream *st)
 {
     if (if_buf == NULL) {
-	if_maxsize = SYMON_MAX_OBJSIZE;
-	if_buf = xmalloc(if_maxsize);
+        if_maxsize = SYMON_MAX_OBJSIZE;
+        if_buf = xmalloc(if_maxsize);
     }
 
     info("started module if(%.200s)", st->arg);
@@ -91,8 +91,8 @@ gets_if()
     int fd;
 
     if ((fd = open("/proc/net/dev", O_RDONLY)) < 0) {
-	warning("cannot access /proc/net/dev: %.200s", strerror(errno));
-	return;
+        warning("cannot access /proc/net/dev: %.200s", strerror(errno));
+        return;
     }
 
     bzero(if_buf, if_maxsize);
@@ -100,19 +100,19 @@ gets_if()
     close(fd);
 
     if (if_size == if_maxsize) {
-	/* buffer is too small to hold all interface data */
-	if_maxsize += SYMON_MAX_OBJSIZE;
-	if (if_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for if data",
-		  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
-	}
-	if_buf = xrealloc(if_buf, if_maxsize);
-	gets_if();
-	return;
+        /* buffer is too small to hold all interface data */
+        if_maxsize += SYMON_MAX_OBJSIZE;
+        if (if_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for if data",
+                  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
+        }
+        if_buf = xrealloc(if_buf, if_maxsize);
+        gets_if();
+        return;
     }
 
     if (if_size == -1) {
-	warning("could not read if statistics from /proc/net/dev: %.200s", strerror(errno));
+        warning("could not read if statistics from /proc/net/dev: %.200s", strerror(errno));
     }
 }
 
@@ -123,12 +123,12 @@ get_if(char *symon_buf, int maxlen, struct stream *st)
     struct if_device_stats stats;
 
     if (if_size <= 0) {
-	return 0;
+        return 0;
     }
 
     if ((line = strstr(if_buf, st->arg)) == NULL) {
-	warning("could not find interface %s", st->arg);
-	return 0;
+        warning("could not find interface %s", st->arg);
+        return 0;
     }
 
     line += strlen(st->arg);
@@ -138,23 +138,23 @@ get_if(char *symon_buf, int maxlen, struct stream *st)
      *  face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
      */
     if (16 > sscanf(line, ":%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
-		    &stats.rx_bytes, &stats.rx_packets, &stats.rx_errors, &stats.rx_dropped, &stats.rx_fifo_errors,
-		    &stats.rx_frame_errors, &stats.rx_compressed, &stats.multicast,
-		    &stats.tx_bytes, &stats.tx_packets, &stats.tx_errors, &stats.tx_dropped, &stats.tx_fifo_errors,
-		    &stats.collisions, &stats.tx_carrier_errors, &stats.tx_compressed)) {
-	warning("could not parse interface statistics for %.200s", st->arg);
-	return 0;
+                    &stats.rx_bytes, &stats.rx_packets, &stats.rx_errors, &stats.rx_dropped, &stats.rx_fifo_errors,
+                    &stats.rx_frame_errors, &stats.rx_compressed, &stats.multicast,
+                    &stats.tx_bytes, &stats.tx_packets, &stats.tx_errors, &stats.tx_dropped, &stats.tx_fifo_errors,
+                    &stats.collisions, &stats.tx_carrier_errors, &stats.tx_compressed)) {
+        warning("could not parse interface statistics for %.200s", st->arg);
+        return 0;
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_IF,
-		  stats.rx_packets,
-		  stats.tx_packets,
-		  stats.rx_bytes,
-		  stats.tx_bytes,
-		  stats.multicast,
-		  0,
-		  (stats.rx_errors + stats.rx_fifo_errors + stats.rx_frame_errors),
-		  (stats.tx_errors + stats.tx_fifo_errors + stats.tx_carrier_errors),
-		  stats.collisions,
-		  (stats.rx_dropped + stats.tx_dropped));
+                  stats.rx_packets,
+                  stats.tx_packets,
+                  stats.rx_bytes,
+                  stats.tx_bytes,
+                  stats.multicast,
+                  0,
+                  (stats.rx_errors + stats.rx_fifo_errors + stats.rx_frame_errors),
+                  (stats.tx_errors + stats.tx_fifo_errors + stats.tx_carrier_errors),
+                  stats.collisions,
+                  (stats.rx_dropped + stats.tx_dropped));
 }

+ 37 - 37
symon/platform/Linux/sm_io.c

@@ -1,4 +1,4 @@
-/* $Id: sm_io.c,v 1.1 2006/06/30 08:21:23 dijkstra Exp $ */
+/* $Id: sm_io.c,v 1.2 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2006 Willem Dijkstra
@@ -82,8 +82,8 @@ void
 init_io(struct stream *st)
 {
     if (io_buf == NULL) {
-	io_maxsize = SYMON_MAX_OBJSIZE;
-	io_buf = xmalloc(io_maxsize);
+        io_maxsize = SYMON_MAX_OBJSIZE;
+        io_buf = xmalloc(io_maxsize);
     }
 
     info("started module io(%.200s)", st->arg);
@@ -94,8 +94,8 @@ gets_io()
 {
     int fd;
     if ((fd = open(io_filename, O_RDONLY)) < 0) {
-	warning("cannot access %.200s: %.200s", io_filename, strerror(errno));
-	return;
+        warning("cannot access %.200s: %.200s", io_filename, strerror(errno));
+        return;
     }
 
     bzero(io_buf, io_maxsize);
@@ -103,19 +103,19 @@ gets_io()
     close(fd);
 
     if (io_size == io_maxsize) {
-	/* buffer is too small to hold all interface data */
-	io_maxsize += SYMON_MAX_OBJSIZE;
-	if (io_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for io data",
-		  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
-	}
-	io_buf = xrealloc(io_buf, io_maxsize);
-	gets_io();
-	return;
+        /* buffer is too small to hold all interface data */
+        io_maxsize += SYMON_MAX_OBJSIZE;
+        if (io_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for io data",
+                  __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
+        }
+        io_buf = xrealloc(io_buf, io_maxsize);
+        gets_io();
+        return;
     }
 
     if (io_size == -1) {
-	warning("could not read io statistics from %.200s: %.200s", io_filename, strerror(errno));
+        warning("could not read io statistics from %.200s: %.200s", io_filename, strerror(errno));
     }
 }
 
@@ -126,44 +126,44 @@ get_io(char *symon_buf, int maxlen, struct stream *st)
     struct io_device_stats stats;
 
     if (io_size <= 0) {
-	return 0;
+        return 0;
     }
 
     if ((line = strstr(io_buf, st->arg)) == NULL) {
-	warning("could not find disk %s", st->arg);
-	return 0;
+        warning("could not find disk %s", st->arg);
+        return 0;
     }
 
     line += strlen(st->arg);
     bzero(&stats, sizeof(struct io_device_stats));
 
     if (11 > sscanf(line, " %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
-		    &stats.read_issued, &stats.read_merged,
-		    &stats.read_sectors, &stats.read_milliseconds,
-		    &stats.write_issued, &stats.write_merged,
-		    &stats.write_sectors, &stats.write_milliseconds,
-		    &stats.progress_ios, &stats.progress_milliseconds,
-		    &stats.progress_weight)) {
+                    &stats.read_issued, &stats.read_merged,
+                    &stats.read_sectors, &stats.read_milliseconds,
+                    &stats.write_issued, &stats.write_merged,
+                    &stats.write_sectors, &stats.write_milliseconds,
+                    &stats.progress_ios, &stats.progress_milliseconds,
+                    &stats.progress_weight)) {
 #ifdef HAS_PROC_DISKSTATS
-	if (4 > sscanf(line, " %llu %llu %llu %llu\n",
-		       &stats.read_issued, &stats.read_sectors,
-		       &stats.write_issued, &stats.write_sectors)) {
-	    warning("could not parse disk statistics for %.200s", st->arg);
-	    return 0;
-	}
+        if (4 > sscanf(line, " %llu %llu %llu %llu\n",
+                       &stats.read_issued, &stats.read_sectors,
+                       &stats.write_issued, &stats.write_sectors)) {
+            warning("could not parse disk statistics for %.200s", st->arg);
+            return 0;
+        }
     }
 #else
-	warning("could not parse disk statistics for %.200s", st->arg);
-	return 0;
+        warning("could not parse disk statistics for %.200s", st->arg);
+        return 0;
     }
 #endif
 
     return snpack(symon_buf, maxlen, st->arg, MT_IO2,
-		  (stats.read_issued + stats.read_merged),
-		  (stats.write_issued + stats.write_merged),
-		  (uint64_t) 0,
-		  (uint64_t)(stats.read_sectors * DEV_BSIZE),
-		  (uint64_t)(stats.write_sectors * DEV_BSIZE));
+                  (stats.read_issued + stats.read_merged),
+                  (stats.write_issued + stats.write_merged),
+                  (uint64_t) 0,
+                  (uint64_t)(stats.read_sectors * DEV_BSIZE),
+                  (uint64_t)(stats.write_sectors * DEV_BSIZE));
 }
 #else
 void

+ 21 - 21
symon/platform/Linux/sm_mem.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mem.c,v 1.3 2005/10/19 20:06:05 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Harm Schotanus
@@ -58,8 +58,8 @@ void
 init_mem(struct stream *st)
 {
     if (me_buf == NULL) {
-	me_maxsize = SYMON_MAX_OBJSIZE;
-	me_buf = xmalloc(me_maxsize);
+        me_maxsize = SYMON_MAX_OBJSIZE;
+        me_buf = xmalloc(me_maxsize);
     }
 
     info("started module mem(%.200s)", st->arg);
@@ -70,7 +70,7 @@ gets_mem()
 {
    int fd;
    if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
-	warning("cannot access /proc/meminfo: %.200s", strerror(errno));
+        warning("cannot access /proc/meminfo: %.200s", strerror(errno));
    }
 
    bzero(me_buf, me_maxsize);
@@ -78,15 +78,15 @@ gets_mem()
    close(fd);
 
    if (me_size == me_maxsize) {
-	/* buffer is too small to hold all memory data */
-	me_maxsize += SYMON_MAX_OBJSIZE;
-	if (me_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for cp data",
-		__FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
-	}
-	me_buf = xrealloc(me_buf, me_maxsize);
-	gets_mem();
-	return;
+        /* buffer is too small to hold all memory data */
+        me_maxsize += SYMON_MAX_OBJSIZE;
+        if (me_maxsize > SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for cp data",
+                __FILE__, __LINE__, SYMON_MAX_OBJSIZE * SYMON_MAX_DOBJECTS);
+        }
+        me_buf = xrealloc(me_buf, me_maxsize);
+        gets_mem();
+        return;
     }
 
    if (me_size == -1) {
@@ -101,20 +101,20 @@ mem_getitem(char *name)
     char *line;
 
     if (me_size <= 0) {
-	return 0;
+        return 0;
     }
 
     if ((line = strstr(me_buf, name)) == NULL) {
-	warning("could not find %s in /proc/meminfo", name);
-	return 0;
+        warning("could not find %s in /proc/meminfo", name);
+        return 0;
     }
 
     line += strlen(name);
     if (1 < sscanf(line, ": %lu Kb", &stat)) {
-	warning("could not parse memory statistics");
-	return 0;
+        warning("could not parse memory statistics");
+        return 0;
     } else {
-	return stat;
+        return stat;
     }
 }
 
@@ -130,6 +130,6 @@ get_mem(char *symon_buf, int maxlen, struct stream *st)
     me_stats[3] = me_stats[4] - me_stats[3];
 
     return snpack(symon_buf, maxlen, st->arg, MT_MEM,
-		  me_stats[0], me_stats[1], me_stats[2],
-		  me_stats[3], me_stats[4]);
+                  me_stats[0], me_stats[1], me_stats[2],
+                  me_stats[3], me_stats[4]);
 }

+ 7 - 7
symon/platform/NetBSD/platform.h

@@ -1,4 +1,4 @@
-/* $Id: platform.h,v 1.4 2005/10/21 14:58:45 dijkstra Exp $ */
+/* $Id: platform.h,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 #ifndef _CONF_NETBSD_H
 #define _CONF_NETBSD_H
@@ -18,18 +18,18 @@
 #define SS_LEN(x)       ((x)->ss_len)
 
 union semun {
-	int val;
+        int val;
 };
 
 union stream_parg {
     struct {
-	u_int64_t time[CPUSTATES];
-	u_int64_t old[CPUSTATES];
-	u_int64_t diff[CPUSTATES];
-	int states[CPUSTATES];
+        u_int64_t time[CPUSTATES];
+        u_int64_t old[CPUSTATES];
+        u_int64_t diff[CPUSTATES];
+        int states[CPUSTATES];
     } cp;
     struct {
-	char rawdev[SYMON_DFNAMESIZE];
+        char rawdev[SYMON_DFNAMESIZE];
     } df;
     struct ifdatareq ifr;
     int sn;

+ 16 - 16
symon/platform/NetBSD/sm_cpu.c

@@ -1,4 +1,4 @@
-/* $Id: sm_cpu.c,v 1.4 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_cpu.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /* The author of this code is Matthew Gream.
  *
@@ -94,22 +94,22 @@ percentages(int cnt, int *out, register u_int64_t *new, register u_int64_t *old,
 
     /* calculate changes for each state and the overall change */
     for (i = 0; i < cnt; i++) {
-	if (*new < *old)
-	    change = (ULLONG_MAX - *old) + *new;
-	else
-	    change = *new - *old;
-	total_change += (*dp++ = change);
-	*old++ = *new++;
+        if (*new < *old)
+            change = (ULLONG_MAX - *old) + *new;
+        else
+            change = *new - *old;
+        total_change += (*dp++ = change);
+        *old++ = *new++;
     }
 
     /* avoid divide by zero potential */
     if (total_change == 0)
-	total_change = 1;
+        total_change = 1;
 
     /* calculate percentages based on overall change, rounding up */
     half_total = total_change / 2;
     for (i = 0; i < cnt; i++)
-	*out++ = ((*diffs++ * 1000 + half_total) / total_change);
+        *out++ = ((*diffs++ * 1000 + half_total) / total_change);
 
     /* return the total in case the caller wants to use it */
     return total_change;
@@ -136,17 +136,17 @@ int
 get_cpu(char *symon_buf, int maxlen, struct stream *st)
 {
     if (sysctl(cp_time_mib, 2, &st->parg.cp.time, &cp_size, NULL, 0) < 0) {
-	warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
-	return 0;
+        warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
+        return 0;
     }
 
     /* convert cp_time counts to percentages */
     (void)percentages(CPUSTATES, st->parg.cp.states, st->parg.cp.time, st->parg.cp.old, st->parg.cp.diff);
 
     return snpack(symon_buf, maxlen, st->arg, MT_CPU,
-		  (double) (st->parg.cp.states[CP_USER] / 10.0),
-		  (double) (st->parg.cp.states[CP_NICE] / 10.0),
-		  (double) (st->parg.cp.states[CP_SYS] / 10.0),
-		  (double) (st->parg.cp.states[CP_INTR] / 10.0),
-		  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
+                  (double) (st->parg.cp.states[CP_USER] / 10.0),
+                  (double) (st->parg.cp.states[CP_NICE] / 10.0),
+                  (double) (st->parg.cp.states[CP_SYS] / 10.0),
+                  (double) (st->parg.cp.states[CP_INTR] / 10.0),
+                  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
 }

+ 6 - 6
symon/platform/NetBSD/sm_debug.c

@@ -1,4 +1,4 @@
-/* $Id: sm_debug.c,v 1.4 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_debug.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -66,14 +66,14 @@ get_debug(char *symon_buf, int maxlen, struct stream *st)
     len = sizeof(int);
 
     for (i = 0; i < SYMON_MAXDEBUGID; i++) {
-	db_mib[1] = i;
+        db_mib[1] = i;
 
-	sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
+        sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_DEBUG,
-		  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
-		  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
-		  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
+                  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
+                  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
+                  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
 
 }

+ 16 - 15
symon/platform/NetBSD/sm_df.c

@@ -1,4 +1,4 @@
-/* $Id: sm_df.c,v 1.2 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_df.c,v 1.2 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Marc Balmer
@@ -42,6 +42,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/mount.h>
+#include <sys/statvfs.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 
@@ -56,7 +57,7 @@
 #include "symon.h"
 
 /* Globals for this module start with df_ */
-static struct statfs *df_stats = NULL;
+static struct statvfs *df_stats = NULL;
 static int df_parts = 0;
 
 void
@@ -72,7 +73,7 @@ void
 gets_df()
 {
     if ((df_parts = getmntinfo(&df_stats, MNT_NOWAIT)) == 0) {
-	warning("df failed");
+        warning("df failed");
     }
 }
 
@@ -82,8 +83,8 @@ gets_df()
  * Attempts to avoid overflow for large filesystems.
  */
 #define fsbtoblk(num, fsbs, bs) \
-	(((fsbs) != 0 && (fsbs) < (bs)) ? \
-		(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
+        (((fsbs) != 0 && (fsbs) < (bs)) ? \
+                (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
 
 int
 get_df(char *symon_buf, int maxlen, struct stream *st)
@@ -91,16 +92,16 @@ get_df(char *symon_buf, int maxlen, struct stream *st)
     int n;
 
     for (n = 0; n < df_parts; n++) {
-	if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
-	    return snpack(symon_buf, maxlen, st->arg, MT_DF,
-			  (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)df_stats[n].f_files,
-			  (u_int64_t)df_stats[n].f_ffree,
-			  (u_int64_t)df_stats[n].f_syncwrites,
-			  (u_int64_t)df_stats[n].f_asyncwrites);
-	}
+        if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
+            return snpack(symon_buf, maxlen, st->arg, MT_DF,
+                          (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)df_stats[n].f_files,
+                          (u_int64_t)df_stats[n].f_ffree,
+                          (u_int64_t)df_stats[n].f_syncwrites,
+                          (u_int64_t)df_stats[n].f_asyncwrites);
+        }
     }
 
     warning("df(%.200s) failed (no such device)", st->arg);

+ 17 - 17
symon/platform/NetBSD/sm_if.c

@@ -1,4 +1,4 @@
-/* $Id: sm_if.c,v 1.4 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_if.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -61,10 +61,10 @@ void
 init_if(struct stream *st)
 {
     if (if_s == -1) {
-	if ((if_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-	    fatal("%s:%d: socket failed, %.200",
-		  __FILE__, __LINE__, strerror(errno));
-	}
+        if ((if_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+            fatal("%s:%d: socket failed, %.200",
+                  __FILE__, __LINE__, strerror(errno));
+        }
     }
 
     strncpy(st->parg.ifr.ifdr_name, st->arg, sizeof(st->parg.ifr.ifdr_name));
@@ -84,20 +84,20 @@ get_if(char *symon_buf, int maxlen, struct stream *st)
     const struct if_data* ifi;
 
     if (ioctl(if_s, SIOCGIFDATA, (caddr_t)&st->parg.ifr)) {
-	warning("if(%.200s) failed (ioctl error)", st->arg);
-	return 0;
+        warning("if(%.200s) failed (ioctl error)", st->arg);
+        return 0;
     }
     ifi = &st->parg.ifr.ifdr_data;
 
     return snpack(symon_buf, maxlen, st->arg, MT_IF,
-		  (u_int32_t) ifi->ifi_ipackets,
-		  (u_int32_t) ifi->ifi_opackets,
-		  (u_int32_t) ifi->ifi_ibytes,
-		  (u_int32_t) ifi->ifi_obytes,
-		  (u_int32_t) ifi->ifi_imcasts,
-		  (u_int32_t) ifi->ifi_omcasts,
-		  (u_int32_t) ifi->ifi_ierrors,
-		  (u_int32_t) ifi->ifi_oerrors,
-		  (u_int32_t) ifi->ifi_collisions,
-		  (u_int32_t) ifi->ifi_iqdrops);
+                  (u_int32_t) ifi->ifi_ipackets,
+                  (u_int32_t) ifi->ifi_opackets,
+                  (u_int32_t) ifi->ifi_ibytes,
+                  (u_int32_t) ifi->ifi_obytes,
+                  (u_int32_t) ifi->ifi_imcasts,
+                  (u_int32_t) ifi->ifi_omcasts,
+                  (u_int32_t) ifi->ifi_ierrors,
+                  (u_int32_t) ifi->ifi_oerrors,
+                  (u_int32_t) ifi->ifi_collisions,
+                  (u_int32_t) ifi->ifi_iqdrops);
 }

+ 19 - 19
symon/platform/NetBSD/sm_io.c

@@ -1,4 +1,4 @@
-/* $Id: sm_io.c,v 1.3 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_io.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -66,28 +66,28 @@ gets_io()
     mib[2] = sizeof (struct disk_sysctl);
     size = 0;
     if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
-	fatal("%s:%d: io can't get hw.diskstats"
-	      __FILE__, __LINE__);
+        fatal("%s:%d: io can't get hw.diskstats"
+              __FILE__, __LINE__);
     }
     io_dks = size / sizeof (struct disk_sysctl);
 
     /* adjust buffer if necessary */
     if (io_dks > io_maxdks) {
-	io_maxdks = io_dks;
+        io_maxdks = io_dks;
 
-	if (io_maxdks > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for diskstat structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (io_maxdks > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for diskstat structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	io_dkstats = xrealloc(io_dkstats, io_maxdks * sizeof(struct disk_sysctl));
+        io_dkstats = xrealloc(io_dkstats, io_maxdks * sizeof(struct disk_sysctl));
     }
 
     /* read structure  */
     size = io_maxdks * sizeof(struct disk_sysctl);
     if (sysctl(mib, 3, io_dkstats, &size, NULL, 0) < 0) {
-	fatal("%s:%d: io can't get hw.diskstats"
-	      __FILE__, __LINE__);
+        fatal("%s:%d: io can't get hw.diskstats"
+              __FILE__, __LINE__);
     }
 }
 
@@ -103,14 +103,14 @@ get_io(char *symon_buf, int maxlen, struct stream *st)
     int i;
 
     for (i = 0; i < io_maxdks; i++)
-	if (strncmp(io_dkstats[i].dk_name, st->arg,
-		    sizeof(io_dkstats[i].dk_name)) == 0)
-	    return snpack(symon_buf, maxlen, st->arg, MT_IO2,
-			  io_dkstats[i].dk_rxfer,
-			  io_dkstats[i].dk_wxfer,
-			  io_dkstats[i].dk_seek,
-			  io_dkstats[i].dk_rbytes,
-			  io_dkstats[i].dk_wbytes);
+        if (strncmp(io_dkstats[i].dk_name, st->arg,
+                    sizeof(io_dkstats[i].dk_name)) == 0)
+            return snpack(symon_buf, maxlen, st->arg, MT_IO2,
+                          io_dkstats[i].dk_rxfer,
+                          io_dkstats[i].dk_wxfer,
+                          io_dkstats[i].dk_seek,
+                          io_dkstats[i].dk_rbytes,
+                          io_dkstats[i].dk_wbytes);
 
     return 0;
 }

+ 49 - 49
symon/platform/NetBSD/sm_mbuf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mbuf.c,v 1.3 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_mbuf.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2003 Daniel Hartmeier
@@ -70,8 +70,8 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     mib[2] = MBUF_STATS;
     size = sizeof(mbstat);
     if (sysctl(mib, 3, &mbstat, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return (0);
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return (0);
     }
 
 #ifdef KERN_POOL
@@ -80,50 +80,50 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     mib[2] = KERN_POOL_NPOOLS;
     size = sizeof(npools);
     if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return (0);
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return (0);
     }
 
     for (i = 1; npools; ++i) {
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_POOL;
-	mib[2] = KERN_POOL_POOL;
-	mib[3] = i;
-	size = sizeof(pool);
-	if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return (0);
-	}
-	npools--;
-	mib[2] = KERN_POOL_NAME;
-	size = sizeof(name);
-	if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return (0);
-	}
-	if (!strcmp(name, "mbpl")) {
-	    bcopy(&pool, &mbpool, sizeof(pool));
-	    flag |= 1;
-	} else if (!strcmp(name, "mclpl")) {
-	    bcopy(&pool, &mclpool, sizeof(pool));
-	    flag |= 2;
-	}
-	if (flag == 3)
-	    break;
+        mib[0] = CTL_KERN;
+        mib[1] = KERN_POOL;
+        mib[2] = KERN_POOL_POOL;
+        mib[3] = i;
+        size = sizeof(pool);
+        if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return (0);
+        }
+        npools--;
+        mib[2] = KERN_POOL_NAME;
+        size = sizeof(name);
+        if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return (0);
+        }
+        if (!strcmp(name, "mbpl")) {
+            bcopy(&pool, &mbpool, sizeof(pool));
+            flag |= 1;
+        } else if (!strcmp(name, "mclpl")) {
+            bcopy(&pool, &mclpool, sizeof(pool));
+            flag |= 2;
+        }
+        if (flag == 3)
+            break;
     }
     if (flag != 3) {
-	warning("mbuf(%.200s) failed (flag != 3)", st->arg);
-	return (0);
+        warning("mbuf(%.200s) failed (flag != 3)", st->arg);
+        return (0);
     }
 #endif
 
     totmbufs = 0;
     for (i = 0; i < nmbtypes; ++i)
-	totmbufs += mbstat.m_mtypes[i];
+        totmbufs += mbstat.m_mtypes[i];
 #ifdef KERN_POOL
     totmem = (mbpool.pr_npages + mclpool.pr_npages) * page_size;
     totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
-	(mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
+        (mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
 #else
     totmem = 0;
     totused = 0;
@@ -152,19 +152,19 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     stats[14] = mbstat.m_drain;
 
     return snpack(symon_buf, maxlen, st->arg, MT_MBUF,
-		  stats[0],
-		  stats[1],
-		  stats[2],
-		  stats[3],
-		  stats[4],
-		  stats[5],
-		  stats[6],
-		  stats[7],
-		  stats[8],
-		  stats[9],
-		  stats[10],
-		  stats[11],
-		  stats[12],
-		  stats[13],
-		  stats[14]);
+                  stats[0],
+                  stats[1],
+                  stats[2],
+                  stats[3],
+                  stats[4],
+                  stats[5],
+                  stats[6],
+                  stats[7],
+                  stats[8],
+                  stats[9],
+                  stats[10],
+                  stats[11],
+                  stats[12],
+                  stats[13],
+                  stats[14]);
 }

+ 140 - 0
symon/platform/NetBSD/sm_mem.c

@@ -0,0 +1,140 @@
+/* $Id: sm_mem.c,v 1.2 2007/02/11 20:07:32 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2001-2004 Willem Dijkstra
+ * 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.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Get current memory statistics in bytes; reports them back in symon_buf as
+ *
+ * real active : real total : free : [swap used : swap total]
+ */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/swap.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+
+#include "error.h"
+#include "symon.h"
+#include "xmalloc.h"
+
+#define pagetob(size) ((size) << me_pageshift)
+
+/* Globals for this module all start with me_ */
+static int me_pageshift;
+static long me_stats[5];
+static int me_vm_mib[] = {CTL_VM, VM_METER};
+static struct vmtotal me_vmtotal;
+static size_t me_vmsize;
+static int me_pagesize;
+static int me_nswap;
+struct swapent *me_swdev = NULL;
+
+void
+init_mem(struct stream *st)
+{
+    me_pagesize = sysconf(_SC_PAGESIZE);
+    me_pageshift = 0;
+    while (me_pagesize > 1) {
+        me_pageshift++;
+        me_pagesize >>= 1;
+    }
+
+    /* get total -- systemwide main memory usage structure */
+    me_vmsize = sizeof(me_vmtotal);
+
+    /* determine number of swap entries */
+    me_nswap = swapctl(SWAP_NSWAP, 0, 0);
+
+    if (me_swdev) {
+        xfree(me_swdev);
+    }
+
+    if (me_nswap != 0) {
+        me_swdev = xmalloc(me_nswap * sizeof(*me_swdev));
+    } else {
+        me_swdev = NULL;
+    }
+
+    if (me_swdev == NULL && me_nswap != 0) {
+        me_nswap = 0;
+    }
+
+    if (st != NULL) {
+        info("started module mem(%.200s)", st->arg);
+    }
+}
+
+void
+gets_mem()
+{
+    int i, rnswap;
+
+    if (sysctl(me_vm_mib, 2, &me_vmtotal, &me_vmsize, NULL, 0) < 0) {
+        warning("%s:%d: sysctl failed", __FILE__, __LINE__);
+        bzero(&me_vmtotal, sizeof(me_vmtotal));
+    }
+
+    /* convert memory stats to Kbytes */
+    me_stats[0] = pagetob(me_vmtotal.t_arm);
+    me_stats[1] = pagetob(me_vmtotal.t_rm);
+    me_stats[2] = pagetob(me_vmtotal.t_free);
+
+    rnswap = swapctl(SWAP_STATS, me_swdev, me_nswap);
+    if (rnswap == -1) {
+        /* A swap device may have been added; increase and retry */
+        init_mem(NULL);
+        rnswap = swapctl(SWAP_STATS, me_swdev, me_nswap);
+    }
+
+    me_stats[3] = me_stats[4] = 0;
+    if (rnswap == me_nswap) {   /* Read swap successfully */
+        /* Total things up */
+        for (i = 0; i < me_nswap; i++) {
+            if (me_swdev[i].se_flags & SWF_ENABLE) {
+                me_stats[3] += (me_swdev[i].se_inuse * DEV_BSIZE);
+                me_stats[4] += (me_swdev[i].se_nblks * DEV_BSIZE);
+            }
+        }
+    }
+}
+
+int
+get_mem(char *symon_buf, int maxlen, struct stream *st)
+{
+    return snpack(symon_buf, maxlen, st->arg, MT_MEM,
+                  me_stats[0], me_stats[1], me_stats[2],
+                  me_stats[3], me_stats[4]);
+}

+ 161 - 0
symon/platform/NetBSD/sm_pf.c

@@ -0,0 +1,161 @@
+/* $Id: sm_pf.c,v 1.2 2007/02/11 20:07:32 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2002 Daniel Hartmeier
+ * 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.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Get current pf statistics and return them in symon_buf as
+ *
+ *   bytes_v4_in : bytes_v4_out : bytes_v6_in : bytes_v6_out :
+ *   packets_v4_in_pass : * packets_v4_in_drop : packets_v4_out_pass :
+ *   packets_v4_out_drop : * packets_v6_in_pass : packets_v6_in_drop :
+ *   packets_v6_out_pass : * packets_v6_out_drop : states_entries :
+ *   states_searches : states_inserts : * states_removals : counters_match :
+ *   counters_badoffset : counters_fragment : * counters_short :
+ *   counters_normalize : counters_memory
+ *
+ */
+
+#include "conf.h"
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <net/if.h>
+#ifdef HAS_PFVAR_H
+#include <net/pfvar.h>
+#endif
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "error.h"
+#include "symon.h"
+
+#ifndef HAS_PFVAR_H
+void
+privinit_pf()
+{
+}
+void
+init_pf(struct stream *st)
+{
+    fatal("pf support not available");
+}
+int
+get_pf(char *symon_buf, int maxlen, struct stream *st)
+{
+    fatal("pf support not available");
+    return 0;
+}
+void
+gets_pf()
+{
+    fatal("pf support not available");
+}
+
+#else
+
+/* Globals for this module start with pf_ */
+int pf_dev = -1;
+struct pf_status pf_stat;
+
+void
+privinit_pf()
+{
+    if ((pf_dev = open("/dev/pf", O_RDONLY)) == -1) {
+        warning("could not open \"/dev/pf\", %.200s", strerror(errno));
+    }
+}
+
+void
+init_pf(struct stream *st)
+{
+    if (pf_dev == -1) {
+        privinit_pf();
+    }
+
+    info("started module pf()");
+}
+
+void
+gets_pf()
+{
+    if (pf_dev == -1) {
+        warning("could not get pf stats (dev == -1)");
+        pf_stat.running = 0;
+        return;
+    }
+
+    if (ioctl(pf_dev, DIOCGETSTATUS, &pf_stat)) {
+        warning("could not get pf stats (ioctl error)");
+        pf_stat.running = 0;
+        return;
+    }
+}
+
+int
+get_pf(char *symon_buf, int maxlen, struct stream *st)
+{
+    u_int64_t n;
+
+    if (!pf_stat.running) {
+        return 0;
+    }
+
+    n = pf_stat.states;
+    return snpack(symon_buf, maxlen, st->arg, MT_PF,
+                  pf_stat.bcounters[0][0],
+                  pf_stat.bcounters[0][1],
+                  pf_stat.bcounters[1][0],
+                  pf_stat.bcounters[1][1],
+                  pf_stat.pcounters[0][0][PF_PASS],
+                  pf_stat.pcounters[0][0][PF_DROP],
+                  pf_stat.pcounters[0][1][PF_PASS],
+                  pf_stat.pcounters[0][1][PF_DROP],
+                  pf_stat.pcounters[1][0][PF_PASS],
+                  pf_stat.pcounters[1][0][PF_DROP],
+                  pf_stat.pcounters[1][1][PF_PASS],
+                  pf_stat.pcounters[1][1][PF_DROP],
+                  n,
+                  pf_stat.fcounters[0],
+                  pf_stat.fcounters[1],
+                  pf_stat.fcounters[2],
+                  pf_stat.counters[0],
+                  pf_stat.counters[1],
+                  pf_stat.counters[2],
+                  pf_stat.counters[3],
+                  pf_stat.counters[4],
+                  pf_stat.counters[5]
+        );
+}
+#endif /* HAS_PFVAR_H */

+ 240 - 0
symon/platform/NetBSD/sm_pfq.c

@@ -0,0 +1,240 @@
+/* $Id: sm_pfq.c,v 1.2 2007/02/11 20:07:32 dijkstra Exp $ */
+
+/*
+ * Copyright (c) 2005 J. Martin Petersen
+ * 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.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Get current altq statistics from pf and return them in symon_buf as
+ * sent_bytes : sent_packets : drop_bytes : drop_packets
+ */
+
+#include "conf.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAS_PFVAR_H
+#include <net/pfvar.h>
+#include <altq/altq.h>
+#include <altq/altq_cbq.h>
+#include <altq/altq_priq.h>
+#include <altq/altq_hfsc.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "error.h"
+#include "symon.h"
+#include "xmalloc.h"
+
+#ifndef HAS_PFVAR_H
+void
+privinit_pfq()
+{
+    fatal("pf support not available");
+}
+void
+init_pfq(struct stream *st)
+{
+    fatal("pf support not available");
+}
+void
+gets_pfq()
+{
+    fatal("pf support not available");
+}
+
+int
+get_pfq(char *b, int l, struct stream *st)
+{
+  fatal("pf support not available");
+  return 0;
+}
+
+#else
+
+union class_stats {
+    class_stats_t cbq;
+    struct priq_basic_class_stats priq;
+    struct hfsc_basic_class_stats hfsc;
+};
+
+/*
+ * We do not use the data structures from altq/altq_{cbq|hfsc|priq}.h as they
+ * are overly complex. For now we only grab the interesting stuff.
+ */
+
+struct altq_stats {
+    char qname[PF_QNAME_SIZE + IFNAMSIZ + 1];
+    u_int64_t sent_bytes;
+    u_int64_t sent_packets;
+    u_int64_t drop_bytes;
+    u_int64_t drop_packets;
+};
+
+static struct altq_stats *pfq_stats = NULL;
+static int pfq_cur = 0;
+static int pfq_max = 0;
+int pfq_dev = -1;
+
+void
+privinit_pfq()
+{
+    if ((pfq_dev = open("/dev/pf", O_RDONLY)) == -1) {
+        warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
+    }
+}
+
+void
+init_pfq(struct stream *st)
+{
+    if (pfq_dev == -1) {
+        privinit_pfq();
+    }
+
+    info("started module pfq(%.200s)", st->arg);
+}
+
+void
+gets_pfq()
+{
+    struct pfioc_altq qs;
+    struct pfioc_qstats stats;
+    union class_stats q;
+    unsigned int nqs;
+    unsigned int i;
+
+    bzero(&qs, sizeof(qs));
+    bzero(&stats, sizeof(stats));
+    bzero(&q, sizeof(q));
+
+    if (ioctl(pfq_dev, DIOCGETALTQS, &qs)) {
+        fatal("pfq: DIOCGETALTQS failed");
+    }
+    nqs = qs.nr;
+
+    /* Allocate memory for info for the nqs queues */
+    if (nqs > pfq_max) {
+        if (pfq_stats) {
+            xfree(pfq_stats);
+        }
+
+        pfq_max = 2 * nqs;
+
+        if (pfq_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for pf queue structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
+
+        pfq_stats = xmalloc(pfq_max * sizeof(struct altq_stats));
+    }
+
+    pfq_cur = 0;
+
+    /* Loop through the queues, copy info */
+    for (i = 0; i < nqs; i++) {
+        qs.nr = i;
+        if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
+            fatal("pfq: DIOCGETALTQ failed");
+        }
+
+        /* only process the non-empty queues */
+        if (qs.altq.qid > 0) {
+            stats.nr = qs.nr;
+            stats.ticket = qs.ticket;
+            stats.buf = &q;
+            stats.nbytes = sizeof(q);
+
+            if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
+                fatal("pfq: DIOCGETQSTATS failed");
+            }
+
+            /* We're now ready to copy the data we want. */
+            snprintf(pfq_stats[pfq_cur].qname, sizeof(pfq_stats[0].qname),
+                     "%s/%s", qs.altq.ifname, qs.altq.qname);
+
+            switch (qs.altq.scheduler) {
+            case ALTQT_CBQ:
+                pfq_stats[pfq_cur].sent_bytes = q.cbq.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.cbq.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.cbq.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.cbq.drop_cnt.packets;
+                break;
+
+            case ALTQT_PRIQ:
+                pfq_stats[pfq_cur].sent_bytes = q.priq.xmitcnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.priq.xmitcnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.priq.dropcnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.priq.dropcnt.packets;
+                break;
+
+            case ALTQT_HFSC:
+                pfq_stats[pfq_cur].sent_bytes = q.hfsc.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.hfsc.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.hfsc.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.hfsc.drop_cnt.packets;
+                break;
+
+            default:
+                warning("pfq: unknown altq scheduler type encountered");
+                break;
+            }
+            pfq_cur++;
+        }
+    }
+}
+
+int
+get_pfq(char *symon_buf, int maxlen, struct stream *st)
+{
+    unsigned int i;
+
+    for (i = 0; i < pfq_cur; i++) {
+        if (strncmp(pfq_stats[i].qname, st->arg, sizeof(pfq_stats[0].qname)) == 0) {
+            return snpack(symon_buf, maxlen, st->arg, MT_PFQ,
+                          pfq_stats[i].sent_bytes,
+                          pfq_stats[i].sent_packets,
+                          pfq_stats[i].drop_bytes,
+                          pfq_stats[i].drop_packets
+                );
+        }
+    }
+
+    return 0;
+}
+#endif

+ 37 - 37
symon/platform/NetBSD/sm_proc.c

@@ -1,4 +1,4 @@
-/* $Id: sm_proc.c,v 1.4 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_proc.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -76,20 +76,20 @@ gets_proc()
     mib[1] = KERN_MAXPROC;
     size = sizeof(procs);
     if (sysctl(mib, 2, &procs, &size, NULL, 0) < 0) {
-	fatal("%s:%d: sysctl failed: can't get kern.nproc",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: sysctl failed: can't get kern.nproc",
+              __FILE__, __LINE__);
     }
 
     /* increase buffers if necessary */
     if (procs > proc_max) {
-	proc_max = (procs * 5) / 4;
+        proc_max = (procs * 5) / 4;
 
-	if (proc_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (proc_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
+        proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
     }
 
     /* read data in anger */
@@ -99,17 +99,17 @@ gets_proc()
 
     size = proc_max * sizeof(struct kinfo_proc);
     if (sysctl(mib, 3, proc_ps, &size, NULL, 0) < 0) {
-	warning("proc probe cannot get processes");
-	proc_cur = 0;
-	return;
+        warning("proc probe cannot get processes");
+        proc_cur = 0;
+        return;
     }
 
     if (size % sizeof(struct kinfo_proc) != 0) {
-	warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
-		size, sizeof(struct kinfo_proc));
-	proc_cur = 0;
+        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
+                size, sizeof(struct kinfo_proc));
+        proc_cur = 0;
     } else {
-	proc_cur = size / sizeof(struct kinfo_proc);
+        proc_cur = size / sizeof(struct kinfo_proc);
     }
 }
 
@@ -128,7 +128,7 @@ init_proc(struct stream *st)
 
     /* get clockrate */
     if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1) {
-	fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
+        fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
     }
 
     proc_stathz = cinf.stathz;
@@ -137,8 +137,8 @@ init_proc(struct stream *st)
     proc_pagesize = sysconf(_SC_PAGESIZE);
     proc_pageshift = 0;
     while (proc_pagesize > 1) {
-	proc_pageshift++;
-	proc_pagesize >>= 1;
+        proc_pageshift++;
+        proc_pagesize >>= 1;
     }
 
     info("started module proc(%.200s)", st->arg);
@@ -161,21 +161,21 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     int n = 0;
 
     for (pp = proc_ps, i = 0; i < proc_cur; pp++, i++) {
-	 if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
-	     /* cpu time - accumulated */
-	     cpu_uticks += pp->kp_proc.p_uticks;  /* user */
-	     cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
-	     cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
-	     /* cpu time - percentage since last measurement */
-	     cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
-	     cpu_pcti += cpu_pct;
-	     /* memory size - shared pages are counted multiple times */
-	     mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
-				     pp->kp_eproc.e_vm.vm_dsize + /* data */
-				     pp->kp_eproc.e_vm.vm_ssize); /* stack */
-	     mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
-	     n++;
-	 }
+         if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
+             /* cpu time - accumulated */
+             cpu_uticks += pp->kp_proc.p_uticks;  /* user */
+             cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
+             cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
+             /* cpu time - percentage since last measurement */
+             cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
+             cpu_pcti += cpu_pct;
+             /* memory size - shared pages are counted multiple times */
+             mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
+                                     pp->kp_eproc.e_vm.vm_dsize + /* data */
+                                     pp->kp_eproc.e_vm.vm_ssize); /* stack */
+             mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
+             n++;
+         }
     }
 
     /* calc total cpu_secs spent */
@@ -183,7 +183,7 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     cpu_secs = cpu_ticks / proc_stathz;
 
     return snpack(symon_buf, maxlen, st->arg, MT_PROC,
-		  n,
-		  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
-		  mem_procsize, mem_rss );
+                  n,
+                  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
+                  mem_procsize, mem_rss );
 }

+ 30 - 30
symon/platform/NetBSD/sm_sensor.c

@@ -1,4 +1,4 @@
-/* $Id: sm_sensor.c,v 1.3 2005/10/18 19:58:09 dijkstra Exp $ */
+/* $Id: sm_sensor.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2004      Matthew Gream
@@ -54,7 +54,7 @@ void
 privinit_sensor()
 {
     if (sn_dev == -1 && (sn_dev = open("/dev/sysmon", O_RDONLY)) == -1) {
-	warning("could not open \"/dev/sysmon\", %.200s", strerror(errno));
+        warning("could not open \"/dev/sysmon\", %.200s", strerror(errno));
     }
 }
 
@@ -62,7 +62,7 @@ void
 init_sensor(struct stream *st)
 {
     if (sn_dev == -1) {
-	privinit_sensor();
+        privinit_sensor();
     }
 
     st->parg.sn = (strtol(st->arg, NULL, 10) & SYMON_SENSORMASK);
@@ -80,46 +80,46 @@ get_sensor(char *symon_buf, int maxlen, struct stream *st)
 
     e_info.sensor = st->parg.sn;
     if (ioctl(sn_dev, ENVSYS_GTREINFO, &e_info) == -1) {
-	warning("%s:%d: sensor can't get sensor info %.200s -- %.200s",
-		__FILE__, __LINE__, st->arg, strerror(errno));
-	return 0;
+        warning("%s:%d: sensor can't get sensor info %.200s -- %.200s",
+                __FILE__, __LINE__, st->arg, strerror(errno));
+        return 0;
     }
 
     if (!(e_info.validflags & ENVSYS_FVALID)) {
-	warning("%s:%d: sensor info is invalid %.200s -- %.200s",
-		__FILE__, __LINE__, st->arg, strerror(errno));
-	return 0;
+        warning("%s:%d: sensor info is invalid %.200s -- %.200s",
+                __FILE__, __LINE__, st->arg, strerror(errno));
+        return 0;
     }
 
     e_data.sensor = st->parg.sn;
     if (ioctl(sn_dev, ENVSYS_GTREDATA, &e_data) == -1) {
-	warning("%s:%d: sensor can't get sensor data %.200s -- %.200s",
-		__FILE__, __LINE__, st->arg, strerror(errno));
-	return 0;
+        warning("%s:%d: sensor can't get sensor data %.200s -- %.200s",
+                __FILE__, __LINE__, st->arg, strerror(errno));
+        return 0;
     }
 
     if (!(e_data.validflags & ENVSYS_FCURVALID)) {
-	warning("%s:%d: sensor data is invalid %.200s -- %.200s",
-		__FILE__, __LINE__, st->arg, strerror(errno));
-	return 0;
+        warning("%s:%d: sensor data is invalid %.200s -- %.200s",
+                __FILE__, __LINE__, st->arg, strerror(errno));
+        return 0;
     }
 
     switch (e_data.units) {
-	case ENVSYS_INDICATOR:
-	    t = (double) (e_data.cur.data_us ? 1.0 : 0.0);
-	    break;
-	case ENVSYS_INTEGER:
-	    t = (double) (e_data.cur.data_s);
-	    break;
-	case ENVSYS_STEMP:
-	    t = (double) (e_data.cur.data_s / 1000.0 / 1000.0) - 273.16;
-	    break;
-	case ENVSYS_SFANRPM:
-	    t = (double) (e_data.cur.data_us);
-	    break;
-	default: /* generic - includes volts/etc */
-	    t = (double) (e_data.cur.data_s / 1000.0 / 1000.0);
-	    break;
+        case ENVSYS_INDICATOR:
+            t = (double) (e_data.cur.data_us ? 1.0 : 0.0);
+            break;
+        case ENVSYS_INTEGER:
+            t = (double) (e_data.cur.data_s);
+            break;
+        case ENVSYS_STEMP:
+            t = (double) (e_data.cur.data_s / 1000.0 / 1000.0) - 273.16;
+            break;
+        case ENVSYS_SFANRPM:
+            t = (double) (e_data.cur.data_us);
+            break;
+        default: /* generic - includes volts/etc */
+            t = (double) (e_data.cur.data_s / 1000.0 / 1000.0);
+            break;
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_SENSOR, t);

+ 4 - 0
symon/platform/OpenBSD/conf.sh

@@ -9,6 +9,10 @@ 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" ;;
+esac
+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" ;;

+ 9 - 2
symon/platform/OpenBSD/platform.h

@@ -1,4 +1,4 @@
-/* $Id: platform.h,v 1.4 2006/09/10 19:50:29 dijkstra Exp $ */
+/* $Id: platform.h,v 1.5 2007/01/19 21:37:27 dijkstra Exp $ */
 
 #ifndef _CONF_OPENBSD_H
 #define _CONF_OPENBSD_H
@@ -8,6 +8,7 @@
 #include <sys/dkstat.h>
 #include <sys/queue.h>
 #include <sys/types.h>
+#include <sys/sensors.h>
 #include <sys/socket.h>
 #include <net/if.h>
 
@@ -39,7 +40,13 @@ union stream_parg {
         char rawdev[SYMON_DFNAMESIZE];
     } df;
     struct ifreq ifr;
-    int sn;
+    struct {
+#ifndef HAS_SENSORDEV
+        int mib[3];
+#else
+        int mib[5];
+#endif
+    } sn;
 };
 
 #endif

+ 38 - 38
symon/platform/OpenBSD/sm_cpu.c

@@ -1,4 +1,4 @@
-/* $Id: sm_cpu.c,v 1.22 2006/09/10 19:50:29 dijkstra Exp $ */
+/* $Id: sm_cpu.c,v 1.23 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /* The author of this code is Willem Dijkstra (wpd@xs4all.nl).
  *
@@ -84,42 +84,42 @@ static size_t cp_size;
 int
 percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_t *diffs)
 {
-	int64_t change, total_change, *dp, half_total;
+        int64_t change, total_change, *dp, half_total;
 #else
 static int cp_time_mib[] = {CTL_KERN, KERN_CPTIME};
 int
 percentages(int cnt, int *out, register long *new, register long *old, long *diffs)
 {
-	long change, total_change, *dp, half_total;
+        long change, total_change, *dp, half_total;
 #endif
-	int i;
-
-
-	/* initialization */
-	total_change = 0;
-	dp = diffs;
-
-	/* calculate changes for each state and the overall change */
-	for (i = 0; i < cnt; i++) {
-		if ((change = *new - *old) < 0) {
-			/* this only happens when the counter wraps */
-			change = (*new - *old);
-		}
-		total_change += (*dp++ = change);
-		*old++ = *new++;
-	}
-
-	/* avoid divide by zero potential */
-	if (total_change == 0)
-		total_change = 1;
-
-	/* calculate percentages based on overall change, rounding up */
-	half_total = total_change / 2l;
-	for (i = 0; i < cnt; i++)
-		*out++ = ((*diffs++ * 1000 + half_total) / total_change);
-
-	/* return the total in case the caller wants to use it */
-	return (total_change);
+        int i;
+
+
+        /* initialization */
+        total_change = 0;
+        dp = diffs;
+
+        /* calculate changes for each state and the overall change */
+        for (i = 0; i < cnt; i++) {
+                if ((change = *new - *old) < 0) {
+                        /* this only happens when the counter wraps */
+                        change = (*new - *old);
+                }
+                total_change += (*dp++ = change);
+                *old++ = *new++;
+        }
+
+        /* avoid divide by zero potential */
+        if (total_change == 0)
+                total_change = 1;
+
+        /* calculate percentages based on overall change, rounding up */
+        half_total = total_change / 2l;
+        for (i = 0; i < cnt; i++)
+                *out++ = ((*diffs++ * 1000 + half_total) / total_change);
+
+        /* return the total in case the caller wants to use it */
+        return (total_change);
 }
 
 void
@@ -176,8 +176,8 @@ get_cpu(char *symon_buf, int maxlen, struct stream *st)
     }
 #else
     if (sysctl(cp_time_mib, 2, &st->parg.cp.time, &cp_size, NULL, 0) < 0) {
-	warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
-	return 0;
+        warning("%s:%d: sysctl kern.cp_time failed", __FILE__, __LINE__);
+        return 0;
     }
 #endif
 
@@ -185,9 +185,9 @@ get_cpu(char *symon_buf, int maxlen, struct stream *st)
     total = percentages(CPUSTATES, st->parg.cp.states, st->parg.cp.time, st->parg.cp.old, st->parg.cp.diff);
 
     return snpack(symon_buf, maxlen, st->arg, MT_CPU,
-		  (double) (st->parg.cp.states[CP_USER] / 10.0),
-		  (double) (st->parg.cp.states[CP_NICE] / 10.0),
-		  (double) (st->parg.cp.states[CP_SYS] / 10.0),
-		  (double) (st->parg.cp.states[CP_INTR] / 10.0),
-		  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
+                  (double) (st->parg.cp.states[CP_USER] / 10.0),
+                  (double) (st->parg.cp.states[CP_NICE] / 10.0),
+                  (double) (st->parg.cp.states[CP_SYS] / 10.0),
+                  (double) (st->parg.cp.states[CP_INTR] / 10.0),
+                  (double) (st->parg.cp.states[CP_IDLE] / 10.0));
 }

+ 6 - 6
symon/platform/OpenBSD/sm_debug.c

@@ -1,4 +1,4 @@
-/* $Id: sm_debug.c,v 1.7 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_debug.c,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -65,14 +65,14 @@ get_debug(char *symon_buf, int maxlen, struct stream *st)
     len = sizeof(int);
 
     for (i = 0; i < SYMON_MAXDEBUGID; i++) {
-	db_mib[1] = i;
+        db_mib[1] = i;
 
-	sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
+        sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_DEBUG,
-		  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
-		  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
-		  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
+                  db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
+                  db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
+                  db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
 
 }

+ 14 - 14
symon/platform/OpenBSD/sm_df.c

@@ -1,4 +1,4 @@
-/* $Id: sm_df.c,v 1.3 2005/10/21 14:58:46 dijkstra Exp $ */
+/* $Id: sm_df.c,v 1.4 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 Marc Balmer
@@ -72,7 +72,7 @@ void
 gets_df()
 {
     if ((df_parts = getmntinfo(&df_stats, MNT_NOWAIT)) == 0) {
-	warning("df failed");
+        warning("df failed");
     }
 }
 
@@ -82,8 +82,8 @@ gets_df()
  * Attempts to avoid overflow for large filesystems.
  */
 #define fsbtoblk(num, fsbs, bs) \
-	(((fsbs) != 0 && (fsbs) < (bs)) ? \
-		(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
+        (((fsbs) != 0 && (fsbs) < (bs)) ? \
+                (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
 
 int
 get_df(char *symon_buf, int maxlen, struct stream *st)
@@ -91,16 +91,16 @@ get_df(char *symon_buf, int maxlen, struct stream *st)
     int n;
 
     for (n = 0; n < df_parts; n++) {
-	if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
-	    return snpack(symon_buf, maxlen, st->arg, MT_DF,
-			  (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
-			  (u_int64_t)df_stats[n].f_files,
-			  (u_int64_t)df_stats[n].f_ffree,
-			  (u_int64_t)df_stats[n].f_syncwrites,
-			  (u_int64_t)df_stats[n].f_asyncwrites);
-	}
+        if (!strncmp(df_stats[n].f_mntfromname, st->parg.df.rawdev, SYMON_DFNAMESIZE)) {
+            return snpack(symon_buf, maxlen, st->arg, MT_DF,
+                          (u_int64_t)fsbtoblk(df_stats[n].f_blocks, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bfree, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)fsbtoblk(df_stats[n].f_bavail, df_stats[n].f_bsize, SYMON_DFBLOCKSIZE),
+                          (u_int64_t)df_stats[n].f_files,
+                          (u_int64_t)df_stats[n].f_ffree,
+                          (u_int64_t)df_stats[n].f_syncwrites,
+                          (u_int64_t)df_stats[n].f_asyncwrites);
+        }
     }
 
     warning("df(%.200s) failed (no such device)", st->arg);

+ 17 - 17
symon/platform/OpenBSD/sm_if.c

@@ -1,4 +1,4 @@
-/* $Id: sm_if.c,v 1.15 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_if.c,v 1.16 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -64,10 +64,10 @@ void
 init_if(struct stream *st)
 {
     if (if_s == -1) {
-	if ((if_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-	    fatal("%s:%d: socket failed, %.200",
-		  __FILE__, __LINE__, strerror(errno));
-	}
+        if ((if_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+            fatal("%s:%d: socket failed, %.200",
+                  __FILE__, __LINE__, strerror(errno));
+        }
     }
 
     strncpy(st->parg.ifr.ifr_name, st->arg, IFNAMSIZ - 1);
@@ -88,19 +88,19 @@ get_if(char *symon_buf, int maxlen, struct stream *st)
     st->parg.ifr.ifr_data = (caddr_t) &ifdata;
 
     if (ioctl(if_s, SIOCGIFDATA, &st->parg.ifr)) {
-	warning("if(%.200s) failed (ioctl error)", st->arg);
-	return 0;
+        warning("if(%.200s) failed (ioctl error)", st->arg);
+        return 0;
     }
 
     return snpack(symon_buf, maxlen, st->arg, MT_IF,
-		  ifdata.ifi_ipackets,
-		  ifdata.ifi_opackets,
-		  ifdata.ifi_ibytes,
-		  ifdata.ifi_obytes,
-		  ifdata.ifi_imcasts,
-		  ifdata.ifi_omcasts,
-		  ifdata.ifi_ierrors,
-		  ifdata.ifi_oerrors,
-		  ifdata.ifi_collisions,
-		  ifdata.ifi_iqdrops);
+                  ifdata.ifi_ipackets,
+                  ifdata.ifi_opackets,
+                  ifdata.ifi_ibytes,
+                  ifdata.ifi_obytes,
+                  ifdata.ifi_imcasts,
+                  ifdata.ifi_omcasts,
+                  ifdata.ifi_ierrors,
+                  ifdata.ifi_oerrors,
+                  ifdata.ifi_collisions,
+                  ifdata.ifi_iqdrops);
 }

+ 43 - 43
symon/platform/OpenBSD/sm_io.c

@@ -1,4 +1,4 @@
-/* $Id: sm_io.c,v 1.18 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_io.c,v 1.19 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -71,44 +71,44 @@ gets_io()
     mib[1] = HW_DISKCOUNT;
     size = sizeof(dks);
     if (sysctl(mib, 2, &dks, &size, NULL, 0) < 0) {
-	fatal("%s:%d: sysctl failed: can't get hw.diskcount",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: sysctl failed: can't get hw.diskcount",
+              __FILE__, __LINE__);
     }
 
     mib[0] = CTL_HW;
     mib[1] = HW_DISKNAMES;
     strsize = 0;
     if (sysctl(mib, 2, NULL, &strsize, NULL, 0) < 0) {
-	fatal("%s:%d: sysctl failed: can't get hw.disknames",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: sysctl failed: can't get hw.disknames",
+              __FILE__, __LINE__);
     }
 
     /* increase buffers if necessary */
     if (dks > io_maxdks || strsize > io_maxstr) {
-	io_maxdks = dks;
-	io_maxstr = strsize;
-
-	if (io_maxdks > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for diskstat structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
-
-	if (io_maxstr > SYMON_MAX_OBJSIZE) {
-	    fatal("%s:%d: string size exceeded (%d)",
-		  __FILE__, __LINE__, SYMON_MAX_OBJSIZE);
-	}
-
-	io_dkstats = xrealloc(io_dkstats, io_maxdks * sizeof(struct diskstats));
-	io_dknames = xrealloc(io_dknames, io_maxdks * sizeof(char *));
-	io_dkstr = xrealloc(io_dkstr, io_maxstr + 1);
+        io_maxdks = dks;
+        io_maxstr = strsize;
+
+        if (io_maxdks > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for diskstat structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
+
+        if (io_maxstr > SYMON_MAX_OBJSIZE) {
+            fatal("%s:%d: string size exceeded (%d)",
+                  __FILE__, __LINE__, SYMON_MAX_OBJSIZE);
+        }
+
+        io_dkstats = xrealloc(io_dkstats, io_maxdks * sizeof(struct diskstats));
+        io_dknames = xrealloc(io_dknames, io_maxdks * sizeof(char *));
+        io_dkstr = xrealloc(io_dkstr, io_maxstr + 1);
     }
 
     /* read data in anger */
     mib[0] = CTL_HW;
     mib[1] = HW_DISKNAMES;
     if (sysctl(mib, 2, io_dkstr, &io_maxstr, NULL, 0) < 0) {
-	fatal("%s:%d: io can't get hw.disknames"
-	      __FILE__, __LINE__);
+        fatal("%s:%d: io can't get hw.disknames"
+              __FILE__, __LINE__);
     }
     io_dkstr[io_maxstr] = '\0';
 
@@ -116,8 +116,8 @@ gets_io()
     mib[1] = HW_DISKSTATS;
     size = io_maxdks * sizeof(struct diskstats);
     if (sysctl(mib, 2, io_dkstats, &size, NULL, 0) < 0) {
-	fatal("%s:%d: io can't get hw.diskstats"
-	      __FILE__, __LINE__);
+        fatal("%s:%d: io can't get hw.diskstats"
+              __FILE__, __LINE__);
     }
 
     p = io_dkstr;
@@ -126,12 +126,12 @@ gets_io()
     io_dknames[io_dks] = p;
 
     while ((*p != '\0') && ((p - io_dkstr) < io_maxstr)) {
-	if ((*p == ',') && (*p+1 != '\0')) {
-	    *p = '\0';
-	    io_dks++; p++;
-	    io_dknames[io_dks] = p;
-	}
-	p++;
+        if ((*p == ',') && (*p+1 != '\0')) {
+            *p = '\0';
+            io_dks++; p++;
+            io_dknames[io_dks] = p;
+        }
+        p++;
     }
 }
 
@@ -148,20 +148,20 @@ get_io(char *symon_buf, int maxlen, struct stream *st)
 
     /* look for disk */
     for (i = 0; i <= io_dks; i++) {
-	if (strncmp(io_dknames[i], st->arg,
-		    (io_dkstr + io_maxstr - io_dknames[i])) == 0)
+        if (strncmp(io_dknames[i], st->arg,
+                    (io_dkstr + io_maxstr - io_dknames[i])) == 0)
 #ifdef HAS_IO2
-	    return snpack(symon_buf, maxlen, st->arg, MT_IO2,
-			  io_dkstats[i].ds_rxfer,
-			  io_dkstats[i].ds_wxfer,
-			  io_dkstats[i].ds_seek,
-			  io_dkstats[i].ds_rbytes,
-			  io_dkstats[i].ds_wbytes);
+            return snpack(symon_buf, maxlen, st->arg, MT_IO2,
+                          io_dkstats[i].ds_rxfer,
+                          io_dkstats[i].ds_wxfer,
+                          io_dkstats[i].ds_seek,
+                          io_dkstats[i].ds_rbytes,
+                          io_dkstats[i].ds_wbytes);
 #else
-	    return snpack(symon_buf, maxlen, st->arg, MT_IO1,
-			  io_dkstats[i].ds_xfer,
-			  io_dkstats[i].ds_seek,
-			  io_dkstats[i].ds_bytes);
+            return snpack(symon_buf, maxlen, st->arg, MT_IO1,
+                          io_dkstats[i].ds_xfer,
+                          io_dkstats[i].ds_seek,
+                          io_dkstats[i].ds_bytes);
 #endif
     }
 

+ 49 - 49
symon/platform/OpenBSD/sm_mbuf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mbuf.c,v 1.7 2006/09/10 19:50:29 dijkstra Exp $ */
+/* $Id: sm_mbuf.c,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2003 Daniel Hartmeier
@@ -81,8 +81,8 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     mib[1] = KERN_MBSTAT;
     size = sizeof(mbstat);
     if (sysctl(mib, 2, &mbstat, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return 0;
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return 0;
     }
 
     mib[0] = CTL_KERN;
@@ -90,48 +90,48 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     mib[2] = KERN_POOL_NPOOLS;
     size = sizeof(npools);
     if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) {
-	warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	return 0;
+        warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+        return 0;
     }
 
     for (i = 1; npools; ++i) {
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_POOL;
-	mib[2] = KERN_POOL_POOL;
-	mib[3] = i;
-	size = sizeof(pool);
-	if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return 0;
-	}
-	npools--;
-	mib[2] = KERN_POOL_NAME;
-	size = sizeof(name);
-	if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
-	    warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
-	    return (0);
-	}
-	if (!strcmp(name, "mbpl")) {
-	    bcopy(&pool, &mbpool, sizeof(pool));
-	    flag |= 1;
-	} else if (!strcmp(name, "mclpl")) {
-	    bcopy(&pool, &mclpool, sizeof(pool));
-	    flag |= 2;
-	}
-	if (flag == 3)
-	    break;
+        mib[0] = CTL_KERN;
+        mib[1] = KERN_POOL;
+        mib[2] = KERN_POOL_POOL;
+        mib[3] = i;
+        size = sizeof(pool);
+        if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return 0;
+        }
+        npools--;
+        mib[2] = KERN_POOL_NAME;
+        size = sizeof(name);
+        if (sysctl(mib, 4, name, &size, NULL, 0) < 0) {
+            warning("mbuf(%.200s) failed (sysctl() %.200s)", st->arg, strerror(errno));
+            return (0);
+        }
+        if (!strcmp(name, "mbpl")) {
+            bcopy(&pool, &mbpool, sizeof(pool));
+            flag |= 1;
+        } else if (!strcmp(name, "mclpl")) {
+            bcopy(&pool, &mclpool, sizeof(pool));
+            flag |= 2;
+        }
+        if (flag == 3)
+            break;
     }
     if (flag != 3) {
-	warning("mbuf(%.200s) failed (flag != 3)", st->arg);
-	return 0;
+        warning("mbuf(%.200s) failed (flag != 3)", st->arg);
+        return 0;
     }
 
     totmbufs = 0;
     for (i = 0; i < nmbtypes; ++i)
-	totmbufs += mbstat.m_mtypes[i];
+        totmbufs += mbstat.m_mtypes[i];
     totmem = (mbpool.pr_npages + mclpool.pr_npages) * page_size;
     totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
-	(mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
+        (mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
     totpct = (totmem == 0) ? 0 : ((totused * 100) / totmem);
 
     stats[0] = totmbufs;
@@ -151,20 +151,20 @@ get_mbuf(char *symon_buf, int maxlen, struct stream *st)
     stats[14] = mbstat.m_drain;
 
     return snpack(symon_buf, maxlen, st->arg, MT_MBUF,
-		  stats[0],
-		  stats[1],
-		  stats[2],
-		  stats[3],
-		  stats[4],
-		  stats[5],
-		  stats[6],
-		  stats[7],
-		  stats[8],
-		  stats[9],
-		  stats[10],
-		  stats[11],
-		  stats[12],
-		  stats[13],
-		  stats[14]);
+                  stats[0],
+                  stats[1],
+                  stats[2],
+                  stats[3],
+                  stats[4],
+                  stats[5],
+                  stats[6],
+                  stats[7],
+                  stats[8],
+                  stats[9],
+                  stats[10],
+                  stats[11],
+                  stats[12],
+                  stats[13],
+                  stats[14]);
 }
 #endif /* HAS_KERN_MBSTAT */

+ 23 - 23
symon/platform/OpenBSD/sm_mem.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mem.c,v 1.20 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.21 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -68,8 +68,8 @@ init_mem(struct stream *st)
     me_pagesize = sysconf(_SC_PAGESIZE);
     me_pageshift = 0;
     while (me_pagesize > 1) {
-	me_pageshift++;
-	me_pagesize >>= 1;
+        me_pageshift++;
+        me_pagesize >>= 1;
     }
 
     /* get total -- systemwide main memory usage structure */
@@ -79,21 +79,21 @@ init_mem(struct stream *st)
     me_nswap = swapctl(SWAP_NSWAP, 0, 0);
 
     if (me_swdev) {
-	xfree(me_swdev);
+        xfree(me_swdev);
     }
 
     if (me_nswap != 0) {
-	me_swdev = xmalloc(me_nswap * sizeof(*me_swdev));
+        me_swdev = xmalloc(me_nswap * sizeof(*me_swdev));
     } else {
-	me_swdev = NULL;
+        me_swdev = NULL;
     }
 
     if (me_swdev == NULL && me_nswap != 0) {
-	me_nswap = 0;
+        me_nswap = 0;
     }
 
     if (st != NULL) {
-	info("started module mem(%.200s)", st->arg);
+        info("started module mem(%.200s)", st->arg);
     }
 }
 
@@ -103,8 +103,8 @@ gets_mem()
     int i, rnswap;
 
     if (sysctl(me_vm_mib, 2, &me_vmtotal, &me_vmsize, NULL, 0) < 0) {
-	warning("%s:%d: sysctl failed", __FILE__, __LINE__);
-	bzero(&me_vmtotal, sizeof(me_vmtotal));
+        warning("%s:%d: sysctl failed", __FILE__, __LINE__);
+        bzero(&me_vmtotal, sizeof(me_vmtotal));
     }
 
     /* convert memory stats to Kbytes */
@@ -114,20 +114,20 @@ gets_mem()
 
     rnswap = swapctl(SWAP_STATS, me_swdev, me_nswap);
     if (rnswap == -1) {
-	/* A swap device may have been added; increase and retry */
-	init_mem(NULL);
-	rnswap = swapctl(SWAP_STATS, me_swdev, me_nswap);
+        /* A swap device may have been added; increase and retry */
+        init_mem(NULL);
+        rnswap = swapctl(SWAP_STATS, me_swdev, me_nswap);
     }
 
     me_stats[3] = me_stats[4] = 0;
-    if (rnswap == me_nswap) {	/* Read swap successfully */
-	/* Total things up */
-	for (i = 0; i < me_nswap; i++) {
-	    if (me_swdev[i].se_flags & SWF_ENABLE) {
-		me_stats[3] += (me_swdev[i].se_inuse * DEV_BSIZE);
-		me_stats[4] += (me_swdev[i].se_nblks * DEV_BSIZE);
-	    }
-	}
+    if (rnswap == me_nswap) {   /* Read swap successfully */
+        /* Total things up */
+        for (i = 0; i < me_nswap; i++) {
+            if (me_swdev[i].se_flags & SWF_ENABLE) {
+                me_stats[3] += (me_swdev[i].se_inuse * DEV_BSIZE);
+                me_stats[4] += (me_swdev[i].se_nblks * DEV_BSIZE);
+            }
+        }
     }
 }
 
@@ -135,6 +135,6 @@ int
 get_mem(char *symon_buf, int maxlen, struct stream *st)
 {
     return snpack(symon_buf, maxlen, st->arg, MT_MEM,
-		  me_stats[0], me_stats[1], me_stats[2],
-		  me_stats[3], me_stats[4]);
+                  me_stats[0], me_stats[1], me_stats[2],
+                  me_stats[3], me_stats[4]);
 }

+ 33 - 33
symon/platform/OpenBSD/sm_pf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_pf.c,v 1.12 2006/11/07 08:00:20 dijkstra Exp $ */
+/* $Id: sm_pf.c,v 1.13 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2002 Daniel Hartmeier
@@ -93,7 +93,7 @@ void
 privinit_pf()
 {
     if ((pf_dev = open("/dev/pf", O_RDONLY)) == -1) {
-	warning("could not open \"/dev/pf\", %.200s", strerror(errno));
+        warning("could not open \"/dev/pf\", %.200s", strerror(errno));
     }
 }
 
@@ -101,7 +101,7 @@ void
 init_pf(struct stream *st)
 {
     if (pf_dev == -1) {
-	privinit_pf();
+        privinit_pf();
     }
 
     info("started module pf()");
@@ -111,15 +111,15 @@ void
 gets_pf()
 {
     if (pf_dev == -1) {
-	warning("could not get pf stats (dev == -1)");
-	pf_stat.running = 0;
-	return;
+        warning("could not get pf stats (dev == -1)");
+        pf_stat.running = 0;
+        return;
     }
 
     if (ioctl(pf_dev, DIOCGETSTATUS, &pf_stat)) {
-	warning("could not get pf stats (ioctl error)");
-	pf_stat.running = 0;
-	return;
+        warning("could not get pf stats (ioctl error)");
+        pf_stat.running = 0;
+        return;
     }
 }
 
@@ -129,33 +129,33 @@ get_pf(char *symon_buf, int maxlen, struct stream *st)
     u_int64_t n;
 
     if (!pf_stat.running) {
-	return 0;
+        return 0;
     }
 
     n = pf_stat.states;
     return snpack(symon_buf, maxlen, st->arg, MT_PF,
-		  pf_stat.bcounters[0][0],
-		  pf_stat.bcounters[0][1],
-		  pf_stat.bcounters[1][0],
-		  pf_stat.bcounters[1][1],
-		  pf_stat.pcounters[0][0][PF_PASS],
-		  pf_stat.pcounters[0][0][PF_DROP],
-		  pf_stat.pcounters[0][1][PF_PASS],
-		  pf_stat.pcounters[0][1][PF_DROP],
-		  pf_stat.pcounters[1][0][PF_PASS],
-		  pf_stat.pcounters[1][0][PF_DROP],
-		  pf_stat.pcounters[1][1][PF_PASS],
-		  pf_stat.pcounters[1][1][PF_DROP],
-		  n,
-		  pf_stat.fcounters[0],
-		  pf_stat.fcounters[1],
-		  pf_stat.fcounters[2],
-		  pf_stat.counters[0],
-		  pf_stat.counters[1],
-		  pf_stat.counters[2],
-		  pf_stat.counters[3],
-		  pf_stat.counters[4],
-		  pf_stat.counters[5]
-	);
+                  pf_stat.bcounters[0][0],
+                  pf_stat.bcounters[0][1],
+                  pf_stat.bcounters[1][0],
+                  pf_stat.bcounters[1][1],
+                  pf_stat.pcounters[0][0][PF_PASS],
+                  pf_stat.pcounters[0][0][PF_DROP],
+                  pf_stat.pcounters[0][1][PF_PASS],
+                  pf_stat.pcounters[0][1][PF_DROP],
+                  pf_stat.pcounters[1][0][PF_PASS],
+                  pf_stat.pcounters[1][0][PF_DROP],
+                  pf_stat.pcounters[1][1][PF_PASS],
+                  pf_stat.pcounters[1][1][PF_DROP],
+                  n,
+                  pf_stat.fcounters[0],
+                  pf_stat.fcounters[1],
+                  pf_stat.fcounters[2],
+                  pf_stat.counters[0],
+                  pf_stat.counters[1],
+                  pf_stat.counters[2],
+                  pf_stat.counters[3],
+                  pf_stat.counters[4],
+                  pf_stat.counters[5]
+        );
 }
 #endif /* HAS_PFVAR_H */

+ 69 - 69
symon/platform/OpenBSD/sm_pfq.c

@@ -1,4 +1,4 @@
-/* $Id: sm_pfq.c,v 1.4 2005/10/21 14:58:46 dijkstra Exp $ */
+/* $Id: sm_pfq.c,v 1.5 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2005 J. Martin Petersen
@@ -115,7 +115,7 @@ void
 privinit_pfq()
 {
     if ((pfq_dev = open("/dev/pf", O_RDONLY)) == -1) {
-	warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
+        warning("pfq: could not open \"/dev/pf\", %.200s", strerror(errno));
     }
 }
 
@@ -123,7 +123,7 @@ void
 init_pfq(struct stream *st)
 {
     if (pfq_dev == -1) {
-	privinit_pfq();
+        privinit_pfq();
     }
 
     info("started module pfq(%.200s)", st->arg);
@@ -143,78 +143,78 @@ gets_pfq()
     bzero(&q, sizeof(q));
 
     if (ioctl(pfq_dev, DIOCGETALTQS, &qs)) {
-	fatal("pfq: DIOCGETALTQS failed");
+        fatal("pfq: DIOCGETALTQS failed");
     }
     nqs = qs.nr;
 
     /* Allocate memory for info for the nqs queues */
     if (nqs > pfq_max) {
-	if (pfq_stats) {
-	    xfree(pfq_stats);
-	}
+        if (pfq_stats) {
+            xfree(pfq_stats);
+        }
 
-	pfq_max = 2 * nqs;
+        pfq_max = 2 * nqs;
 
-	if (pfq_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for pf queue structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (pfq_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for pf queue structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	pfq_stats = xmalloc(pfq_max * sizeof(struct altq_stats));
+        pfq_stats = xmalloc(pfq_max * sizeof(struct altq_stats));
     }
 
     pfq_cur = 0;
 
     /* Loop through the queues, copy info */
     for (i = 0; i < nqs; i++) {
-	qs.nr = i;
-	if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
-	    fatal("pfq: DIOCGETALTQ failed");
-	}
-
-	/* only process the non-empty queues */
-	if (qs.altq.qid > 0) {
-	    stats.nr = qs.nr;
-	    stats.ticket = qs.ticket;
-	    stats.buf = &q;
-	    stats.nbytes = sizeof(q);
-
-	    if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
-		fatal("pfq: DIOCGETQSTATS failed");
-	    }
-
-	    /* We're now ready to copy the data we want. */
-	    snprintf(pfq_stats[pfq_cur].qname, sizeof(pfq_stats[0].qname),
-		     "%s/%s", qs.altq.ifname, qs.altq.qname);
-
-	    switch (qs.altq.scheduler) {
-	    case ALTQT_CBQ:
-		pfq_stats[pfq_cur].sent_bytes = q.cbq.xmit_cnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.cbq.xmit_cnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.cbq.drop_cnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.cbq.drop_cnt.packets;
-		break;
-
-	    case ALTQT_PRIQ:
-		pfq_stats[pfq_cur].sent_bytes = q.priq.xmitcnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.priq.xmitcnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.priq.dropcnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.priq.dropcnt.packets;
-		break;
-
-	    case ALTQT_HFSC:
-		pfq_stats[pfq_cur].sent_bytes = q.hfsc.xmit_cnt.bytes;
-		pfq_stats[pfq_cur].sent_packets = q.hfsc.xmit_cnt.packets;
-		pfq_stats[pfq_cur].drop_bytes = q.hfsc.drop_cnt.bytes;
-		pfq_stats[pfq_cur].drop_packets = q.hfsc.drop_cnt.packets;
-		break;
-
-	    default:
-		warning("pfq: unknown altq scheduler type encountered");
-		break;
-	    }
-	    pfq_cur++;
-	}
+        qs.nr = i;
+        if (ioctl(pfq_dev, DIOCGETALTQ, &qs)) {
+            fatal("pfq: DIOCGETALTQ failed");
+        }
+
+        /* only process the non-empty queues */
+        if (qs.altq.qid > 0) {
+            stats.nr = qs.nr;
+            stats.ticket = qs.ticket;
+            stats.buf = &q;
+            stats.nbytes = sizeof(q);
+
+            if (ioctl(pfq_dev, DIOCGETQSTATS, &stats)) {
+                fatal("pfq: DIOCGETQSTATS failed");
+            }
+
+            /* We're now ready to copy the data we want. */
+            snprintf(pfq_stats[pfq_cur].qname, sizeof(pfq_stats[0].qname),
+                     "%s/%s", qs.altq.ifname, qs.altq.qname);
+
+            switch (qs.altq.scheduler) {
+            case ALTQT_CBQ:
+                pfq_stats[pfq_cur].sent_bytes = q.cbq.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.cbq.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.cbq.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.cbq.drop_cnt.packets;
+                break;
+
+            case ALTQT_PRIQ:
+                pfq_stats[pfq_cur].sent_bytes = q.priq.xmitcnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.priq.xmitcnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.priq.dropcnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.priq.dropcnt.packets;
+                break;
+
+            case ALTQT_HFSC:
+                pfq_stats[pfq_cur].sent_bytes = q.hfsc.xmit_cnt.bytes;
+                pfq_stats[pfq_cur].sent_packets = q.hfsc.xmit_cnt.packets;
+                pfq_stats[pfq_cur].drop_bytes = q.hfsc.drop_cnt.bytes;
+                pfq_stats[pfq_cur].drop_packets = q.hfsc.drop_cnt.packets;
+                break;
+
+            default:
+                warning("pfq: unknown altq scheduler type encountered");
+                break;
+            }
+            pfq_cur++;
+        }
     }
 }
 
@@ -224,14 +224,14 @@ get_pfq(char *symon_buf, int maxlen, struct stream *st)
     unsigned int i;
 
     for (i = 0; i < pfq_cur; i++) {
-	if (strncmp(pfq_stats[i].qname, st->arg, sizeof(pfq_stats[0].qname)) == 0) {
-	    return snpack(symon_buf, maxlen, st->arg, MT_PFQ,
-			  pfq_stats[i].sent_bytes,
-			  pfq_stats[i].sent_packets,
-			  pfq_stats[i].drop_bytes,
-			  pfq_stats[i].drop_packets
-		);
-	}
+        if (strncmp(pfq_stats[i].qname, st->arg, sizeof(pfq_stats[0].qname)) == 0) {
+            return snpack(symon_buf, maxlen, st->arg, MT_PFQ,
+                          pfq_stats[i].sent_bytes,
+                          pfq_stats[i].sent_packets,
+                          pfq_stats[i].drop_bytes,
+                          pfq_stats[i].drop_packets
+                );
+        }
     }
 
     return 0;

+ 37 - 37
symon/platform/OpenBSD/sm_proc.c

@@ -1,4 +1,4 @@
-/* $Id: sm_proc.c,v 1.7 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_proc.c,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -76,20 +76,20 @@ gets_proc()
     mib[1] = KERN_NPROCS;
     size = sizeof(procs);
     if (sysctl(mib, 2, &procs, &size, NULL, 0) < 0) {
-	fatal("%s:%d: sysctl failed: can't get kern.nproc",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: sysctl failed: can't get kern.nproc",
+              __FILE__, __LINE__);
     }
 
     /* increase buffers if necessary */
     if (procs > proc_max) {
-	proc_max = (procs * 5) / 4;
+        proc_max = (procs * 5) / 4;
 
-	if (proc_max > SYMON_MAX_DOBJECTS) {
-	    fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
-		  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
-	}
+        if (proc_max > SYMON_MAX_DOBJECTS) {
+            fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
+                  __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
+        }
 
-	proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
+        proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
     }
 
     /* read data in anger */
@@ -98,17 +98,17 @@ gets_proc()
     mib[2] = KERN_PROC_KTHREAD;
     size = proc_max * sizeof(struct kinfo_proc);
     if (sysctl(mib, 3, proc_ps, &size, NULL, 0) < 0) {
-	warning("proc probe cannot get processes");
-	proc_cur = 0;
-	return;
+        warning("proc probe cannot get processes");
+        proc_cur = 0;
+        return;
     }
 
     if (size % sizeof(struct kinfo_proc) != 0) {
-	warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
-		size, sizeof(struct kinfo_proc));
-	proc_cur = 0;
+        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
+                size, sizeof(struct kinfo_proc));
+        proc_cur = 0;
     } else {
-	proc_cur = size / sizeof(struct kinfo_proc);
+        proc_cur = size / sizeof(struct kinfo_proc);
     }
 }
 
@@ -127,7 +127,7 @@ init_proc(struct stream *st)
 
     /* get clockrate */
     if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1) {
-	fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
+        fatal("%s:%d: could not get clockrate", __FILE__, __LINE__);
     }
 
     proc_stathz = cinf.stathz;
@@ -136,8 +136,8 @@ init_proc(struct stream *st)
     proc_pagesize = sysconf(_SC_PAGESIZE);
     proc_pageshift = 0;
     while (proc_pagesize > 1) {
-	proc_pageshift++;
-	proc_pagesize >>= 1;
+        proc_pageshift++;
+        proc_pagesize >>= 1;
     }
 
     info("started module proc(%.200s)", st->arg);
@@ -160,21 +160,21 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     int n = 0;
 
     for (pp = proc_ps, i = 0; i < proc_cur; pp++, i++) {
-	 if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
-	     /* cpu time - accumulated */
-	     cpu_uticks += pp->kp_proc.p_uticks;  /* user */
-	     cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
-	     cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
-	     /* cpu time - percentage since last measurement */
-	     cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
-	     cpu_pcti += cpu_pct;
-	     /* memory size - shared pages are counted multiple times */
-	     mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
-				     pp->kp_eproc.e_vm.vm_dsize + /* data */
-				     pp->kp_eproc.e_vm.vm_ssize); /* stack */
-	     mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
-	     n++;
-	 }
+         if (strncmp(st->arg, pp->kp_proc.p_comm, strlen(st->arg)) == 0) {
+             /* cpu time - accumulated */
+             cpu_uticks += pp->kp_proc.p_uticks;  /* user */
+             cpu_sticks += pp->kp_proc.p_sticks;  /* sys  */
+             cpu_iticks += pp->kp_proc.p_iticks;  /* int  */
+             /* cpu time - percentage since last measurement */
+             cpu_pct = pctdouble(pp->kp_proc.p_pctcpu) * 100.0;
+             cpu_pcti += cpu_pct;
+             /* memory size - shared pages are counted multiple times */
+             mem_procsize += pagetob(pp->kp_eproc.e_vm.vm_tsize + /* text pages */
+                                     pp->kp_eproc.e_vm.vm_dsize + /* data */
+                                     pp->kp_eproc.e_vm.vm_ssize); /* stack */
+             mem_rss += pagetob(pp->kp_eproc.e_vm.vm_rssize);     /* rss  */
+             n++;
+         }
     }
 
     /* calc total cpu_secs spent */
@@ -182,7 +182,7 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     cpu_secs = cpu_ticks / proc_stathz;
 
     return snpack(symon_buf, maxlen, st->arg, MT_PROC,
-		  n,
-		  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
-		  mem_procsize, mem_rss );
+                  n,
+                  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
+                  mem_procsize, mem_rss );
 }

+ 109 - 34
symon/platform/OpenBSD/sm_sensor.c

@@ -1,7 +1,9 @@
-/* $Id: sm_sensor.c,v 1.7 2005/10/18 19:58:11 dijkstra Exp $ */
+/* $Id: sm_sensor.c,v 1.10 2007/02/11 20:26:56 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
+ * Copyright (c) 2006-2007 Constantine A. Murenin
+ *                         <cnst+symon@bugmail.mojo.ru>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -46,10 +48,14 @@
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "error.h"
 #include "symon.h"
 
+/* Globals for this module start with sn_ */
+static struct sensor sn_sensor;
+
 #ifndef HAS_SENSORS_H
 void
 privinit_sensor()
@@ -71,11 +77,6 @@ get_sensor(char *symon_buf, int maxlen, struct stream *st)
 #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()
 {
@@ -85,44 +86,118 @@ privinit_sensor()
 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);
+
+#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 = xstrdup(st->arg);
+    bufp = bufpo;
+
+    if ((devname = strsep(&bufp, ".")) == NULL)
+        fatal("sensor(%.200s): incomplete specification", 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("sensor(%.200s): incomplete specification", 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;
+
+    xfree(bufpo);
+
+#endif /* !HAS_SENSORDEV */
 
-    info("started module sensors(%.200s)", st->arg);
+    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;
-
-    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;
+    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);
+
+        return 0;
     } else {
-	switch (sn_sensor.type) {
-	case SENSOR_TEMP:
-	    t = (double) (sn_sensor.value / 1000.0 / 1000.0) - 273.16;
-	    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);
+        switch (sn_sensor.type) {
+        case SENSOR_TEMP:
+            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 */

+ 122 - 111
symon/symon/readconf.c

@@ -1,4 +1,4 @@
-/* $Id: readconf.c,v 1.23 2005/10/16 15:27:01 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.25 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -56,33 +56,33 @@ read_host_port(struct muxlist * mul, struct mux * mux, struct lex * l)
 
     lex_nexttoken(l);
     if (!getip(l->token, AF_INET) && !getip(l->token, AF_INET6)) {
-	warning("%.200s:%d: could not resolve '%.200s'",
-		l->filename, l->cline, l->token);
-	return 0;
+        warning("%.200s:%d: could not resolve '%.200s'",
+                l->filename, l->cline, l->token);
+        return 0;
     }
 
     mux->addr = xstrdup((const char *) &res_host);
 
     /* check for port statement */
     if (!lex_nexttoken(l))
-	return 1;
+        return 1;
 
     if (l->op == LXT_PORT || l->op == LXT_COMMA)
-	lex_nexttoken(l);
+        lex_nexttoken(l);
 
     if (l->type != LXY_NUMBER) {
-	lex_ungettoken(l);
-	mux->port = xstrdup(default_symux_port);
+        lex_ungettoken(l);
+        mux->port = xstrdup(default_symux_port);
     } else {
-	mux->port = xstrdup((const char *) l->token);
+        mux->port = xstrdup((const char *) l->token);
     }
 
     bzero(&muxname, sizeof(muxname));
     snprintf(&muxname[0], sizeof(muxname), "%s %s", mux->addr, mux->port);
     if (rename_mux(mul, mux, muxname) == NULL) {
-	warning("%.200s:%d: monitored data for host '%.200s' has already been specified",
-		l->filename, l->cline, muxname);
-	return 0;
+        warning("%.200s:%d: monitored data for host '%.200s' has already been specified",
+                l->filename, l->cline, muxname);
+        return 0;
     }
 
     return 1;
@@ -96,68 +96,68 @@ read_symon_args(struct mux * mux, struct lex * l)
     int st;
 
     EXPECT(l, LXT_BEGIN)
-	while (lex_nexttoken(l) && l->op != LXT_END) {
-	switch (l->op) {
-	case LXT_CPU:
-	case LXT_DF:
-	case LXT_IF:
-	case LXT_IO:
-	case LXT_IO1:
-	case LXT_MEM:
-	case LXT_PF:
-	case LXT_PFQ:
-	case LXT_MBUF:
-	case LXT_DEBUG:
-	case LXT_PROC:
-	case LXT_SENSOR:
-	    st = token2type(l->op);
-	    strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
-
-	    /* parse arg */
-	    lex_nexttoken(l);
-	    if (l->op == LXT_OPEN) {
-		lex_nexttoken(l);
-		if (l->op == LXT_CLOSE) {
-		    parse_error(l, "<stream argument>");
-		    return 0;
-		}
-		strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
-		lex_nexttoken(l);
-		if (l->op != LXT_CLOSE) {
-		    parse_error(l, ")");
-		    return 0;
-		}
-	    } else {
-		lex_ungettoken(l);
-		sa[0] = '\0';
-	    }
-
-	    if (strlen(sa) > (SYMON_PS_ARGLEN - 1)) {
-		warning("%.200s:%d: argument '%.200s' too long for network format, "
-			"will send leading " SYMON_PS_ARGLENSTR " chars only",
-			l->filename, l->cline, sa);
-	    }
-
-	    if ((add_mux_stream(mux, st, sa)) == NULL) {
-		warning("%.200s:%d: stream %.200s(%.200s) redefined",
-			l->filename, l->cline, sn, sa);
-		return 0;
-	    }
-
-	    break;
-	case LXT_COMMA:
-	    break;
-	default:
-	    parse_error(l, "{cpu|mem|if|io|pf|debug|sensor}");
-	    return 0;
-	    break;
-	}
+        while (lex_nexttoken(l) && l->op != LXT_END) {
+        switch (l->op) {
+        case LXT_CPU:
+        case LXT_DF:
+        case LXT_IF:
+        case LXT_IO:
+        case LXT_IO1:
+        case LXT_MEM:
+        case LXT_PF:
+        case LXT_PFQ:
+        case LXT_MBUF:
+        case LXT_DEBUG:
+        case LXT_PROC:
+        case LXT_SENSOR:
+            st = token2type(l->op);
+            strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
+
+            /* parse arg */
+            lex_nexttoken(l);
+            if (l->op == LXT_OPEN) {
+                lex_nexttoken(l);
+                if (l->op == LXT_CLOSE) {
+                    parse_error(l, "<stream argument>");
+                    return 0;
+                }
+                strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
+                lex_nexttoken(l);
+                if (l->op != LXT_CLOSE) {
+                    parse_error(l, ")");
+                    return 0;
+                }
+            } else {
+                lex_ungettoken(l);
+                sa[0] = '\0';
+            }
+
+            if (strlen(sa) > (SYMON_PS_ARGLENV2 - 1)) {
+                warning("%.200s:%d: argument '%.200s' too long for network format, "
+                        "will send leading " SYMON_PS_ARGLENSTRV2 " chars only",
+                        l->filename, l->cline, sa);
+            }
+
+            if ((add_mux_stream(mux, st, sa)) == NULL) {
+                warning("%.200s:%d: stream %.200s(%.200s) redefined",
+                        l->filename, l->cline, sn, sa);
+                return 0;
+            }
+
+            break;
+        case LXT_COMMA:
+            break;
+        default:
+            parse_error(l, "{cpu|df|if|io|io1|mem|pf|pfq|mbuf|debug|proc|sensor}");
+            return 0;
+            break;
+        }
     }
 
     return 1;
 }
 
-/* parse monitor <args> stream [to] <host>:<port> */
+/* parse monitor <args> stream [from <host>] [to] <host>:<port> */
 int
 read_monitor(struct muxlist * mul, struct lex * l)
 {
@@ -167,40 +167,51 @@ read_monitor(struct muxlist * mul, struct lex * l)
 
     /* parse [stream(streamarg)]+ */
     if (!read_symon_args(mux, l))
-	return 0;
+        return 0;
 
     lex_nexttoken(l);
 
     /* parse [every x seconds]? */
     if (l->op == LXT_EVERY) {
-	lex_nexttoken(l);
-
-	if (l->op == LXT_SECOND) {
-	    symon_interval = 1;
-	} else if (l->type == LXY_NUMBER) {
-	    symon_interval = l->value;
-	    lex_nexttoken(l);
-	    if (l->op != LXT_SECONDS) {
-		parse_error(l, "seconds");
-	    }
-	} else {
-	    parse_error(l, "<number> ");
-	    return 0;
-	}
-
-	lex_nexttoken(l);
+        lex_nexttoken(l);
+
+        if (l->op == LXT_SECOND) {
+            symon_interval = 1;
+        } else if (l->type == LXY_NUMBER) {
+            symon_interval = l->value;
+            lex_nexttoken(l);
+            if (l->op != LXT_SECONDS) {
+                parse_error(l, "seconds");
+            }
+        } else {
+            parse_error(l, "<number> ");
+            return 0;
+        }
+
+        lex_nexttoken(l);
     }
 
-    /* parse [stream to] */
+    /* parse [stream [from <host>] to] */
     if (l->op != LXT_STREAM) {
-	parse_error(l, "stream");
-	return 0;
+        parse_error(l, "stream");
+        return 0;
     }
 
     lex_nexttoken(l);
 
+    if (l->op == LXT_FROM) {
+        lex_nexttoken(l);
+        if (!getip(l->token, AF_INET) && !getip(l->token, AF_INET6)) {
+            warning("%.200s:%d: could not resolve '%.200s'",
+                l->filename, l->cline, l->token);
+            return 0;
+        }
+        mux->localaddr = xstrdup((const char *) &res_host);
+        lex_nexttoken(l);
+    }
+
     if (l->op != LXT_TO)
-	lex_ungettoken(l);
+        lex_ungettoken(l);
 
     /* parse [host [port]?] */
     return read_host_port(mul, mux, l);
@@ -218,34 +229,34 @@ read_config_file(struct muxlist *muxlist, char *filename)
     l = open_lex(filename);
 
     while (lex_nexttoken(l)) {
-	/* expecting keyword now */
-	switch (l->op) {
-	case LXT_MONITOR:
-	    if (!read_monitor(muxlist, l))
-		return 0;
-	    break;
-	default:
-	    parse_error(l, "monitor");
-	    return 0;
-	    break;
-	}
+        /* expecting keyword now */
+        switch (l->op) {
+        case LXT_MONITOR:
+            if (!read_monitor(muxlist, l))
+                return 0;
+            break;
+        default:
+            parse_error(l, "monitor");
+            return 0;
+            break;
+        }
     }
 
     /* sanity checks */
     SLIST_FOREACH(mux, muxlist, muxes) {
-	if (strncmp(SYMON_UNKMUX, mux->name, sizeof(SYMON_UNKMUX)) == 0) {
-	    /* mux was not initialised for some reason */
-	    return 0;
-	}
-	if (SLIST_EMPTY(&mux->sl)) {
-	    warning("%.200s: no monitors selected for mux '%.200s'",
-		    l->filename, mux->name);
-	    return 0;
-	}
+        if (strncmp(SYMON_UNKMUX, mux->name, sizeof(SYMON_UNKMUX)) == 0) {
+            /* mux was not initialised for some reason */
+            return 0;
+        }
+        if (SLIST_EMPTY(&mux->sl)) {
+            warning("%.200s: no monitors selected for mux '%.200s'",
+                    l->filename, mux->name);
+            return 0;
+        }
     }
 
     if (symon_interval < SYMON_DEFAULT_INTERVAL) {
-	warning("%.200s: monitoring set to every %d s", l->filename, symon_interval);
+        warning("%.200s: monitoring set to every %d s", l->filename, symon_interval);
     }
 
     close_lex(l);

+ 2 - 2
symon/symon/readconf.h

@@ -1,4 +1,4 @@
-/* $Id: readconf.h,v 1.7 2004/02/26 22:48:08 dijkstra Exp $ */
+/* $Id: readconf.h,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -38,4 +38,4 @@
 __BEGIN_DECLS
 int read_config_file(struct muxlist *, char *);
 __END_DECLS
-#endif				/* _SYMON_READCONF_H */
+#endif                          /* _SYMON_READCONF_H */

+ 6 - 6
symon/symon/symon.8

@@ -1,6 +1,6 @@
 .\"  -*- nroff -*-
 .\"
-.\" Copyright (c) 2001-2005 Willem Dijkstra
+.\" Copyright (c) 2001-2007 Willem Dijkstra
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -40,9 +40,9 @@
 .Pp
 .Sh DESCRIPTION
 .Nm
-is a lightweight system monitor that measures cpu, memory, debug,
-process, interface and disk statistics every 5 seconds. This information
-is then spooled to
+is a lightweight system monitor that measures cpu, filesystem, interface, disk,
+memory, pf, pf queues, mbuf, proc and sensor statistics every 5 seconds. This
+information is then spooled to
 .Xr symux 8
 for further processing.
 .Pp
@@ -102,7 +102,7 @@ newlines and text behind '#' are ignored. The format in BNF:
 .Pp
 .nf
 monitor-rule = "monitor" "{" resources "}" [every]
-               "stream" ["to"] host [ port ]
+               "stream" ["from" host] ["to"] host [ port ]
 resources    = resource ["(" argument ")"] [ ","|" " resources ]
 argument     = number | interfacename | diskname
 resource     = "cpu" | "mem" | "if" | "io" | "pf" | "pfq" |
@@ -173,7 +173,7 @@ exist.
 .Sh AUTHOR
 Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier helped to port to big-endian
 architectures. Matthew Gream helped to port symon to other BSD platforms.
-
+.Pp
 Port contributors: Marc Balmer, Matthew Gream, Daniel Hartmeier, J. Martin
 Petersen, Fredrik Soderblom and Harm Schotanus.
 .Sh SEE ALSO

+ 106 - 106
symon/symon/symon.c

@@ -1,4 +1,4 @@
-/* $Id: symon.c,v 1.45 2006/09/22 07:13:19 dijkstra Exp $ */
+/* $Id: symon.c,v 1.46 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -92,12 +92,12 @@ set_stream_use(struct muxlist *mul)
     int i;
 
     for (i = 0; i < MT_EOT; i++)
-	streamfunc[i].used = 0;
+        streamfunc[i].used = 0;
 
 
     SLIST_FOREACH(mux, mul, muxes) {
-	SLIST_FOREACH(stream, &mux->sl, streams)
-	    streamfunc[stream->type].used = 1;
+        SLIST_FOREACH(stream, &mux->sl, streams)
+            streamfunc[stream->type].used = 1;
     }
 }
 void
@@ -106,34 +106,34 @@ drop_privileges(int unsecure)
     struct passwd *pw;
 
     if (unsecure) {
-	if (setegid(getgid()) || setgid(getgid()) ||
-	    seteuid(getuid()) || setuid(getuid()))
-	    fatal("can't drop privileges: %.200s", strerror(errno));
+        if (setegid(getgid()) || setgid(getgid()) ||
+            seteuid(getuid()) || setuid(getuid()))
+            fatal("can't drop privileges: %.200s", strerror(errno));
     } else {
-	if ((pw = getpwnam(SYMON_USER)) == NULL)
-	    fatal("could not get user information for user '%.200s': %.200s",
-		  SYMON_USER, strerror(errno));
+        if ((pw = getpwnam(SYMON_USER)) == NULL)
+            fatal("could not get user information for user '%.200s': %.200s",
+                  SYMON_USER, strerror(errno));
 
-	if (chroot(pw->pw_dir) < 0)
-	    fatal("chroot failed: %.200s", strerror(errno));
+        if (chroot(pw->pw_dir) < 0)
+            fatal("chroot failed: %.200s", strerror(errno));
 
-	if (chdir("/") < 0)
-	    fatal("chdir / failed: %.200s", strerror(errno));
+        if (chdir("/") < 0)
+            fatal("chdir / failed: %.200s", strerror(errno));
 
-	if (setgroups(1, &pw->pw_gid))
-	    fatal("can't setgroups: %.200s", strerror(errno));
+        if (setgroups(1, &pw->pw_gid))
+            fatal("can't setgroups: %.200s", strerror(errno));
 
-	if (setgid(pw->pw_gid))
-	    fatal("can't set group id: %.200s", strerror(errno));
+        if (setgid(pw->pw_gid))
+            fatal("can't set group id: %.200s", strerror(errno));
 
-	if (setegid(pw->pw_gid))
-	    fatal("can't set effective group id: %.200s", strerror(errno));
+        if (setegid(pw->pw_gid))
+            fatal("can't set effective group id: %.200s", strerror(errno));
 
-	if (setuid(pw->pw_uid))
-	    fatal("can't set user id: %.200s", strerror(errno));
+        if (setuid(pw->pw_uid))
+            fatal("can't set user id: %.200s", strerror(errno));
 
-	if (seteuid(pw->pw_uid))
-	    fatal("can't set effective user id: %.200s", strerror(errno));
+        if (seteuid(pw->pw_uid))
+            fatal("can't set effective user id: %.200s", strerror(errno));
     }
 }
 /* alarmhandler that gets called every symon_interval */
@@ -188,59 +188,59 @@ main(int argc, char *argv[])
     cfgpath = SYMON_CONFIG_FILE;
 
     while ((ch = getopt(argc, argv, "dvuf:")) != -1) {
-	switch (ch) {
-	case 'd':
-	    flag_debug = 1;
-	    break;
-
-	case 'f':
-	    cfgpath = xstrdup(optarg);
-	    break;
-
-	case 'u':
-	    flag_unsecure = 1;
-	    break;
-
-	case 'v':
-	    info("symon version %s", SYMON_VERSION);
-	default:
-	    info("usage: %s [-d] [-u] [-v] [-f cfgfile]", __progname);
-	    exit(EX_USAGE);
-	}
+        switch (ch) {
+        case 'd':
+            flag_debug = 1;
+            break;
+
+        case 'f':
+            cfgpath = xstrdup(optarg);
+            break;
+
+        case 'u':
+            flag_unsecure = 1;
+            break;
+
+        case 'v':
+            info("symon version %s", SYMON_VERSION);
+        default:
+            info("usage: %s [-d] [-u] [-v] [-f cfgfile]", __progname);
+            exit(EX_USAGE);
+        }
     }
 
     if (!read_config_file(&mul, cfgpath))
-	fatal("configuration file contained errors - aborting");
+        fatal("configuration file contained errors - aborting");
 
     set_stream_use(&mul);
 
     /* open resources that might not be available after privilege drop */
     for (i = 0; i < MT_EOT; i++)
-	if (streamfunc[i].used && (streamfunc[i].privinit != NULL))
-	    (streamfunc[i].privinit) ();
+        if (streamfunc[i].used && (streamfunc[i].privinit != NULL))
+            (streamfunc[i].privinit) ();
 
     if ((pidfile = fopen(SYMON_PID_FILE, "w")) == NULL)
-	warning("could not open \"%.200s\", %.200s", SYMON_PID_FILE,
-		strerror(errno));
+        warning("could not open \"%.200s\", %.200s", SYMON_PID_FILE,
+                strerror(errno));
 
     drop_privileges(flag_unsecure);
 
     if (flag_debug != 1) {
-	if (daemon(0, 0) != 0)
-	    fatal("daemonize failed: %.200s", strerror(errno));
+        if (daemon(0, 0) != 0)
+            fatal("daemonize failed: %.200s", strerror(errno));
 
-	flag_daemon = 1;
+        flag_daemon = 1;
 
-	if (pidfile) {
-	    fprintf(pidfile, "%u\n", (u_int) getpid());
-	    fclose(pidfile);
-	}
+        if (pidfile) {
+            fprintf(pidfile, "%u\n", (u_int) getpid());
+            fclose(pidfile);
+        }
     }
 
     info("symon version %s", SYMON_VERSION);
 
     if (flag_debug == 1)
-	info("program id=%d", (u_int) getpid());
+        info("program id=%d", (u_int) getpid());
 
     /* setup signal handlers */
     signal(SIGALRM, alarmhandler);
@@ -254,10 +254,10 @@ main(int argc, char *argv[])
 
     /* init modules */
     SLIST_FOREACH(mux, &mul, muxes) {
-	connect2mux(mux);
-	SLIST_FOREACH(stream, &mux->sl, streams) {
-	    (streamfunc[stream->type].init) (stream);
-	}
+        connect2mux(mux);
+        SLIST_FOREACH(stream, &mux->sl, streams) {
+            (streamfunc[stream->type].init) (stream);
+        }
     }
     set_stream_use(&mul);
 
@@ -265,45 +265,45 @@ main(int argc, char *argv[])
     timerclear(&alarminterval.it_interval);
     timerclear(&alarminterval.it_value);
     alarminterval.it_interval.tv_sec =
-	alarminterval.it_value.tv_sec = symon_interval;
+        alarminterval.it_value.tv_sec = symon_interval;
 
     if (setitimer(ITIMER_REAL, &alarminterval, NULL) != 0) {
-	fatal("alarm setup failed: %.200s", strerror(errno));
+        fatal("alarm setup failed: %.200s", strerror(errno));
     }
 
     last_update = time(NULL);
-    for (;;) {			/* FOREVER */
-	sleep(symon_interval * 2);	/* alarm will interrupt sleep */
-	now = time(NULL);
-
-	if (flag_hup == 1) {
-	    flag_hup = 0;
-
-	    SLIST_INIT(&newmul);
-
-	    if (flag_unsecure) {
-		if (!read_config_file(&newmul, cfgpath)) {
-		    info("new configuration contains errors; keeping old configuration");
-		    free_muxlist(&newmul);
-		} else {
-		    free_muxlist(&mul);
-		    mul = newmul;
-		    info("read configuration file '%.200s' successfully", cfgpath);
-
-		    /* init modules */
-		    SLIST_FOREACH(mux, &mul, muxes) {
-			connect2mux(mux);
-			SLIST_FOREACH(stream, &mux->sl, streams) {
-			    (streamfunc[stream->type].init) (stream);
-			}
-		    }
-		    set_stream_use(&mul);
-		}
-	    } else {
-		info("configuration unreachable because of privsep; keeping old configuration");
-	    }
-	} else {
-	    /* check timing to catch ntp drifts */
+    for (;;) {                  /* FOREVER */
+        sleep(symon_interval * 2);      /* alarm will interrupt sleep */
+        now = time(NULL);
+
+        if (flag_hup == 1) {
+            flag_hup = 0;
+
+            SLIST_INIT(&newmul);
+
+            if (flag_unsecure) {
+                if (!read_config_file(&newmul, cfgpath)) {
+                    info("new configuration contains errors; keeping old configuration");
+                    free_muxlist(&newmul);
+                } else {
+                    free_muxlist(&mul);
+                    mul = newmul;
+                    info("read configuration file '%.200s' successfully", cfgpath);
+
+                    /* init modules */
+                    SLIST_FOREACH(mux, &mul, muxes) {
+                        connect2mux(mux);
+                        SLIST_FOREACH(stream, &mux->sl, streams) {
+                            (streamfunc[stream->type].init) (stream);
+                        }
+                    }
+                    set_stream_use(&mul);
+                }
+            } else {
+                info("configuration unreachable because of privsep; keeping old configuration");
+            }
+        } else {
+            /* check timing to catch ntp drifts */
             if (now < last_update ||
                 now > last_update + symon_interval + symon_interval) {
                 info("last update seems long ago - assuming system time change");
@@ -314,22 +314,22 @@ main(int argc, char *argv[])
             }
             last_update = now;
 
-	    /* populate for modules that get all their measurements in one go */
-	    for (i = 0; i < MT_EOT; i++)
-		if (streamfunc[i].used && (streamfunc[i].gets != NULL))
-		    (streamfunc[i].gets) ();
+            /* populate for modules that get all their measurements in one go */
+            for (i = 0; i < MT_EOT; i++)
+                if (streamfunc[i].used && (streamfunc[i].gets != NULL))
+                    (streamfunc[i].gets) ();
 
-	    SLIST_FOREACH(mux, &mul, muxes) {
-		prepare_packet(mux);
+            SLIST_FOREACH(mux, &mul, muxes) {
+                prepare_packet(mux);
 
-		SLIST_FOREACH(stream, &mux->sl, streams)
-		    stream_in_packet(stream, mux);
+                SLIST_FOREACH(stream, &mux->sl, streams)
+                    stream_in_packet(stream, mux);
 
-		finish_packet(mux);
+                finish_packet(mux);
 
-		send_packet(mux);
-	    }
-	}
+                send_packet(mux);
+            }
+        }
     }
 
     return (EX_SOFTWARE);     /* NOTREACHED */

+ 3 - 3
symon/symon/symon.h

@@ -1,4 +1,4 @@
-/* $Id: symon.h,v 1.35 2005/10/16 15:27:01 dijkstra Exp $ */
+/* $Id: symon.h,v 1.36 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -37,7 +37,7 @@
 #include "data.h"
 
 #define SYMON_PID_FILE "/var/run/symon.pid"
-#define SYMON_DEFAULT_INTERVAL 5	/* measurement interval */
+#define SYMON_DEFAULT_INTERVAL 5        /* measurement interval */
 
 /* funcmap holds functions to be called for the individual monitors:
  *
@@ -118,4 +118,4 @@ extern void gets_df();
 extern int get_df(char *, int, struct stream *);
 __END_DECLS
 
-#endif				/* _SYMON_SYMON_H */
+#endif                          /* _SYMON_SYMON_H */

+ 16 - 16
symon/symon/symonnet.c

@@ -1,4 +1,4 @@
-/* $Id: symonnet.c,v 1.15 2005/10/16 15:27:01 dijkstra Exp $ */
+/* $Id: symonnet.c,v 1.16 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -58,13 +58,13 @@ connect2mux(struct mux * mux)
     get_mux_sockaddr(mux, SOCK_DGRAM);
     family = mux->sockaddr.ss_family;
 
-    get_inaddrany_sockaddr(&sockaddr, family, SOCK_DGRAM, "0");
+    get_sockaddr(&sockaddr, family, SOCK_DGRAM, AI_PASSIVE, mux->localaddr, "0");
 
     if ((mux->symuxsocket = socket(family, SOCK_DGRAM, 0)) == -1)
-	fatal("could not obtain socket: %.200s", strerror(errno));
+        fatal("could not obtain socket: %.200s", strerror(errno));
 
     if (bind(mux->symuxsocket, (struct sockaddr *) & sockaddr, SS_LEN(&sockaddr)) == -1)
-	fatal("could not bind socket: %.200s", strerror(errno));
+        fatal("could not bind socket: %.200s", strerror(errno));
 
     info("sending packets to udp %.200s", mux->name);
 }
@@ -73,16 +73,16 @@ void
 send_packet(struct mux * mux)
 {
     if (sendto(mux->symuxsocket, (void *) &mux->packet.data,
-	       mux->offset, 0, (struct sockaddr *) & mux->sockaddr,
-	       SS_LEN(&mux->sockaddr))
-	!= mux->offset) {
-	mux->senderr++;
+               mux->offset, 0, (struct sockaddr *) & mux->sockaddr,
+               SS_LEN(&mux->sockaddr))
+        != mux->offset) {
+        mux->senderr++;
     }
 
     if (mux->senderr >= SYMON_WARN_SENDERR) {
-	warning("%d updates to mux(%.200s) lost due to send errors",
-		mux->senderr, mux->name);
-	mux->senderr = 0;
+        warning("%d updates to mux(%.200s) lost due to send errors",
+                mux->senderr, mux->name);
+        mux->senderr = 0;
     }
 }
 /* Prepare a packet for data */
@@ -97,17 +97,17 @@ prepare_packet(struct mux * mux)
 
     /* symonpacketheader is always first stream */
     mux->offset =
-	setheader((char *) &mux->packet.data,
-		  &mux->packet.header);
+        setheader((char *) &mux->packet.data,
+                  &mux->packet.header);
 }
 /* Put a stream into the packet for a mux */
 void
 stream_in_packet(struct stream * stream, struct mux * mux)
 {
     mux->offset +=
-    (streamfunc[stream->type].get)	/* call getter of stream */
-    (&mux->packet.data[mux->offset],	/* packet buffer */
-     sizeof(mux->packet.data) - mux->offset,	/* maxlen */
+    (streamfunc[stream->type].get)      /* call getter of stream */
+    (&mux->packet.data[mux->offset],    /* packet buffer */
+     sizeof(mux->packet.data) - mux->offset,    /* maxlen */
      stream);
 }
 /* Ready a packet for transmission, set length and crc */

+ 2 - 2
symon/symon/symonnet.h

@@ -1,4 +1,4 @@
-/* $Id: symonnet.h,v 1.7 2004/02/26 22:48:08 dijkstra Exp $ */
+/* $Id: symonnet.h,v 1.8 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -43,4 +43,4 @@ void prepare_packet(struct mux *);
 void stream_in_packet(struct stream *, struct mux *);
 void finish_packet(struct mux *);
 __END_DECLS
-#endif				/* _SYMON_SYMONNET_H */
+#endif                          /* _SYMON_SYMONNET_H */

+ 284 - 284
symon/symux/readconf.c

@@ -1,4 +1,4 @@
-/* $Id: readconf.c,v 1.29 2006/12/19 22:30:48 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.31 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -62,63 +62,63 @@ insert_filename(char *path, int maxlen, int type, char *args)
 
     switch (type) {
     case MT_CPU:
-	ts = "cpu";
-	ta = args;
-	break;
+        ts = "cpu";
+        ta = args;
+        break;
     case MT_DF:
-	ts = "df_";
-	ta = args;
-	break;
+        ts = "df_";
+        ta = args;
+        break;
     case MT_IF:
-	ts = "if_";
-	ta = args;
-	break;
+        ts = "if_";
+        ta = args;
+        break;
     case MT_IO2:
-	ts = "io_";
-	ta = args;
-	break;
+        ts = "io_";
+        ta = args;
+        break;
     case MT_IO1:
-	ts = "io1_";
-	ta = args;
-	break;
+        ts = "io1_";
+        ta = args;
+        break;
     case MT_MEM:
-	ts = "mem";
-	ta = "";
-	break;
+        ts = "mem";
+        ta = "";
+        break;
     case MT_PF:
-	ts = "pf";
-	ta = "";
-	break;
+        ts = "pf";
+        ta = "";
+        break;
     case MT_PFQ:
-	ts  = "pfq_";
-	ta = args;
-	break;
+        ts  = "pfq_";
+        ta = args;
+        break;
     case MT_MBUF:
-	ts = "mbuf";
-	ta = "";
-	break;
+        ts = "mbuf";
+        ta = "";
+        break;
     case MT_DEBUG:
-	ts = "debug";
-	ta = "";
-	break;
+        ts = "debug";
+        ta = "";
+        break;
     case MT_PROC:
-	ts = "proc_";
-	ta = args;
-	break;
+        ts = "proc_";
+        ta = args;
+        break;
     case MT_SENSOR:
-	ts = "sensor";
-	ta = args;
-	break;
+        ts = "sensor";
+        ta = args;
+        break;
     default:
-	warning("%.200s:%d: internal error: type (%d) unknown",
-		__FILE__, __LINE__, type);
-	return 0;
+        warning("%.200s:%d: internal error: type (%d) unknown",
+                __FILE__, __LINE__, type);
+        return 0;
     }
 
     if ((snprintf(path, maxlen, "/%s%s.rrd", ts, ta)) >= maxlen) {
-	return 0;
+        return 0;
     } else {
-	return 1;
+        return 1;
     }
 }
 /* mux <host> (port|,| ) <number> */
@@ -129,16 +129,16 @@ read_mux(struct muxlist * mul, struct lex * l)
     struct mux *mux;
 
     if (!SLIST_EMPTY(mul)) {
-	warning("%.200s:%d: only one mux statement allowed",
-		l->filename, l->cline);
-	return 0;
+        warning("%.200s:%d: only one mux statement allowed",
+                l->filename, l->cline);
+        return 0;
     }
 
     lex_nexttoken(l);
     if (!getip(l->token, AF_INET) && !getip(l->token, AF_INET6)) {
-	warning("%.200s:%d: could not resolve '%s'",
-		l->filename, l->cline, l->token);
-	return 0;
+        warning("%.200s:%d: could not resolve '%s'",
+                l->filename, l->cline, l->token);
+        return 0;
     }
 
     mux = add_mux(mul, SYMON_UNKMUX);
@@ -148,20 +148,20 @@ read_mux(struct muxlist * mul, struct lex * l)
     lex_nexttoken(l);
 
     if (l->op == LXT_PORT || l->op == LXT_COMMA)
-	lex_nexttoken(l);
+        lex_nexttoken(l);
 
     if (l->type != LXY_NUMBER) {
-	lex_ungettoken(l);
-	mux->port = xstrdup(default_symux_port);
+        lex_ungettoken(l);
+        mux->port = xstrdup(default_symux_port);
     } else {
-	mux->port = xstrdup((const char *) l->token);
+        mux->port = xstrdup((const char *) l->token);
     }
 
     bzero(&muxname, sizeof(muxname));
     snprintf(&muxname[0], sizeof(muxname), "%s %s", mux->addr, mux->port);
 
     if (rename_mux(mul, mux, muxname) == NULL)
-	fatal("%s:%d: internal error: dual mux", __FILE__, __LINE__);
+        fatal("%s:%d: internal error: dual mux", __FILE__, __LINE__);
 
     return 1;
 }
@@ -182,90 +182,90 @@ read_source(struct sourcelist * sol, struct lex * l, int filecheck)
     /* get hostname */
     lex_nexttoken(l);
     if (!getip(l->token, AF_INET) && !getip(l->token, AF_INET6)) {
-	warning("%.200s:%d: could not resolve '%s'",
-		l->filename, l->cline, l->token);
-	return 0;
+        warning("%.200s:%d: could not resolve '%s'",
+                l->filename, l->cline, l->token);
+        return 0;
     }
 
     source = add_source(sol, res_host);
 
     EXPECT(l, LXT_BEGIN);
     while (lex_nexttoken(l)) {
-	switch (l->op) {
-	    /* accept { cpu(x), ... } */
-	case LXT_ACCEPT:
-	    EXPECT(l, LXT_BEGIN);
-	    while (lex_nexttoken(l) && l->op != LXT_END) {
-		switch (l->op) {
-		case LXT_CPU:
-		case LXT_DF:
-		case LXT_IF:
-		case LXT_IO:
-		case LXT_IO1:
-		case LXT_MEM:
-		case LXT_PF:
-		case LXT_PFQ:
-		case LXT_MBUF:
-		case LXT_DEBUG:
-		case LXT_PROC:
-		case LXT_SENSOR:
-		    st = token2type(l->op);
-		    strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
-
-		    /* parse arg */
-		    lex_nexttoken(l);
-		    if (l->op == LXT_OPEN) {
-			lex_nexttoken(l);
-			if (l->op == LXT_CLOSE) {
-			    parse_error(l, "<stream argument>");
-			    return 0;
-			}
-
-			strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
-			lex_nexttoken(l);
-
-			if (l->op != LXT_CLOSE) {
-			    parse_error(l, ")");
-			    return 0;
-			}
-		    } else {
-			lex_ungettoken(l);
-			sa[0] = '\0';
-		    }
-
-		    if (strlen(sa) > (SYMON_PS_ARGLEN - 1)) {
-			warning("%.200s:%d: argument '%.200s' too long for network format, "
-				"will accept initial " SYMON_PS_ARGLENSTR " chars only",
-				l->filename, l->cline, sa);
-			sa[SYMON_PS_ARGLEN-1]='\0';
-		    }
-
-		    if ((stream = add_source_stream(source, st, sa)) == NULL) {
-			warning("%.200s:%d: stream %.200s(%.200s) redefined",
-				l->filename, l->cline, sn, sa);
-			return 0;
-		    }
-
-		    break;	/* LXT_CPU/IF/IO/IO1/MEM/PF/MBUF/DEBUG/PROC */
-		case LXT_COMMA:
-		    break;
-		default:
-		    parse_error(l, "{cpu|mem|if|io|pf|debug|mbuf|proc|sensor}");
-		    return 0;
-
-		    break;
-		}
-	    }
-	    break;		/* LXT_ACCEPT */
-	    /* datadir "path" */
-	case LXT_DATADIR:
-	    lex_nexttoken(l);
-	    /* is path absolute */
-	    if (l->token && l->token[0] != '/') {
-		warning("%.200s:%d: datadir path '%.200s' is not absolute",
-			l->filename, l->cline, l->token);
-		return 0;
-	    }
+        switch (l->op) {
+            /* accept { cpu(x), ... } */
+        case LXT_ACCEPT:
+            EXPECT(l, LXT_BEGIN);
+            while (lex_nexttoken(l) && l->op != LXT_END) {
+                switch (l->op) {
+                case LXT_CPU:
+                case LXT_DF:
+                case LXT_IF:
+                case LXT_IO:
+                case LXT_IO1:
+                case LXT_MEM:
+                case LXT_PF:
+                case LXT_PFQ:
+                case LXT_MBUF:
+                case LXT_DEBUG:
+                case LXT_PROC:
+                case LXT_SENSOR:
+                    st = token2type(l->op);
+                    strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
+
+                    /* parse arg */
+                    lex_nexttoken(l);
+                    if (l->op == LXT_OPEN) {
+                        lex_nexttoken(l);
+                        if (l->op == LXT_CLOSE) {
+                            parse_error(l, "<stream argument>");
+                            return 0;
+                        }
+
+                        strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
+                        lex_nexttoken(l);
+
+                        if (l->op != LXT_CLOSE) {
+                            parse_error(l, ")");
+                            return 0;
+                        }
+                    } else {
+                        lex_ungettoken(l);
+                        sa[0] = '\0';
+                    }
+
+                    if (strlen(sa) > (SYMON_PS_ARGLENV2 - 1)) {
+                        warning("%.200s:%d: argument '%.200s' too long for network format, "
+                                "will accept initial " SYMON_PS_ARGLENSTRV2 " chars only",
+                                l->filename, l->cline, sa);
+                        sa[SYMON_PS_ARGLENV2 - 1] = '\0';
+                    }
+
+                    if ((stream = add_source_stream(source, st, sa)) == NULL) {
+                        warning("%.200s:%d: stream %.200s(%.200s) redefined",
+                                l->filename, l->cline, sn, sa);
+                        return 0;
+                    }
+
+                    break;      /* LXT_CPU/IF/IO/IO1/MEM/PF/MBUF/DEBUG/PROC */
+                case LXT_COMMA:
+                    break;
+                default:
+                    parse_error(l, "{cpu|mem|if|io|pf|debug|mbuf|proc|sensor}");
+                    return 0;
+
+                    break;
+                }
+            }
+            break;              /* LXT_ACCEPT */
+            /* datadir "path" */
+        case LXT_DATADIR:
+            lex_nexttoken(l);
+            /* is path absolute */
+            if (l->token && l->token[0] != '/') {
+                warning("%.200s:%d: datadir path '%.200s' is not absolute",
+                        l->filename, l->cline, l->token);
+                return 0;
+            }
 
             if (filecheck) {
                 /* make sure that directory exists */
@@ -284,38 +284,38 @@ read_source(struct sourcelist * sol, struct lex * l, int filecheck)
                 }
             }
 
-	    strncpy(&path[0], l->token, _POSIX2_LINE_MAX);
-	    path[_POSIX2_LINE_MAX - 1] = '\0';
-
-	    pc = strlen(path);
-
-	    if (path[pc - 1] == '/') {
-		path[pc - 1] = '\0';
-		pc--;
-	    }
-
-	    /* add path to empty streams */
-	    SLIST_FOREACH(stream, &source->sl, streams) {
-		if (stream->file == NULL) {
-		    if (!(insert_filename(&path[pc],
-					  _POSIX2_LINE_MAX - pc,
-					  stream->type,
-					  stream->arg))) {
-			if (stream->arg && strlen(stream->arg)) {
-			    warning("%.200s:%d: failed to construct stream "
-				    "%.200s(%.200s) filename using datadir '%.200s'",
-				    l->filename, l->cline,
-				    type2str(stream->type),
-				    stream->arg, l->token);
-			} else {
-			    warning("%.200s:%d: failed to construct stream "
-				    "%.200s) filename using datadir '%.200s'",
-				    l->filename, l->cline,
-				    type2str(stream->type),
-				    l->token);
-			}
-			return 0;
-		    }
+            strncpy(&path[0], l->token, _POSIX2_LINE_MAX);
+            path[_POSIX2_LINE_MAX - 1] = '\0';
+
+            pc = strlen(path);
+
+            if (path[pc - 1] == '/') {
+                path[pc - 1] = '\0';
+                pc--;
+            }
+
+            /* add path to empty streams */
+            SLIST_FOREACH(stream, &source->sl, streams) {
+                if (stream->file == NULL) {
+                    if (!(insert_filename(&path[pc],
+                                          _POSIX2_LINE_MAX - pc,
+                                          stream->type,
+                                          stream->arg))) {
+                        if (stream->arg && strlen(stream->arg)) {
+                            warning("%.200s:%d: failed to construct stream "
+                                    "%.200s(%.200s) filename using datadir '%.200s'",
+                                    l->filename, l->cline,
+                                    type2str(stream->type),
+                                    stream->arg, l->token);
+                        } else {
+                            warning("%.200s:%d: failed to construct stream "
+                                    "%.200s) filename using datadir '%.200s'",
+                                    l->filename, l->cline,
+                                    type2str(stream->type),
+                                    l->token);
+                        }
+                        return 0;
+                    }
 
                     if (filecheck) {
                         /* try filename */
@@ -330,63 +330,63 @@ read_source(struct sourcelist * sol, struct lex * l, int filecheck)
                     } else {
                         stream->file = xstrdup(path);
                     }
-		}
-	    }
-	    break;		/* LXT_DATADIR */
-	    /* write cpu(0) in "filename" */
-	case LXT_WRITE:
-	    lex_nexttoken(l);
-	    switch (l->op) {
-	    case LXT_CPU:
-	    case LXT_DF:
-	    case LXT_IF:
-	    case LXT_IO:
-	    case LXT_IO1:
-	    case LXT_MEM:
-	    case LXT_PF:
-	    case LXT_PFQ:
-	    case LXT_MBUF:
-	    case LXT_DEBUG:
-	    case LXT_PROC:
-	    case LXT_SENSOR:
-		st = token2type(l->op);
-		strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
-
-		/* parse arg */
-		lex_nexttoken(l);
-		if (l->op == LXT_OPEN) {
-		    lex_nexttoken(l);
-		    if (l->op == LXT_CLOSE) {
-			parse_error(l, "<stream argument>");
-			return 0;
-		    }
-
-		    strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
-		    lex_nexttoken(l);
-		    if (l->op != LXT_CLOSE) {
-			parse_error(l, ")");
-			return 0;
-		    }
-		} else {
-		    lex_ungettoken(l);
-		    sa[0] = '\0';
-		}
-
-		EXPECT(l, LXT_IN);
-
-		lex_nexttoken(l);
-
-		if ((stream = find_source_stream(source, st, sa)) == NULL) {
-		    if (strlen(sa)) {
-			warning("%.200s:%d: stream %.200s(%.200s) is not accepted for %.200s",
-				l->filename, l->cline, sn, sa, source->addr);
-			return 0;
-		    } else {
-			warning("%.200s:%d: stream %.200s is not accepted for %.200s",
-				l->filename, l->cline, sn, source->addr);
-			return 0;
-		    }
-		} else {
+                }
+            }
+            break;              /* LXT_DATADIR */
+            /* write cpu(0) in "filename" */
+        case LXT_WRITE:
+            lex_nexttoken(l);
+            switch (l->op) {
+            case LXT_CPU:
+            case LXT_DF:
+            case LXT_IF:
+            case LXT_IO:
+            case LXT_IO1:
+            case LXT_MEM:
+            case LXT_PF:
+            case LXT_PFQ:
+            case LXT_MBUF:
+            case LXT_DEBUG:
+            case LXT_PROC:
+            case LXT_SENSOR:
+                st = token2type(l->op);
+                strncpy(&sn[0], l->token, _POSIX2_LINE_MAX);
+
+                /* parse arg */
+                lex_nexttoken(l);
+                if (l->op == LXT_OPEN) {
+                    lex_nexttoken(l);
+                    if (l->op == LXT_CLOSE) {
+                        parse_error(l, "<stream argument>");
+                        return 0;
+                    }
+
+                    strncpy(&sa[0], l->token, _POSIX2_LINE_MAX);
+                    lex_nexttoken(l);
+                    if (l->op != LXT_CLOSE) {
+                        parse_error(l, ")");
+                        return 0;
+                    }
+                } else {
+                    lex_ungettoken(l);
+                    sa[0] = '\0';
+                }
+
+                EXPECT(l, LXT_IN);
+
+                lex_nexttoken(l);
+
+                if ((stream = find_source_stream(source, st, sa)) == NULL) {
+                    if (strlen(sa)) {
+                        warning("%.200s:%d: stream %.200s(%.200s) is not accepted for %.200s",
+                                l->filename, l->cline, sn, sa, source->addr);
+                        return 0;
+                    } else {
+                        warning("%.200s:%d: stream %.200s is not accepted for %.200s",
+                                l->filename, l->cline, sn, source->addr);
+                        return 0;
+                    }
+                } else {
                     if (filecheck) {
                         /* try filename */
                         if ((fd = open(l->token, O_RDWR | O_NONBLOCK, 0)) == -1) {
@@ -407,24 +407,24 @@ read_source(struct sourcelist * sol, struct lex * l, int filecheck)
                     } else {
                         stream->file = xstrdup(l->token);
                     }
-		}
-		break;		/* LXT_CPU/IF/IO/IO1/MEM/PF/PFQ/MBUF/DEBUG/PROC/SENSOR */
-	    default:
-		parse_error(l, "{cpu|if|io|mem|pf|mbuf|debug|proc|sensor}");
-		return 0;
-		break;
-	    }
-	    break;		/* LXT_WRITE */
-	case LXT_END:
-	    return 1;
-	default:
-	    parse_error(l, "accept|datadir|write");
-	    return 0;
-	}
+                }
+                break;          /* LXT_CPU/IF/IO/IO1/MEM/PF/PFQ/MBUF/DEBUG/PROC/SENSOR */
+            default:
+                parse_error(l, "{cpu|if|io|mem|pf|mbuf|debug|proc|sensor}");
+                return 0;
+                break;
+            }
+            break;              /* LXT_WRITE */
+        case LXT_END:
+            return 1;
+        default:
+            parse_error(l, "accept|datadir|write");
+            return 0;
+        }
     }
 
     warning("%.200s:%d: missing close brace on source statement",
-	    l->filename, l->cline);
+            l->filename, l->cline);
 
     return 0;
 }
@@ -441,66 +441,66 @@ read_config_file(struct muxlist * mul, const char *filename, int filechecks)
     SLIST_INIT(&sol);
 
     if ((l = open_lex(filename)) == NULL)
-	return 0;
+        return 0;
 
     while (lex_nexttoken(l)) {
-	/* expecting keyword now */
-	switch (l->op) {
-	case LXT_MUX:
-	    if (!read_mux(mul, l)) {
-		free_sourcelist(&sol);
-		return 0;
-	    }
-	    break;
-	case LXT_SOURCE:
-	    if (!read_source(&sol, l, filechecks)) {
-		free_sourcelist(&sol);
-		return 0;
-	    }
-	    break;
-	default:
-	    parse_error(l, "mux|source");
-	    free_sourcelist(&sol);
-	    return 0;
-	    break;
-	}
+        /* expecting keyword now */
+        switch (l->op) {
+        case LXT_MUX:
+            if (!read_mux(mul, l)) {
+                free_sourcelist(&sol);
+                return 0;
+            }
+            break;
+        case LXT_SOURCE:
+            if (!read_source(&sol, l, filechecks)) {
+                free_sourcelist(&sol);
+                return 0;
+            }
+            break;
+        default:
+            parse_error(l, "mux|source");
+            free_sourcelist(&sol);
+            return 0;
+            break;
+        }
     }
 
     /* sanity checks */
     if (SLIST_EMPTY(mul)) {
-	free_sourcelist(&sol);
-	warning("%.200s: no mux statement seen",
-		l->filename);
-	return 0;
+        free_sourcelist(&sol);
+        warning("%.200s: no mux statement seen",
+                l->filename);
+        return 0;
     } else {
-	mux = SLIST_FIRST(mul);
-	mux->sol = sol;
-	if (strncmp(SYMON_UNKMUX, mux->name, sizeof(SYMON_UNKMUX)) == 0) {
-	    /* mux was not initialised for some reason */
-	    return 0;
-	}
+        mux = SLIST_FIRST(mul);
+        mux->sol = sol;
+        if (strncmp(SYMON_UNKMUX, mux->name, sizeof(SYMON_UNKMUX)) == 0) {
+            /* mux was not initialised for some reason */
+            return 0;
+        }
     }
 
     if (SLIST_EMPTY(&sol)) {
-	warning("%.200s: no source section seen",
-		l->filename);
-	return 0;
+        warning("%.200s: no source section seen",
+                l->filename);
+        return 0;
     } else {
-	SLIST_FOREACH(source, &sol, sources) {
-	    if (SLIST_EMPTY(&source->sl)) {
-		warning("%.200s: no streams accepted for source '%.200s'",
-			l->filename, source->addr);
-		return 0;
-	    } else {
-		SLIST_FOREACH(stream, &source->sl, streams) {
-		    if (stream->file == NULL) {
-			/* warn, but allow */
-			warning("%.200s: no filename specified for stream '%.200s(%.200s)' in source '%.200s'",
-				l->filename, type2str(stream->type), stream->arg, source->addr);
-		    }
-		}
-	    }
-	}
+        SLIST_FOREACH(source, &sol, sources) {
+            if (SLIST_EMPTY(&source->sl)) {
+                warning("%.200s: no streams accepted for source '%.200s'",
+                        l->filename, source->addr);
+                return 0;
+            } else {
+                SLIST_FOREACH(stream, &source->sl, streams) {
+                    if (stream->file == NULL) {
+                        /* warn, but allow */
+                        warning("%.200s: no filename specified for stream '%.200s(%.200s)' in source '%.200s'",
+                                l->filename, type2str(stream->type), stream->arg, source->addr);
+                    }
+                }
+            }
+        }
     }
 
     close_lex(l);

+ 2 - 2
symon/symux/readconf.h

@@ -1,4 +1,4 @@
-/* $Id: readconf.h,v 1.9 2006/12/19 22:30:48 dijkstra Exp $ */
+/* $Id: readconf.h,v 1.10 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -40,4 +40,4 @@ __BEGIN_DECLS
 int read_config_file(struct muxlist *, const char *, int);
 __END_DECLS
 
-#endif				/* _SYMUX_READCONF_H */
+#endif                          /* _SYMUX_READCONF_H */

+ 100 - 100
symon/symux/share.c

@@ -1,4 +1,4 @@
-/* $Id: share.c,v 1.20 2005/09/30 14:04:43 dijkstra Exp $ */
+/* $Id: share.c,v 1.21 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2005 Willem Dijkstra
@@ -89,10 +89,10 @@ void master_resetsem(int);
 void reap_clients();
 __END_DECLS
 
-int realclients;		/* number of clients active */
+int realclients;                /* number of clients active */
 int newclients;
-int master;			/* is current process master or child */
-int clientsock;			/* connected client */
+int master;                     /* is current process master or child */
+int clientsock;                 /* connected client */
 pid_t clientpid;
 
 enum ipcstat {
@@ -124,9 +124,9 @@ void
 shared_setlen(int slot, long length)
 {
     if (length > shm->slotlen)
-	fatal("%s:%d: internal error:"
-	      "set_length of shared region called with value larger than actual size",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: internal error:"
+              "set_length of shared region called with value larger than actual size",
+              __FILE__, __LINE__);
 
     shm->ctlen[slot % SYMUX_SHARESLOTS] = length;
 }
@@ -141,8 +141,8 @@ void
 check_sem()
 {
     if (semstat != SIPC_KEYED)
-	fatal("%s:%d: internal error: semaphore not available",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: internal error: semaphore not available",
+              __FILE__, __LINE__);
 }
 
 /* Check whether process is the master process */
@@ -150,8 +150,8 @@ void
 check_master()
 {
     if (master == 0)
-	fatal("%s:%d: internal error: child process tried to access master routines",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: internal error: child process tried to access master routines",
+              __FILE__, __LINE__);
 }
 
 /* Reset semaphores before each distribution cycle */
@@ -166,8 +166,8 @@ master_resetsem(int semnum)
     check_master();
 
     if ((semctl(semid, semnum, SETVAL, semarg) != 0))
-	fatal("%s:%d: internal error: cannot reset semaphore %d",
-	      __FILE__, __LINE__, semnum);
+        fatal("%s:%d: internal error: cannot reset semaphore %d",
+              __FILE__, __LINE__, semnum);
 }
 /* Prepare for writing to shm */
 int
@@ -183,11 +183,11 @@ master_forbidread()
     /* prepare for a new read */
     semarg.val = 0;
     if ((stalledclients = semctl(semid, slot, GETVAL, semarg)) < 0) {
-	fatal("%s:%d: internal error: cannot read semaphore",
-	      __FILE__, __LINE__);
+        fatal("%s:%d: internal error: cannot read semaphore",
+              __FILE__, __LINE__);
     } else {
-	reap_clients();
-	debug("realclients = %d; stalledclients = %d", realclients, stalledclients);
+        reap_clients();
+        debug("realclients = %d; stalledclients = %d", realclients, stalledclients);
     }
 
     /* add new clients */
@@ -207,8 +207,8 @@ master_permitread()
     semarg.val = realclients;
 
     if (semctl(semid, slot, SETVAL, semarg) != 0)
-	fatal("%s:%d: internal error: cannot set semaphore %d",
-	      __FILE__, __LINE__, slot);
+        fatal("%s:%d: internal error: cannot set semaphore %d",
+              __FILE__, __LINE__, slot);
 }
 /* Make clients wait until master signals */
 int
@@ -218,9 +218,9 @@ client_waitread()
     struct sembuf sops;
 
     if (seqnr < (shm->seqnr - SYMUX_SHARESLOTS - 1)) {
-	close(clientsock);
-	fatal("%s:%d: client(%d) lagging behind (%d, %d) = high load?",
-	      __FILE__, __LINE__, clientpid, seqnr, shm->seqnr);
+        close(clientsock);
+        fatal("%s:%d: client(%d) lagging behind (%d, %d) = high load?",
+              __FILE__, __LINE__, clientpid, seqnr, shm->seqnr);
     }
 
     check_sem();
@@ -230,8 +230,8 @@ client_waitread()
     sops.sem_flg = 0;
 
     if (semop(semid, &sops, 1) != 0)
-	fatal("%s:%d: internal error: client(%d): cannot obtain semaphore (%.200s)",
-	      __FILE__, __LINE__, clientpid, strerror(errno));
+        fatal("%s:%d: internal error: client(%d): cannot obtain semaphore (%.200s)",
+              __FILE__, __LINE__, clientpid, strerror(errno));
 
     return slot;
 }
@@ -269,12 +269,12 @@ initshare(int bufsize)
     atexit(exitmaster);
 
     if ((shmid = shmget(IPC_PRIVATE, totalsize, SHM_R | SHM_W)) < 0)
-	fatal("could not get a shared memory identifier");
+        fatal("could not get a shared memory identifier");
 
     shmstat = SIPC_KEYED;
 
     if ((shm = (struct sharedregion *) shmat(shmid, 0, 0)) == (void *) (-1))
-	fatal("could not attach shared memory");
+        fatal("could not attach shared memory");
 
     shmstat = SIPC_ATTACHED;
     bzero(shm, totalsize);
@@ -283,12 +283,12 @@ initshare(int bufsize)
 
     /* allocate semaphores */
     if ((semid = semget(IPC_PRIVATE, SYMUX_SHARESLOTS, SEM_ARGS)) < 0)
-	fatal("could not get a semaphore");
+        fatal("could not get a semaphore");
 
     semstat = SIPC_KEYED;
 
     for (i = 0; i < SYMUX_SHARESLOTS; i++)
-	master_resetsem(i);
+        master_resetsem(i);
 }
 /* Spawn off a new client */
 pid_t
@@ -305,36 +305,36 @@ spawn_client(int sock)
 #endif
 
     if ((pid = fork())) {
-	/* server */
-	if (pid == -1) {
-	    info("could not fork client process");
-	} else {
-	    newclients++;
-	    info("forked client(%d) for incoming connection from %.200s:%.200s",
-		 pid, res_host, res_service);
-	}
-
-	close(clientsock);
-
-	return pid;
+        /* server */
+        if (pid == -1) {
+            info("could not fork client process");
+        } else {
+            newclients++;
+            info("forked client(%d) for incoming connection from %.200s:%.200s",
+                 pid, res_host, res_service);
+        }
+
+        close(clientsock);
+
+        return pid;
     } else {
-	/* client */
-	master = 0;
-	seqnr = shm->seqnr;
-
-	/* catch signals */
-	signal(SIGHUP, client_signalhandler);
-	signal(SIGINT, client_signalhandler);
-	signal(SIGQUIT, client_signalhandler);
-	signal(SIGTERM, client_signalhandler);
-	signal(SIGTERM, client_signalhandler);
-	signal(SIGPIPE, client_signalhandler);
-
-	clientpid = getpid();
-	client_loop();
-
-	/* NOT REACHED */
-	return 0;
+        /* client */
+        master = 0;
+        seqnr = shm->seqnr;
+
+        /* catch signals */
+        signal(SIGHUP, client_signalhandler);
+        signal(SIGINT, client_signalhandler);
+        signal(SIGQUIT, client_signalhandler);
+        signal(SIGTERM, client_signalhandler);
+        signal(SIGTERM, client_signalhandler);
+        signal(SIGPIPE, client_signalhandler);
+
+        clientpid = getpid();
+        client_loop();
+
+        /* NOT REACHED */
+        return 0;
     }
 }
 /* Reap exit/stopped clients */
@@ -349,19 +349,19 @@ reap_clients()
     /* Reap all children that died */
     while (((int) (pid = wait4(-1, &status, WNOHANG, NULL)) > 0) && realclients >= 0) {
 
-	/*
-	 * wait4 is supposed to return 0 if there is no status to report, but
-	 * it also reports -1 on OpenBSD 2.9
-	 */
+        /*
+         * wait4 is supposed to return 0 if there is no status to report, but
+         * it also reports -1 on OpenBSD 2.9
+         */
 
-	if (WIFEXITED(status))
-	    info("client process %d exited", pid, status);
-	if (WIFSIGNALED(status))
-	    info("client process %d killed with signal %d", pid, WTERMSIG(status));
-	if (WIFSTOPPED(status))
-	    info("client process %d stopped with signal %d", pid, WSTOPSIG(status));
+        if (WIFEXITED(status))
+            info("client process %d exited", pid, status);
+        if (WIFSIGNALED(status))
+            info("client process %d killed with signal %d", pid, WTERMSIG(status));
+        if (WIFSTOPPED(status))
+            info("client process %d stopped with signal %d", pid, WSTOPSIG(status));
 
-	realclients--;
+        realclients--;
     }
 }
 /* Remove shared memory and semaphores at exit */
@@ -371,41 +371,41 @@ exitmaster()
     union semun semarg;
 
     if (master == 0)
-	return;
+        return;
 
     switch (shmstat) {
     case SIPC_ATTACHED:
-	if (shmdt(shm))
-	    warning("%s:%d: internal error: control region could not be detached",
-		    __FILE__, __LINE__);
+        if (shmdt(shm))
+            warning("%s:%d: internal error: control region could not be detached",
+                    __FILE__, __LINE__);
 
-	/* no break */
+        /* no break */
     case SIPC_KEYED:
-	if (shmctl(shmid, IPC_RMID, NULL))
-	    warning("%s:%d: internal error: could remove control region %d",
-		    __FILE__, __LINE__, shmid);
-	/* no break */
+        if (shmctl(shmid, IPC_RMID, NULL))
+            warning("%s:%d: internal error: could remove control region %d",
+                    __FILE__, __LINE__, shmid);
+        /* no break */
     case SIPC_FREE:
-	break;
+        break;
 
     default:
-	warning("%s:%d: internal error: control region is in an unknown state",
-		__FILE__, __LINE__);
+        warning("%s:%d: internal error: control region is in an unknown state",
+                __FILE__, __LINE__);
     }
 
     switch (semstat) {
     case SIPC_KEYED:
-	semarg.val = 0;
-	if (semctl(semid, 0, IPC_RMID, semarg) != 0)
-	    warning("%s:%d: internal error: could not remove semaphore %d",
-		    __FILE__, __LINE__, semid);
-	/* no break */
+        semarg.val = 0;
+        if (semctl(semid, 0, IPC_RMID, semarg) != 0)
+            warning("%s:%d: internal error: could not remove semaphore %d",
+                    __FILE__, __LINE__, semid);
+        /* no break */
     case SIPC_FREE:
-	break;
+        break;
 
     default:
-	warning("%s:%d: internal error: semaphore is in an unknown state",
-		__FILE__, __LINE__);
+        warning("%s:%d: internal error: semaphore is in an unknown state",
+                __FILE__, __LINE__);
     }
 }
 void
@@ -416,22 +416,22 @@ client_loop()
     int sent;
     int written;
 
-    for (;;) {			/* FOREVER */
+    for (;;) {                  /* FOREVER */
 
-	slot = client_waitread();
-	total = shared_getlen(slot);
-	sent = 0;
+        slot = client_waitread();
+        total = shared_getlen(slot);
+        sent = 0;
 
-	while (sent < total) {
+        while (sent < total) {
 
-	    if ((written = write(clientsock, (char *) (shared_getmem(slot) + sent), total - sent)) == -1) {
-		info("client(%d): write error. Client will quit.", clientpid);
-		exit(1);
-	    }
+            if ((written = write(clientsock, (char *) (shared_getmem(slot) + sent), total - sent)) == -1) {
+                info("client(%d): write error. Client will quit.", clientpid);
+                exit(1);
+            }
 
-	    sent += written;
+            sent += written;
 
-	    debug("client(%d): written %d bytes of %d total from slot %d", clientpid, sent, total, slot);
-	}
+            debug("client(%d): written %d bytes of %d total from slot %d", clientpid, sent, total, slot);
+        }
     }
 }

+ 3 - 3
symon/symux/share.h

@@ -1,4 +1,4 @@
-/* $Id: share.h,v 1.9 2005/06/26 12:35:40 dijkstra Exp $ */
+/* $Id: share.h,v 1.10 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -44,7 +44,7 @@ struct sharedregion {
     long seqnr;
     long slotlen;
     long ctlen[SYMUX_SHARESLOTS]; /* amount of content in buffer n, assert(<
-				   * size) */
+                                   * size) */
     char *data;
 };
 
@@ -60,4 +60,4 @@ void shared_setlen(int, long);
 pid_t spawn_client(int);
 __END_DECLS
 
-#endif				/* _SYMUX_SHARE_H */
+#endif                          /* _SYMUX_SHARE_H */

+ 24 - 24
symon/symux/symux.8

@@ -1,6 +1,6 @@
 .\"  -*- nroff -*-
 .\"
-.\" Copyright (c) 2001-2005 Willem Dijkstra
+.\" Copyright (c) 2001-2007 Willem Dijkstra
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -40,9 +40,9 @@
 .Pp
 .Sh DESCRIPTION
 .Xr symon 8
-is a lightweight system monitor that measures cpu, memory, mbuf, debug,
-process, interface and disk statistics every 5 seconds. This information
-is then spooled to
+is a lightweight system monitor that measures cpu, filesystem, interface, disk,
+memory, pf, pf queues, mbuf, proc and sensor statistics every 5 seconds. This
+information is then spooled to
 .Nm
 for further processing.
 .Pp
@@ -164,7 +164,7 @@ source 127.0.0.1 {
 	     io(wd0), io(wd1), io(wd2),
 	     io(wd3), io(cd0), io(cd1),
 	     df(sd0a), df(sd0d), df(sd0e) }
-
+.Pp
     datadir "/var/www/symon/rrds/localhost"
 }
 .fi
@@ -179,7 +179,7 @@ nexus:~/project/symon$ telnet 10.0.0.1 2100
 Trying 10.0.0.1...
 Connected to 10.0.0.1.
 Escape character is '^]'.
-
+.Pp
 10.0.0.1;mem::1077662160:7630848:53850112:469417984:0:25600;cpu:0:
 1077662160:0.00:0.00:0.30:0.20:99.50;io:wd0:1077662160:2074:12759:
 0:30736384:131780608;
@@ -192,7 +192,7 @@ Escape character is '^]'.
 0;if:xl0:1077658247:284267:452077:150620236:273265863:372:89478:0:
 0:0:0;if:de0:1077658247:1813721:1197722:729054136:568900227:101:2:
 0:0:198:0;
-
+.Pp
 ^]
 telnet> close
 Connection closed.
@@ -216,9 +216,12 @@ Data formats:
 .It cpu
 Time spent in ( user, nice, system, interrupt, idle ). Total time is 100, data
 is offered with precision 2.
-.It mem
-Memory in ( real_active, real_total, free, swap_used, swap_total ). All values
-are in bytes rounded of to page boundaries. Values are 32 bit unsigned integers.
+.It debug
+Kernel variables debug0 to debug19. ( debug0 : ... : debug19 ). Values are 32
+bit unsigned integers.
+.It df
+Disk free statistics ( blocks : bfree : bavail : files :
+ffree : synwrites : asyncwrites). Values are 64 bit unsigned integers.
 .It if
 Interface counters ( packets_in, packets_out, bytes_in, bytes_out,
 multicasts_in, multicasts_out, errors_in, errors_out, collisions, drops
@@ -231,6 +234,13 @@ Pre OpenBSD 3.5 io/disk counters ( total_transfers, total_seeks, total_bytes
 .It io2
 Io/disk counters ( total_rxfer, total_wxfer, total_seeks, total_rbytes,
 total_wbytes). Values are 64 bit unsigned integers.
+.It mbuf
+Mbuf statistics ( totmbufs : mt_data : mt_oobdata : mt_control :
+mt_header : mt_ftable : mt_soname : mt_soopts : pgused : pgtotal :
+totmem : totpct : m_drops : m_wait : m_drain ).
+.It mem
+Memory in ( real_active, real_total, free, swap_used, swap_total ). All values
+are in bytes rounded of to page boundaries. Values are 32 bit unsigned integers.
 .It pf
 Packet filter statistics ( bytes_v4_in : bytes_v4_out : bytes_v6_in :
 bytes_v6_out : packets_v4_in_pass : packets_v4_in_drop : packets_v4_out_pass :
@@ -239,25 +249,15 @@ packets_v6_out_pass : packets_v6_out_drop : states_entries : states_searches :
 states_inserts : states_removals : counters_match : counters_badoffset :
 counters_fragment : counters_short : counters_normalize : counters_memory
 ). Values are 64 bit unsigned integers.
-.It debug
-Kernel variables debug0 to debug19. ( debug0 : ... : debug19 ). Values are 32
-bit unsigned integers.
+.It pfq
+pf/altq queue statistics ( sent_bytes : sent_packets : drop_bytes :
+drop_packets ). Values are 64 bit unsigned integers.
 .It proc
 Process statistics ( number : uticks : sticks : iticks : cpusec : cpupct :
 procsz : rsssz ).
-.It mbuf
-Mbuf statistics ( totmbufs : mt_data : mt_oobdata : mt_control :
-mt_header : mt_ftable : mt_soname : mt_soopts : pgused : pgtotal :
-totmem : totpct : m_drops : m_wait : m_drain ).
 .It sensor
 Single sensor measurement offered with 7.6 precision. Value depends on sensor
 type.
-.It pfq
-pf/altq queue statistics ( sent_bytes : sent_packets : drop_bytes :
-drop_packets ). Values are 64 bit unsigned integers.
-.It df
-Disk free statistics ( blocks : bfree : bavail : files :
-ffree : synwrites : asyncwrites). Values are 64 bit unsigned integers.
 .El
 .Sh SIGNALS
 .Bl -tag -width Ds
@@ -333,7 +333,7 @@ will be unresponsive during this process.
 .Sh AUTHOR
 Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier helped to port to big-endian
 architectures. Matthew Gream helped to port symon to other BSD platforms.
-
+.Pp
 Port contributors: Marc Balmer, Matthew Gream, Daniel Hartmeier, J. Martin
 Petersen, Fredrik Soderblom and Harm Schotanus.
 .Sh SEE ALSO

+ 10 - 3
symon/symux/symux.c

@@ -1,4 +1,4 @@
-/* $Id: symux.c,v 1.36 2006/12/19 22:30:48 dijkstra Exp $ */
+/* $Id: symux.c,v 1.38 2007/01/20 12:52:50 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2006 Willem Dijkstra
@@ -284,7 +284,7 @@ main(int argc, char *argv[])
             slot = master_forbidread();
             timestamp = (time_t) packet.header.timestamp;
             stringbuf = shared_getmem(slot);
-            debug("stringbuf = 0x%8x", stringbuf);
+            debug("stringbuf = 0x%08x", stringbuf);
             snprintf(stringbuf, maxstringlen, "%s;", source->addr);
 
             /* hide this string region from rrd update */
@@ -293,7 +293,14 @@ main(int argc, char *argv[])
 
             while (offset < packet.header.length) {
                 bzero(&ps, sizeof(struct packedstream));
-                offset += sunpack(packet.data + offset, &ps);
+                if (packet.header.symon_version == 1) {
+                    offset += sunpack1(packet.data + offset, &ps);
+                } else if (packet.header.symon_version == 2) {
+                    offset += sunpack2(packet.data + offset, &ps);
+                } else {
+                    debug("unsupported packet version - ignoring data");
+                    ps.type = MT_EOT;
+                }
 
                 /* find stream in source */
                 stream = find_source_stream(source, ps.type, ps.arg);

+ 2 - 2
symon/symux/symux.h

@@ -1,4 +1,4 @@
-/* $Id: symux.h,v 1.20 2005/06/26 12:35:41 dijkstra Exp $ */
+/* $Id: symux.h,v 1.22 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -51,4 +51,4 @@
 /* Number of rrd errors logged before smothering sets in */
 #define SYMUX_MAXRRDERRORS 5
 
-#endif				/* _SYMUX_SYMUX_H */
+#endif                          /* _SYMUX_SYMUX_H */

+ 139 - 139
symon/symux/symuxnet.c

@@ -1,4 +1,4 @@
-/* $Id: symuxnet.c,v 1.21 2006/06/30 08:21:23 dijkstra Exp $ */
+/* $Id: symuxnet.c,v 1.23 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -66,63 +66,63 @@ get_symon_sockets(struct mux * mux)
 
     /* iterate over our sources to determine what types of sockets we need */
     SLIST_FOREACH(source, &mux->sol, sources) {
-	if (!get_source_sockaddr(source, AF_INET)) {
-	    if (!get_source_sockaddr(source, AF_INET6)) {
-		warning("cannot determine socket family for source %.200s", source->addr);
-	    }
-	}
-
-	family = source->sockaddr.ss_family;
-	/* do we have a socket for this type of family */
-	if (mux->symonsocket[family] <= 0) {
-	    if ((mux->symonsocket[family] = socket(family, SOCK_DGRAM, 0)) != -1) {
-		/* attempt to set reuse, ignore errors */
-		if (setsockopt(mux->symonsocket[family], SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
-		    warning ("could set socket options: %.200s", strerror(errno));
-		}
-
-		/*
-		 * does the mux statement specify a specific destination
-		 * address
-		 */
-		if (mux->sockaddr.ss_family == family) {
-		    cpysock((struct sockaddr *) & mux->sockaddr, &sockaddr);
-		} else {
-		    get_inaddrany_sockaddr(&sockaddr, family, SOCK_DGRAM, mux->port);
-		}
-
-		if (bind(mux->symonsocket[family], (struct sockaddr *) & sockaddr,
-			 SS_LEN(&sockaddr)) == -1) {
-		    switch (errno) {
-		    case EADDRNOTAVAIL:
-			warning("mux address %.200s is not a local address", mux->addr);
-			break;
-		    case EADDRINUSE:
-			warning("mux address %.200s %.200s already in use", mux->addr, mux->port);
-			break;
-		    case EACCES:
-			warning("mux port %.200s is restricted from current user", mux->port);
-			break;
-		    default:
-			warning("mux port %.200s bind failed", mux->port);
-			break;
-		    }
-		    close(mux->symonsocket[family]);
-		    mux->symonsocket[family] = 0;
-
-		} else {
-
-		    if (get_numeric_name(&sockaddr)) {
-			info("getnameinfo error - cannot determine numeric hostname and service");
-			info("listening for incoming symon traffic for family %d", family);
-		    } else
-			info("listening for incoming symon traffic on udp %.200s %.200s",
-			     res_host, res_service);
-
-		    nsocks++;
-		}
-	    }
-	}
+        if (!get_source_sockaddr(source, AF_INET)) {
+            if (!get_source_sockaddr(source, AF_INET6)) {
+                warning("cannot determine socket family for source %.200s", source->addr);
+            }
+        }
+
+        family = source->sockaddr.ss_family;
+        /* do we have a socket for this type of family */
+        if (mux->symonsocket[family] <= 0) {
+            if ((mux->symonsocket[family] = socket(family, SOCK_DGRAM, 0)) != -1) {
+                /* attempt to set reuse, ignore errors */
+                if (setsockopt(mux->symonsocket[family], SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
+                    warning ("could set socket options: %.200s", strerror(errno));
+                }
+
+                /*
+                 * does the mux statement specify a specific destination
+                 * address
+                 */
+                if (mux->sockaddr.ss_family == family) {
+                    cpysock((struct sockaddr *) & mux->sockaddr, &sockaddr);
+                } else {
+                    get_sockaddr(&sockaddr, family, SOCK_DGRAM, AI_PASSIVE, NULL, mux->port);
+                }
+
+                if (bind(mux->symonsocket[family], (struct sockaddr *) & sockaddr,
+                         SS_LEN(&sockaddr)) == -1) {
+                    switch (errno) {
+                    case EADDRNOTAVAIL:
+                        warning("mux address %.200s is not a local address", mux->addr);
+                        break;
+                    case EADDRINUSE:
+                        warning("mux address %.200s %.200s already in use", mux->addr, mux->port);
+                        break;
+                    case EACCES:
+                        warning("mux port %.200s is restricted from current user", mux->port);
+                        break;
+                    default:
+                        warning("mux port %.200s bind failed", mux->port);
+                        break;
+                    }
+                    close(mux->symonsocket[family]);
+                    mux->symonsocket[family] = 0;
+
+                } else {
+
+                    if (get_numeric_name(&sockaddr)) {
+                        info("getnameinfo error - cannot determine numeric hostname and service");
+                        info("listening for incoming symon traffic for family %d", family);
+                    } else
+                        info("listening for incoming symon traffic on udp %.200s %.200s",
+                             res_host, res_service);
+
+                    nsocks++;
+                }
+            }
+        }
     }
     return nsocks;
 }
@@ -134,10 +134,10 @@ get_client_socket(struct mux * mux)
     int error, sock, one = 1;
 
     if ((sock = socket(mux->sockaddr.ss_family, SOCK_STREAM, 0)) == -1)
-	fatal("could not obtain socket: %.200s", strerror(errno));
+        fatal("could not obtain socket: %.200s", strerror(errno));
 
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
-	fatal ("could set socket options: %.200s", strerror(errno));
+        fatal ("could set socket options: %.200s", strerror(errno));
     }
 
     bzero((void *) &hints, sizeof(struct addrinfo));
@@ -147,22 +147,22 @@ get_client_socket(struct mux * mux)
     hints.ai_socktype = SOCK_STREAM;
 
     if ((error = getaddrinfo(mux->addr, mux->port, &hints, &res)) != 0)
-	fatal("could not get address information for %.200s:%.200s - %.200s",
-	      mux->addr, mux->port, gai_strerror(error));
+        fatal("could not get address information for %.200s:%.200s - %.200s",
+              mux->addr, mux->port, gai_strerror(error));
 
     if (bind(sock, (struct sockaddr *) res->ai_addr, res->ai_addrlen) == -1)
-	fatal("could not bind socket: %.200s", strerror(errno));
+        fatal("could not bind socket: %.200s", strerror(errno));
 
     freeaddrinfo(res);
 
     if (listen(sock, SYMUX_TCPBACKLOG) == -1)
-	fatal("could not listen to socket: %.200s", strerror(errno));
+        fatal("could not listen to socket: %.200s", strerror(errno));
 
     fcntl(sock, O_NONBLOCK);
     mux->clientsocket = sock;
 
     info("listening for incoming connections on tcp %.200s %.200s",
-	 mux->addr, mux->port);
+         mux->addr, mux->port);
 
     return sock;
 }
@@ -173,45 +173,45 @@ get_client_socket(struct mux * mux)
  */
 void
 wait_for_traffic(struct mux * mux, struct source ** source,
-		 struct symonpacket * packet)
+                 struct symonpacket * packet)
 {
     fd_set readset;
     int i;
     int socksactive;
     int maxsock;
 
-    for (;;) {			/* FOREVER - until a valid symon packet is
-				 * received */
-	FD_ZERO(&readset);
-	FD_SET(mux->clientsocket, &readset);
-
-	maxsock = mux->clientsocket;
-
-	for (i = 0; i < AF_MAX; i++) {
-	    if (mux->symonsocket[i] > 0) {
-		FD_SET(mux->symonsocket[i], &readset);
-		maxsock = ((maxsock < mux->symonsocket[i]) ? mux->symonsocket[i] :
-			   maxsock);
-	    }
-	}
-
-	maxsock++;
-	socksactive = select(maxsock, &readset, NULL, NULL, NULL);
-
-	if (socksactive != -1) {
-	    if (FD_ISSET(mux->clientsocket, &readset)) {
-		spawn_client(mux->clientsocket);
-	    }
-
-	    for (i = 0; i < AF_MAX; i++)
-		if (FD_ISSET(mux->symonsocket[i], &readset)) {
-		    if (recv_symon_packet(mux, i, source, packet))
-			return;
-		}
-	} else {
-	    if (errno == EINTR)
-		return;		/* signal received while waiting, bail out */
-	}
+    for (;;) {                  /* FOREVER - until a valid symon packet is
+                                 * received */
+        FD_ZERO(&readset);
+        FD_SET(mux->clientsocket, &readset);
+
+        maxsock = mux->clientsocket;
+
+        for (i = 0; i < AF_MAX; i++) {
+            if (mux->symonsocket[i] > 0) {
+                FD_SET(mux->symonsocket[i], &readset);
+                maxsock = ((maxsock < mux->symonsocket[i]) ? mux->symonsocket[i] :
+                           maxsock);
+            }
+        }
+
+        maxsock++;
+        socksactive = select(maxsock, &readset, NULL, NULL, NULL);
+
+        if (socksactive != -1) {
+            if (FD_ISSET(mux->clientsocket, &readset)) {
+                spawn_client(mux->clientsocket);
+            }
+
+            for (i = 0; i < AF_MAX; i++)
+                if (FD_ISSET(mux->symonsocket[i], &readset)) {
+                    if (recv_symon_packet(mux, i, source, packet))
+                        return;
+                }
+        } else {
+            if (errno == EINTR)
+                return;         /* signal received while waiting, bail out */
+        }
     }
 }
 /* Receive a symon packet for mux. Checks if the source is allowed and returns the source found.
@@ -219,7 +219,7 @@ wait_for_traffic(struct mux * mux, struct source ** source,
  */
 int
 recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
-		  struct symonpacket * packet)
+                  struct symonpacket * packet)
 {
     struct sockaddr_storage sind;
     socklen_t sl;
@@ -231,56 +231,56 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
     tries = 0;
 
     do {
-	sl = sizeof(sind);
+        sl = sizeof(sind);
 
-	size = recvfrom(mux->symonsocket[socknr],
-			(void *) (packet->data + received),
-			sizeof(struct symonpacket) - received,
-			0, (struct sockaddr *) &sind, &sl);
-	if (size > 0)
-	    received += size;
+        size = recvfrom(mux->symonsocket[socknr],
+                        (void *) (packet->data + received),
+                        sizeof(struct symonpacket) - received,
+                        0, (struct sockaddr *) &sind, &sl);
+        if (size > 0)
+            received += size;
 
-	tries++;
+        tries++;
     } while ((size == -1) &&
-	     (errno == EAGAIN || errno == EINTR) &&
-	     (tries < SYMUX_MAXREADTRIES) &&
-	     (received < sizeof(packet->data)));
+             (errno == EAGAIN || errno == EINTR) &&
+             (tries < SYMUX_MAXREADTRIES) &&
+             (received < sizeof(packet->data)));
 
     if ((size == -1) &&
-	errno)
-	warning("recvfrom failed: %.200s", strerror(errno));
+        errno)
+        warning("recvfrom failed: %.200s", strerror(errno));
 
     *source = find_source_sockaddr(&mux->sol, (struct sockaddr *) &sind);
 
     get_numeric_name(&sind);
 
     if (*source == NULL) {
-	debug("ignored data from %.200s:%.200s", res_host, res_service);
-	return 0;
+        debug("ignored data from %.200s:%.200s", res_host, res_service);
+        return 0;
     } else {
-	/* get header stream */
-	mux->offset = getheader(packet->data, &packet->header);
-	/* check crc */
-	crc = packet->header.crc;
-	packet->header.crc = 0;
-	setheader(packet->data, &packet->header);
-	crc ^= crc32(packet->data, received);
-	if (crc != 0) {
-	    warning("ignored packet with bad crc from %.200s:%.200s",
-		    res_host, res_service);
-	    return 0;
-	}
-	/* check packet version */
-	if (packet->header.symon_version != SYMON_PACKET_VER) {
-	    warning("ignored packet with wrong version %d from %.200s:%.200s",
-		    packet->header.symon_version, res_host, res_service);
-	    return 0;
-	} else {
-	    if (flag_debug) {
-		debug("good data received from %.200s:%.200s", res_host, res_service);
-	    }
-	    return 1;		/* good packet received */
-	}
+        /* get header stream */
+        mux->offset = getheader(packet->data, &packet->header);
+        /* check crc */
+        crc = packet->header.crc;
+        packet->header.crc = 0;
+        setheader(packet->data, &packet->header);
+        crc ^= crc32(packet->data, received);
+        if (crc != 0) {
+            warning("ignored packet with bad crc from %.200s:%.200s",
+                    res_host, res_service);
+            return 0;
+        }
+        /* check packet version */
+        if (packet->header.symon_version > SYMON_PACKET_VER) {
+            warning("ignored packet with unsupported version %d from %.200s:%.200s",
+                    packet->header.symon_version, res_host, res_service);
+            return 0;
+        } else {
+            if (flag_debug) {
+                debug("good data received from %.200s:%.200s", res_host, res_service);
+            }
+            return 1;           /* good packet received */
+        }
     }
 }
 int
@@ -294,8 +294,8 @@ accept_connection(int sock)
     len = 0;
 
     if ((clientsock = accept(sock, (struct sockaddr *) &sind, &len)) < 0)
-	fatal("failed to accept an incoming connection. (%.200s)",
-	      strerror(errno));
+        fatal("failed to accept an incoming connection. (%.200s)",
+              strerror(errno));
 
     get_numeric_name(&sind);
 

+ 2 - 2
symon/symux/symuxnet.h

@@ -1,4 +1,4 @@
-/* $Id: symuxnet.h,v 1.11 2004/02/26 22:48:08 dijkstra Exp $ */
+/* $Id: symuxnet.h,v 1.12 2007/02/11 20:07:32 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2004 Willem Dijkstra
@@ -43,4 +43,4 @@ int accept_connection(int);
 int recv_symon_packet(struct mux *, int, struct source **, struct symonpacket *);
 void wait_for_traffic(struct mux *, struct source **, struct symonpacket *);
 __END_DECLS
-#endif				/* _SYMUX_SYMUXNET_H */
+#endif                          /* _SYMUX_SYMUXNET_H */