Browse Source

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

Wictor Lund 3 years ago
parent
commit
c3049f18fb
61 changed files with 1065 additions and 921 deletions
  1. 36 20
      symon/CHANGELOG
  2. 16 16
      symon/INSTALL
  3. 1 2
      symon/Makefile
  4. 4 6
      symon/Makefile.inc
  5. 2 1
      symon/TODO
  6. 1 2
      symon/client/Makefile
  7. 80 81
      symon/client/SymuxClient.pm
  8. 2 3
      symon/client/getsymonitem.pl
  9. 1 2
      symon/lib/Makefile
  10. 32 32
      symon/lib/data.c
  11. 2 2
      symon/lib/data.h
  12. 11 13
      symon/lib/error.c
  13. 2 2
      symon/lib/error.h
  14. 64 44
      symon/lib/lex.c
  15. 28 23
      symon/lib/lex.h
  16. 29 20
      symon/lib/net.c
  17. 4 6
      symon/lib/net.h
  18. 2 2
      symon/lib/xmalloc.c
  19. 8 8
      symon/ports/symon/Makefile
  20. 4 0
      symon/ports/symon/pkg/DEINSTALL
  21. 4 0
      symon/ports/symon/pkg/DEINSTALL-mon
  22. 3 3
      symon/ports/symon/pkg/DESCR
  23. 28 9
      symon/ports/symon/pkg/INSTALL
  24. 29 9
      symon/ports/symon/pkg/INSTALL-mon
  25. 1 1
      symon/ports/symon/pkg/MESSAGE
  26. 1 1
      symon/ports/symon/pkg/MESSAGE-mon
  27. 1 1
      symon/ports/symon/pkg/MESSAGE-mux
  28. 2 0
      symon/ports/symon/pkg/PLIST
  29. 1 0
      symon/ports/symon/pkg/PLIST-mon
  30. 1 0
      symon/ports/symon/pkg/PLIST-mux
  31. 3 3
      symon/symon/Makefile
  32. 6 7
      symon/symon/c_config.sh
  33. 50 21
      symon/symon/readconf.c
  34. 3 3
      symon/symon/readconf.h
  35. 8 7
      symon/symon/sm_cpu.c
  36. 5 5
      symon/symon/sm_debug.c
  37. 6 6
      symon/symon/sm_if.c
  38. 7 7
      symon/symon/sm_io.c
  39. 17 17
      symon/symon/sm_mbuf.c
  40. 5 5
      symon/symon/sm_mem.c
  41. 15 11
      symon/symon/sm_pf.c
  42. 18 18
      symon/symon/sm_proc.c
  43. 10 10
      symon/symon/sm_sensor.c
  44. 57 43
      symon/symon/symon.8
  45. 89 69
      symon/symon/symon.c
  46. 11 6
      symon/symon/symon.conf
  47. 21 9
      symon/symon/symon.h
  48. 9 9
      symon/symon/symonnet.c
  49. 2 2
      symon/symon/symonnet.h
  50. 3 3
      symon/symux/Makefile
  51. 132 123
      symon/symux/c_smrrds.sh
  52. 41 52
      symon/symux/readconf.c
  53. 2 2
      symon/symux/readconf.h
  54. 22 31
      symon/symux/share.c
  55. 2 2
      symon/symux/share.h
  56. 41 41
      symon/symux/symux.8
  57. 13 19
      symon/symux/symux.c
  58. 29 19
      symon/symux/symux.conf
  59. 2 2
      symon/symux/symux.h
  60. 33 57
      symon/symux/symuxnet.c
  61. 3 3
      symon/symux/symuxnet.h

+ 36 - 20
symon/CHANGELOG

@@ -1,15 +1,31 @@
+20/10/2003 - 2.63
+
+   - removed large char arrays on the stack that broke name resolution
+
+   - symon(8) now chroots and drop priviledges to user "_symon" (Henning
+     Brauer)
+
+   - added support for adjusting symon(8) monitoring interval (Henning
+     Brauer)
+
+   - removed typos and better starter configuration (Franciszek Holop)
+
+   - port: MESSAGEs were incorrect (Soeren Thing Andersen), PLIST
+     incomplete (Henning Brauer), HOMEPAGE in Makefile was off (Robert
+     Winder)
+
 12/10/2003 - 2.62
 
    - removed errors in c_smrrds.sh (Henning Brauer)
-   
+
    - detecting sensor support was broken (Nick Forbes)
 
 03/10/2003 - 2.61
 
    - added sensor probe
 
-   - removed symon2web from base source package. symon2web (or the new syweb
-     package) can be downloaded from the main website. 
+   - removed symon2web from base source package. symon2web (or the new
+     syweb package) can be downloaded from the main website.
 
    - symux churnbuffer calculation now deals with ipv6 hostnames too
 
@@ -19,7 +35,7 @@
 
    - symon uses group probes only for configured streams
 
-   - c_config.sh was not included in the PLIST for the symon package 
+   - c_config.sh was not included in the PLIST for the symon package
      (Andrew Dalgleish)
 
 23/03/2003 - 2.60
@@ -27,7 +43,7 @@
    - sm_io was broken on sparc64
    - ntohq functions were not detected for big endian machines
    - c_config.sh broke on nfs mounts and pfsync
-   
+
    All: thanks to Henning Brauer
 
 26/02/2003 - 2.59
@@ -57,14 +73,14 @@
    Added proc and debug symon2web frontends. Debug has limited
    useability, you are better off defining one for yourself.
 
-14/12/2002 - 
+14/12/2002 -
 
    Added the proc module. This can be used to retrieve accumulated
    information about processes with the same name. A proc(httpd)
    statement in symon.conf, for instance, will result in the reporting
    of the number of processes called "httpd" and the amounts of cpu and
    memory that they take.
-  
+
    Added em device to c_smrrds.sh - thanks to Jung.  Fixed typo in
    SymuxClient.pm - thanks Tobias Gresch.  c_config.sh did not deal with
    type mfs devices - thanks Dom De Vitto.
@@ -88,7 +104,7 @@
    something with the measurements as they come in. (I plan to drive an
    LCD using this, but it could also be used to get, say, daily
    bandwidth usage)
- 
+
    Clients of symux would not sleep after they had read and relayed data
    symux gave to them. This could lead to one child eating up multiple
    'semaphore slots' and starvation in other clients - fixed.
@@ -129,7 +145,7 @@
 
    Installation of symon now also generates a default symon.conf file if
    the system does not already have one.
-   
+
    Someone at www.deadly.org pointed out that symon is no longer
    compatible with OpenBSD 3.0 - removed claim from the website.
 
@@ -139,7 +155,7 @@
 
    symux would bomb out after a hup - fixed.
 
-14/09/2002 - 2.51 
+14/09/2002 - 2.51
 
    Steve Shockley reported that the port Makefile did not install rrd
    tool. (Which is required for compilation of symux)
@@ -181,7 +197,7 @@
 
 01/09/2002 - Internal cosmetics - not released
 
-   mon/mon.c: 
+   mon/mon.c:
      - mon packetsize is still limited by size of struct monpacket in
        data.h:79. All other limits have been removed.
 
@@ -194,7 +210,7 @@
 
 31/08/2002 - 2.3
 
-    Makefiles, mon/mon.c: 
+    Makefiles, mon/mon.c:
      - Environment variable KVM will enable the building of a setgid
        kmem version of the monitor. If this environment variable is not
        present, a non priviledged monitor will be built. (Note that all
@@ -205,7 +221,7 @@
     mon/if.c:
      - obtain ifdata as per h1kari's suggestion.
 
-    mon/pf.c: 
+    mon/pf.c:
      - global naming in sync with other probes
      - repeated initialisation would eat up fds
 
@@ -222,7 +238,7 @@
     Merged contributions by Daniel Hartmeier:
      - cpu probe had a nasty va_arg bug that only showed up on
        big-endian machines.
-    
+
 29/08/2002 - 2.1
 
     Merged contributions by Daniel Hartmeier:
@@ -253,12 +269,12 @@
 
 01/04/2002 - changed all memsets into bzero
              all output messages have the same format now
-             write pids in /var/run 
+             write pids in /var/run
              SIGHUP = reload configuration
 
 31/03/2002 - cleaned up source
 
-             added error reporting routines. 
+             added error reporting routines.
 
 29/03/2002 - mon and monmux no use monpacket to communicate with each
              other. This format defines: version, lenght and crc of the traffic
@@ -267,7 +283,7 @@
              mon no longer connects. monmux and mon can be started and stopped
              independently.
 
-             monmux now checks if incoming traffic is allowed from a certain host.             
+             monmux now checks if incoming traffic is allowed from a certain host.
 
              added rrd write support to monmux
 
@@ -292,8 +308,8 @@
 
 24/11/2001 - Rewrote lib to KNF, OpCodes removed
 03/11/2001 - Added datatypes and rewrote readconf to use SLISTs.
-01/10/2001 - Mon configuration is read from a mon.conf. 
-29/09/2001 - Lexer had trouble dealing with ip-addresses. Cleaned up the number	
+01/10/2001 - Mon configuration is read from a mon.conf.
+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.21 2003/10/12 17:26:04 dijkstra Exp $
+$Id: CHANGELOG,v 1.25 2003/12/21 13:01:05 dijkstra Exp $

+ 16 - 16
symon/INSTALL

@@ -5,15 +5,16 @@ Priviledges
 ===========
 symux needs read and write access to it's rrdfiles.
 
-monitoring needs:
+symon needs:
 cpu, debug, if, io, mbuf, mem, proc, sensor - symon can run as nobody
 pf                                          - symon needs r/w on /dev/pf
 
-Real quick 
+Real quick
 ==========
-make && make install && vi /etc/symux.conf /etc/symon.conf && 
-	~symon/symux/c_smrrds.sh all && 
-	/usr/local/libexec/symux && 
+make && make install && vi /etc/symux.conf /etc/symon.conf &&
+	~symon/symux/c_smrrds.sh all &&
+	/usr/local/libexec/symux &&
+	useradd _symon
 	/usr/local/libexec/symon
 
 or grab the port and do
@@ -25,7 +26,7 @@ Install the seperate syweb package to show the data stored in the rrd files.
 
 Less quick, but more verbose
 ============================
-- Install rrdtool where you want to run the gatherer. 
+- Install rrdtool where you want to run the gatherer.
 	cd /usr/ports/net/rrdtool && make install
 
 - Building by hand: Check Makefile.inc for settings. Things to watch out for
@@ -45,7 +46,7 @@ Less quick, but more verbose
 
    Run make && make install
 
-- Building from the port: 
+- Building from the port:
 	cd ~symon/ports/symon or cd /usr/ports/sysutils/symon
 	make package
 
@@ -53,11 +54,10 @@ Less quick, but more verbose
 	pkg_add symon-mon-version.tgz               on monitored hosts
 	pkg_add symon-mux-version.tgz               on the loghost | gatherer
 
-- Create an '/etc/symon.conf'. Note that there is an example configuration in
-  $PREFIX/$SHRDIR. 
-
-- Create a symux.conf on the gatherer host. You can specify alternative
-  locations than '/etc/symux.conf' using 'symux -f symux.conf'.
+- Create an '/etc/symon.conf' for each monitored host and one symux.conf for
+  the gatherer host. See the manual pages on how to specify alternative
+  configuration file locations, if necessary. Note that there are example
+  configurations for both in $PREFIX/$SHRDIR.
 
 - Create the rrd files where the incoming symon data is to be
   stored. $PREFIX/$SHRDIR/c_smrrds.sh is your friend. Note that syweb expects
@@ -65,14 +65,14 @@ Less quick, but more verbose
 
 - Fire up symon, symux. Check system logs for any failures.
 
-- Only if you need the webinterface: download and install syweb. 
+- Only if you need the webinterface: download and install syweb.
 
 Getting measurements without the web
 ====================================
 
 The client directory contains a perl module 'SymuxClient.pm' that can be used
 to read measurements as they come in at the symux host. A sample Perl program
-called 'getsymonitem.pl' shows how to use the module. 
+called 'getsymonitem.pl' shows how to use the module.
 
 Example:
 
@@ -85,10 +85,10 @@ Portability
 ===========
 
 This package is an OpenBSD application. You might be able to make symux and
-symon2web run on POSIX compliant unixes, but the monitoring application itself
+syweb run on POSIX compliant unixes, but the monitoring application itself
 (symon) is OpenBSD specific.
 
 Willem Dijkstra - wpd@xs4all.nl
 
-$Id: INSTALL,v 1.11 2003/10/10 15:19:45 dijkstra Exp $
+$Id: INSTALL,v 1.12 2003/12/20 16:30:44 dijkstra Exp $
 

+ 1 - 2
symon/Makefile

@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.12 2003/10/10 15:19:45 dijkstra Exp $
+# $Id: Makefile,v 1.13 2003/12/20 16:30:44 dijkstra Exp $
 
 SUBDIR=	lib symon symux client
 
@@ -38,4 +38,3 @@ _SUBDIRUSE: .USE
 		${MAKE} ${.MAKEFLAGS} ${.TARGET}; \
 	done
 .endif
-

+ 4 - 6
symon/Makefile.inc

@@ -1,11 +1,11 @@
-# $Id: Makefile.inc,v 1.18 2003/10/12 17:26:04 dijkstra Exp $
+# $Id: Makefile.inc,v 1.20 2003/12/21 13:01:05 dijkstra Exp $
 
-V=2.62
+V=2.63
 
 AR=	ar
 CC=	cc
 .ifdef DEBUG
-CFLAGS+= -g -Wall
+CFLAGS+=-g -Wall
 .else
 CFLAGS+=-Wall
 .endif
@@ -38,10 +38,8 @@ SYSCONFDIR=/etc
 
 .8.cat8:
 	${NROFF} -mandoc $< > $@ || (rm -f $@; false)
-		
+
 .pm.cat3p:
 	${POD2MAN} $< > $@.tmp || (rm -f $@; false)
 	${NROFF} -mandoc $@.tmp > $@ || (rm -f $@; false)
 	rm -f $@.tmp
-
-

+ 2 - 1
symon/TODO

@@ -9,5 +9,6 @@ TODO:
 == longer term
 - change rrd to accommodate batch updates
 - write a muxer that supports unix pipes
+- test framework
 
-$Id: TODO,v 1.25 2003/10/10 15:19:45 dijkstra Exp $
+$Id: TODO,v 1.26 2003/12/20 16:30:44 dijkstra Exp $

+ 1 - 2
symon/client/Makefile

@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.1 2002/11/08 15:40:25 dijkstra Exp $
+# $Id: Makefile,v 1.2 2003/12/20 16:30:44 dijkstra Exp $
 .include "../Makefile.inc"
 
 all: SymuxClient.cat3p
@@ -11,4 +11,3 @@ install: SymuxClient.pm SymuxClient.cat3p getsymonitem.pl
 	${INSTALL} -c -m 555 -g bin   -o root getsymonitem.pl      ${PREFIX}/${CLIENTDIR}
 	${INSTALL} -c -m 444 -g wheel -o root SymuxClient.pm       ${PREFIX}/${CLIENTDIR}
 	${INSTALL} -c -m 444 -g wheel -o root SymuxClient.cat3p    ${PREFIX}/${CLIENTDIR}/SymuxClient.0
-

+ 80 - 81
symon/client/SymuxClient.pm

@@ -1,6 +1,6 @@
-# $Id: SymuxClient.pm,v 1.6 2003/10/10 15:19:47 dijkstra Exp $
+# $Id: SymuxClient.pm,v 1.7 2003/12/20 16:30:44 dijkstra Exp $
 #
-# Copyright (c) 2001-2002 Willem Dijkstra
+# Copyright (c) 2001-2003 Willem Dijkstra
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -33,43 +33,43 @@ package SymuxClient;
 use Carp;
 use IO::Socket;
 
-my $streamitem = 
+my $streamitem =
     {cpu   => {user => 1, nice => 2, system => 3, interrupt => 4, idle => 5},
-     mem   => {real_active => 1, real_total => 2, free => 3, swap_used => 4, 
+     mem   => {real_active => 1, real_total => 2, free => 3, swap_used => 4,
 	       swap_total =>5},
-     if    => {packets_in => 1, packets_out => 2, bytes_in => 3, bytes_out => 4, 
-	       multicasts_in => 5, multicasts_out => 6, errors_in => 7, 
+     if    => {packets_in => 1, packets_out => 2, bytes_in => 3, bytes_out => 4,
+	       multicasts_in => 5, multicasts_out => 6, errors_in => 7,
 	       errors_out => 8, collisions => 9, drops => 10},
      io    => {total_transfers => 1, total_seeks => 2, total_bytes => 3},
      pf    => {bytes_v4_in => 1, bytes_v4_out => 2, bytes_v6_in => 3,
-	       bytes_v6_out => 4, packets_v4_in_pass => 5, 
+	       bytes_v6_out => 4, packets_v4_in_pass => 5,
 	       packets_v4_in_drop => 6, packets_v4_out_pass => 7,
-	       packets_v4_out_drop => 8, packets_v6_in_pass => 9, 
+	       packets_v4_out_drop => 8, packets_v6_in_pass => 9,
 	       packets_v6_in_drop => 10, packets_v6_out_pass => 11,
-	       packets_v6_out_drop => 12, states_entries => 13, 
-	       states_searches => 14, states_inserts => 15, 
-	       states_removals => 16, counters_match => 17, 
+	       packets_v6_out_drop => 12, states_entries => 13,
+	       states_searches => 14, states_inserts => 15,
+	       states_removals => 16, counters_match => 17,
 	       counters_badoffset => 18, counters_fragment => 19,
-	       counters_short => 20, counters_normalize => 21, 
+	       counters_short => 20, counters_normalize => 21,
 	       counters_memory => 22},
      debug => {debug0 => 1, debug1 => 2, debug3 => 3, debug4 => 4, debug5 => 5,
-	       debug6 => 6, debug7 => 7, debug8 => 8, debug9 => 9, 
+	       debug6 => 6, debug7 => 7, debug8 => 8, debug9 => 9,
 	       debug10 => 10, debug11 => 11, debug12 => 12, debug13 => 13,
 	       debug14 => 14, debug15 => 15, debug16 => 16, debug17 => 17,
 	       debug18 => 18, debug19 => 19},
-     proc  => {number => 1, uticks => 2, sticks => 3, iticks => 4, cpusec => 5, 
+     proc  => {number => 1, uticks => 2, sticks => 3, iticks => 4, cpusec => 5,
 	       cpupct => 6, procsz => 7, rsssz => 8},
      mbuf => {totmbufs => 1, mt_data => 2, mt_oobdata => 3, mt_control => 4,
 	      mt_header => 5, mt_ftable => 6, mt_soname => 7, mt_soopts => 8,
-	      pgused => 9, pgtotal => 10, totmem => 11, totpct => 12, 
+	      pgused => 9, pgtotal => 10, totmem => 11, totpct => 12,
 	      m_drops => 13, m_wait => 14, m_drain => 15 },
      sensor => {value => 1}};
 sub new {
     my ($class, %arg) = @_;
     my $self;
-    
-    (defined $arg{host} && defined $arg{port}) or 
-        croak "error: need a host and a port to connect to.";
+
+    (defined $arg{host} && defined $arg{port}) or
+	croak "error: need a host and a port to connect to.";
 
     ($self->{host}, $self->{port}) = ($arg{host}, $arg{port});
 
@@ -86,25 +86,25 @@ sub DESTROY {
     my $self = shift;
 
     if (defined $self->{sock}) {
-        close($self->{sock});
+	close($self->{sock});
     }
 }
-    
+
 sub connect {
     my $self = shift;
 
     if (defined $self->{sock} && $self->{sock}->connected() ne '') {
-        return;
-    } else { 
-        close($self->{sock});
+	return;
+    } else {
+	close($self->{sock});
     }
-    
-    $self->{sock} = new 
+
+    $self->{sock} = new
       IO::Socket::INET(PeerAddr => $self->{host},
-                       PeerPort => $self->{port},
-                       Proto => "tcp",
-                       Type => SOCK_STREAM)
-          or croak "error: could not connect to $self->{host}:$self->{port}";
+		       PeerPort => $self->{port},
+		       Proto => "tcp",
+		       Type => SOCK_STREAM)
+	  or croak "error: could not connect to $self->{host}:$self->{port}";
 }
 
 sub getdata {
@@ -116,16 +116,16 @@ sub getdata {
     $tries = 0;
 
     while (1) {
-        $self->connect();
-        $sock = $self->{sock};
-        $data = <$sock>;
-        if ((index($data, "\012") != -1) && (index($data, ';') != -1)) {
-            $self->{rawdata} = $data;
-            return $data;
-        } else {
-            croak "error: tried to get data $tries times and failed"  
-                if (++$tries == $self->{retry});
-        }
+	$self->connect();
+	$sock = $self->{sock};
+	$data = <$sock>;
+	if ((index($data, "\012") != -1) && (index($data, ';') != -1)) {
+	    $self->{rawdata} = $data;
+	    return $data;
+	} else {
+	    croak "error: tried to get data $tries times and failed"
+		if (++$tries == $self->{retry});
+	}
     }
 }
 
@@ -142,21 +142,21 @@ sub parse {
     chop $self->{rawdata};
 
     @streams = split(/;/, $self->{rawdata});
-    croak "error: expected a symux dataline with ';' delimited streams" 
-        if ($#streams < 2);
-    
+    croak "error: expected a symux dataline with ';' delimited streams"
+	if ($#streams < 2);
+
     $self->{datasource} = shift @streams;
-    
+
     foreach $stream (@streams) {
-        ($name, $arg, @data) = split(':', $stream);
-        
-        croak "error: expected a symux stream with ':' delimited values"
-            if ($#data < 2);
+	($name, $arg, @data) = split(':', $stream);
 
-        $name .= '('.$arg.')' if ($arg ne '');
+	croak "error: expected a symux stream with ':' delimited values"
+	    if ($#data < 2);
 
-        @{$self->{data}{$name}} = @data;
-        $number++;
+	$name .= '('.$arg.')' if ($arg ne '');
+
+	@{$self->{data}{$name}} = @data;
+	$number++;
     }
 
     $self->{rawdata} = '';
@@ -168,22 +168,22 @@ sub getcacheditem {
     my ($streamtype, @addr, $element);
 
     return undef if not defined $self->{datasource};
-    return undef if (($host ne $self->{datasource})  && 
+    return undef if (($host ne $self->{datasource})  &&
 		     ($host ne "*"));
 
-    croak "error: source $host does not contain stream $streamname" 
-        if not defined $self->{data}{$streamname};
+    croak "error: source $host does not contain stream $streamname"
+	if not defined $self->{data}{$streamname};
 
     ($streamtype = $streamname) =~ s/^([a-z]+).*/\1/;
 
     if ($item eq 'timestamp') {
-        $element = 0;
+	$element = 0;
     } elsif (not defined $$streamitem{$streamtype}{$item}) {
-        croak "error: unknown stream item '$item' - check symux(8) for names";
+	croak "error: unknown stream item '$item' - check symux(8) for names";
     } else {
-        $element = $$streamitem{$streamtype}{$item};
+	$element = $$streamitem{$streamtype}{$item};
     }
-        
+
     return $self->{data}{$streamname}[$element];
 }
 
@@ -191,18 +191,18 @@ sub getitem {
     my ($self, $host, $streamname, $item) = @_;
     my $data;
     my %hosts = ();
-    
+
     undef $data;
     while (! defined $data) {
-        $self->getdata();
-        $self->parse();
-        $hosts{$self->{datasource}} += 1;
-        if ($hosts{$self->{datasource}} > $self->{retry}) {
-            croak "error: seen a lot of data ($tries strings), but none that matches $host";
-        }
-        $data = $self->getcacheditem($host, $streamname, $item);
-        return $data if defined $data;
-        $tries++;
+	$self->getdata();
+	$self->parse();
+	$hosts{$self->{datasource}} += 1;
+	if ($hosts{$self->{datasource}} > $self->{retry}) {
+	    croak "error: seen a lot of data ($tries strings), but none that matches $host";
+	}
+	$data = $self->getcacheditem($host, $streamname, $item);
+	return $data if defined $data;
+	$tries++;
     }
 }
 
@@ -239,17 +239,17 @@ and data it receives from that connection. Arguments are:
 
     host           dotted quad ipv4 hostaddress
     port           tcp port that symux is on
-    retry*         maximum number of retries; used to limit number 
-                   of connection attempts and number of successive 
-                   read attempts
+    retry*         maximum number of retries; used to limit number
+		   of connection attempts and number of successive
+		   read attempts
 
 Arguments marked with * are optional.
 
 Example:
     $sc = new SymuxClient(host => 127.0.0.1,
-                          port => 2100);
+			  port => 2100);
 
-=back 
+=back
 
 =head2 METHODS
 
@@ -273,22 +273,21 @@ with 'error: '.
 Get the symon source host of the currently cached information. Usefull to see
 what host's data getcacheditem is working on.
 
-Example: 
+Example:
     $sc = new SymuxClient(host => 127.0.0.1,
-                          port => 2100);
+			  port => 2100);
 
-    print $sc->getitem("127.0.0.1", "if(de0)", 
-                       "packets_out");
+    print $sc->getitem("127.0.0.1", "if(de0)",
+		       "packets_out");
 
     # get more data from that measurement
-    print $sc->getcacheditem("127.0.0.1","if(de0)", 
-                             "packets_in"); 
+    print $sc->getcacheditem("127.0.0.1","if(de0)",
+			     "packets_in");
 
     # start a new measurement
-    print $sc->getitem("*", "if(de0)", 
-                       "packets_out");
+    print $sc->getitem("*", "if(de0)",
+		       "packets_out");
     # which hosts packets_out was that?
     print $sc->getsource();
 
 =cut
-

+ 2 - 3
symon/client/getsymonitem.pl

@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
-# $Id: getsymonitem.pl,v 1.1 2002/11/08 15:40:25 dijkstra Exp $
-# 
+# $Id: getsymonitem.pl,v 1.2 2003/12/20 16:30:44 dijkstra Exp $
+#
 # Example program of how to use SymuxClient
 
 use SymuxClient;
@@ -13,4 +13,3 @@ my $sc = new SymuxClient( host => $ARGV[0],
 			  port => $ARGV[1]);
 
 print $sc->getitem( $ARGV[2], $ARGV[3], $ARGV[4] );
-			  

+ 1 - 2
symon/lib/Makefile

@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.8 2002/09/14 15:56:18 dijkstra Exp $
+# $Id: Makefile,v 1.9 2003/12/20 16:30:44 dijkstra Exp $
 .include "../Makefile.inc"
 
 SRCS=   error.c lex.c xmalloc.c net.c data.c
@@ -16,4 +16,3 @@ clean:
 	rm -f libsymon.a ${OBJS}
 
 install: libsymon.a
-

+ 32 - 32
symon/lib/data.c

@@ -1,7 +1,7 @@
-/* $Id: data.c,v 1.21 2003/10/10 15:19:49 dijkstra Exp $ */
+/* $Id: data.c,v 1.22 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * The crc routine is from Rob Warnock <rpw3@sgi.com>, from the
@@ -128,7 +128,7 @@ u_int32_t
 crc32_table[256];
 
 /* Convert lexical entities to stream entities */
-const int 
+const int
 token2type(const int token)
 {
     int i;
@@ -160,7 +160,7 @@ type2str(const int streamtype)
     return 0;
 }
 /* Return the maximum lenght of the ascii representation of type <type> */
-int 
+int
 strlentype(int type)
 {
     int i = 0;
@@ -172,7 +172,7 @@ strlentype(int type)
     return sum;
 }
 /* Return the maximum lenght of the ascii representation of streamvar <var> */
-int 
+int
 strlenvar(char var)
 {
     int i;
@@ -188,7 +188,7 @@ strlenvar(char var)
     return 0;
 }
 /* Return the maximum lenght of the network representation of streamvar <var> */
-int 
+int
 bytelenvar(char var)
 {
     int i;
@@ -235,19 +235,18 @@ rrdstrvar(char var)
     return "";
 }
 /* Check whether <extra> more bytes fit in <maxlen> when we are already at <start> */
-int 
+int
 checklen(int maxlen, int current, int extra)
 {
     if ((current + extra) < maxlen) {
 	return 0;
-    }
-    else {
+    } else {
 	warning("buffer overflow: max=%d, current=%d, extra=%d",
 		maxlen, current, extra);
 	return 1;
     }
 }
-int 
+int
 setheader(char *buf, struct symonpacketheader *hph)
 {
     struct symonpacketheader nph;
@@ -271,7 +270,7 @@ setheader(char *buf, struct symonpacketheader *hph)
 
     return (p - buf);
 }
-int 
+int
 getheader(char *buf, struct symonpacketheader *hph)
 {
     char *p;
@@ -297,7 +296,7 @@ getheader(char *buf, struct symonpacketheader *hph)
  * Pack multiple arguments of a MT_TYPE into a network order bytestream.
  * snpack returns the number of bytes actually stored.
  */
-int 
+int
 snpack(char *buf, int maxlen, char *id, int type,...)
 {
     va_list ap;
@@ -318,16 +317,14 @@ snpack(char *buf, int maxlen, char *id, int type,...)
 
     if (maxlen < 2) {
 	fatal("%s:%d: maxlen too small", __FILE__, __LINE__);
-    }
-    else {
+    } else {
 	buf[offset++] = type & 0xff;
     }
 
     if (id) {
 	if ((strlen(id) + 1) >= maxlen) {
 	    return 0;
-	}
-	else {
+	} else {
 	    strncpy(&buf[offset], id, maxlen - 1);
 	    offset += strlen(id);
 	}
@@ -380,7 +377,7 @@ snpack(char *buf, int maxlen, char *id, int type,...)
 	    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);
@@ -388,9 +385,11 @@ snpack(char *buf, int maxlen, char *id, int type,...)
 	    bcopy(&d, buf + offset, sizeof(int64_t));
 	    offset += sizeof(int64_t);
 	    break;
-	    
+
 	default:
-	    warning("unknown stream format identifier");
+	    warning("unknown stream format identifier %c in type %d",
+		    streamform[type].form[i],
+		    type);
 	    return 0;
 	}
 	i++;
@@ -407,7 +406,7 @@ snpack(char *buf, int maxlen, char *id, int type,...)
  * description of the packedstream (streamform) to parse the actual bytes. This
  * description corresponds to the amount of bytes that will fit inside the
  * packedstream structure.  */
-int 
+int
 sunpack(char *buf, struct packedstream * ps)
 {
     char *in, *out;
@@ -434,8 +433,7 @@ sunpack(char *buf, struct packedstream * ps)
 	strncpy(ps->args, in, sizeof(ps->args));
 	ps->args[sizeof(ps->args) - 1] = '\0';
 	in += strlen(ps->args);
-    }
-    else {
+    } else {
 	ps->args[0] = '\0';
     }
 
@@ -492,7 +490,9 @@ sunpack(char *buf, struct packedstream * ps)
 	    break;
 
 	default:
-	    warning("unknown stream format identifier");
+	    warning("unknown stream format identifier %c in type %d",
+		    streamform[type].form[i],
+		    type);
 	    return 0;
 	}
 	i++;
@@ -500,7 +500,7 @@ sunpack(char *buf, struct packedstream * ps)
     return (in - buf);
 }
 /* Get the RRD or 'pretty' ascii representation of packedstream */
-int 
+int
 ps2strn(struct packedstream * ps, char *buf, const int maxlen, int pretty)
 {
     u_int16_t b;
@@ -574,9 +574,9 @@ ps2strn(struct packedstream * ps, char *buf, const int maxlen, int pretty)
 	    in += sizeof(int64_t);
 	    break;
 
-	    
+
 	default:
-	    warning("Unknown stream format identifier");
+	    warning("unknown stream format identifier %c", vartype);
 	    return 0;
 	}
 	out += strlen(out);
@@ -780,7 +780,7 @@ rename_mux(struct muxlist * mul, struct mux * mux, char *name)
 
     return mux;
 }
-void 
+void
 free_muxlist(struct muxlist * mul)
 {
     struct mux *p, *np;
@@ -814,7 +814,7 @@ free_muxlist(struct muxlist * mul)
 	p = np;
     }
 }
-void 
+void
 free_streamlist(struct streamlist * sl)
 {
     struct stream *p, *np;
@@ -836,7 +836,7 @@ free_streamlist(struct streamlist * sl)
 	p = np;
     }
 }
-void 
+void
 free_sourcelist(struct sourcelist * sol)
 {
     struct source *p, *np;
@@ -859,7 +859,7 @@ free_sourcelist(struct sourcelist * sol)
     }
 }
 /* Calculate maximum buffer space needed for a single symon hit */
-int 
+int
 calculate_churnbuffer(struct sourcelist * sol)
 {
     char buf[_POSIX2_LINE_MAX];
@@ -880,7 +880,7 @@ calculate_churnbuffer(struct sourcelist * sol)
 	SLIST_FOREACH(stream, &source->sl, streams) {
 	    len += strlen(type2str(stream->type)) + strlen(":");
 	    len += strlen(stream->args) + strlen(":");
-	    len += (sizeof(time_t) * 3) + strlen(":"); /* 3 =~ ln(255) / ln(10) */
+	    len += (sizeof(time_t) * 3) + strlen(":"); /* 3 > ln(255) / ln(10) */
 	    len += strlentype(stream->type);
 	    n++;
 	}
@@ -903,7 +903,7 @@ crc32(const void *buf, unsigned int len)
     return ~crc;
 }
 /* Init table for CRC32 */
-void 
+void
 init_crc32()
 {
     unsigned int i, j;

+ 2 - 2
symon/lib/data.h

@@ -1,7 +1,7 @@
-/* $Id: data.h,v 1.21 2003/10/10 15:19:49 dijkstra Exp $ */
+/* $Id: data.h,v 1.22 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 11 - 13
symon/lib/error.c

@@ -1,7 +1,7 @@
-/* $Id: error.c,v 1.10 2002/11/29 10:50:29 dijkstra Exp $ */
+/* $Id: error.c,v 1.11 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -69,7 +69,7 @@ struct {
  * Internal helper that actually outputs every
  * (fatal|warning|info|debug) message
  */
-void 
+void
 output_message(int level, char *fmt, va_list args)
 {
     char msgbuf[_POSIX2_LINE_MAX];
@@ -91,20 +91,18 @@ output_message(int level, char *fmt, va_list args)
 
     if (flag_daemon) {
 	syslog(logmapping[loglevel].priority, msgbuf);
-    }
-    else {
+    } else {
 	if (strlen(logmapping[loglevel].errtxt) > 0) {
-	    fprintf(logmapping[loglevel].stream, "%s: %s\n",
+	    fprintf(logmapping[loglevel].stream, "%.200s: %.200s\n",
 		    logmapping[loglevel].errtxt, msgbuf);
-	}
-	else
-	    fprintf(logmapping[loglevel].stream, "%s\n", msgbuf);
+	} else
+	    fprintf(logmapping[loglevel].stream, "%.200s\n", msgbuf);
 
 	fflush(logmapping[loglevel].stream);
     }
 }
 /* Output error and exit */
-__dead void 
+__dead void
 fatal(char *fmt,...)
 {
     va_list ap;
@@ -115,7 +113,7 @@ fatal(char *fmt,...)
     exit(1);
 }
 /* Warn and continue */
-void 
+void
 warning(char *fmt,...)
 {
     va_list ap;
@@ -124,7 +122,7 @@ warning(char *fmt,...)
     va_end(ap);
 }
 /* Inform and continue */
-void 
+void
 info(char *fmt,...)
 {
     va_list ap;
@@ -133,7 +131,7 @@ info(char *fmt,...)
     va_end(ap);
 }
 /* Debug statements only */
-void 
+void
 debug(char *fmt,...)
 {
     va_list ap;

+ 2 - 2
symon/lib/error.h

@@ -1,7 +1,7 @@
-/* $Id: error.h,v 1.7 2002/11/29 10:50:29 dijkstra Exp $ */
+/* $Id: error.h,v 1.8 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 64 - 44
symon/lib/lex.c

@@ -1,4 +1,4 @@
-/* $Id: lex.c,v 1.17 2003/10/10 15:19:49 dijkstra Exp $ */
+/* $Id: lex.c,v 1.18 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2003 Willem Dijkstra
@@ -49,10 +49,11 @@
 #include <sys/types.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "xmalloc.h"
 #include "lex.h"
@@ -71,6 +72,7 @@ static struct {
     { "cpu", LXT_CPU },
     { "datadir", LXT_DATADIR },
     { "debug", LXT_DEBUG },
+    { "every", LXT_EVERY },
     { "if", LXT_IF },
     { "in", LXT_IN },
     { "io", LXT_IO },
@@ -81,6 +83,8 @@ static struct {
     { "pf", LXT_PF },
     { "port", LXT_PORT },
     { "proc", LXT_PROC },
+    { "second", LXT_SECOND },
+    { "seconds", LXT_SECONDS },
     { "sensor", LXT_SENSOR },
     { "source", LXT_SOURCE },
     { "stream", LXT_STREAM },
@@ -91,7 +95,7 @@ static struct {
 #define KW_OPS "{},()"
 
 /* Return the number of the token pointed to by cp or LXT_BADTOKEN */
-int 
+int
 parse_token(const char *cp)
 {
     u_int i;
@@ -115,8 +119,8 @@ parse_opcode(const int op)
     return NULL;
 }
 /* Read a line and increase buffer if needed */
-int 
-lex_readline(struct lex * l)
+int
+lex_readline(struct lex *l)
 {
     char *bp;
 
@@ -129,19 +133,17 @@ lex_readline(struct lex * l)
 	    l->buffer = xrealloc(l->buffer, l->bsize);
 	    bp = l->buffer;
 	    bp += l->endpos;
-	}
-	else {
+	} else {
 	    l->curpos = 0;
 	    l->endpos = 0;
 	}
-    }
-    else {
+    } else {
 	l->bsize = _POSIX2_LINE_MAX;
 	l->buffer = xmalloc(l->bsize);
 	bp = l->buffer;
     }
 
-    if (!fgets(bp, (l->buffer + l->bsize) - bp, l->fh))
+    if (!read(l->fh, bp, (l->buffer + l->bsize) - bp))
 	return 0;
     else {
 	l->endpos += strlen(bp) - 1;
@@ -149,20 +151,20 @@ lex_readline(struct lex * l)
     }
 }
 /* Copy char out of input stream */
-void 
-lex_copychar(struct lex * l)
+void
+lex_copychar(struct lex *l)
 {
     l->token[l->tokpos] = l->buffer[l->curpos];
 
     if (++l->tokpos >= _POSIX2_LINE_MAX) {
 	l->token[_POSIX2_LINE_MAX - 1] = '\0';
-	fatal("%s:%d: parse error at '%s'", l->filename, l->cline, l->token);
+	fatal("%.200s:%d: parse error at '%.200s'", l->filename, l->cline, l->token);
 	/* NOT REACHED */
     }
 }
 /* Get next char, read next line if needed */
-int 
-lex_nextchar(struct lex * l)
+int
+lex_nextchar(struct lex *l)
 {
     l->curpos++;
 
@@ -176,21 +178,21 @@ lex_nextchar(struct lex * l)
     return 1;
 }
 /* Close of current token with a '\0' */
-void 
-lex_termtoken(struct lex * l)
+void
+lex_termtoken(struct lex *l)
 {
     l->token[l->tokpos] = l->token[_POSIX2_LINE_MAX - 1] = '\0';
     l->tokpos = 0;
 }
 /* Unget token; the lexer allows 1 look a head. */
-void 
-lex_ungettoken(struct lex * l)
+void
+lex_ungettoken(struct lex *l)
 {
     l->unget = 1;
 }
 /* Get the next token in lex->token. return 0 if no more tokens found. */
-int 
-lex_nexttoken(struct lex * l)
+int
+lex_nexttoken(struct lex *l)
 {
     /* return same token as last time if it has been pushed back */
     if (l->unget) {
@@ -214,8 +216,7 @@ lex_nexttoken(struct lex * l)
 	    while (l->buffer[l->curpos] != '\n')
 		if (!lex_nextchar(l))
 		    return 0;
-	}
-	else if (!lex_nextchar(l))
+	} else if (!lex_nextchar(l))
 	    return 0;
     }
 
@@ -224,13 +225,13 @@ lex_nexttoken(struct lex * l)
     /* "delimited string" */
     if (l->buffer[l->curpos] == '"') {
 	if (!lex_nextchar(l)) {
-	    warning("%s:%d: unbalanced '\"'", l->filename, l->cline);
+	    warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
 	    return 0;
 	}
 	while (l->buffer[l->curpos] != '"') {
 	    lex_copychar(l);
 	    if (!lex_nextchar(l)) {
-		warning("%s:%d: unbalanced '\"'", l->filename, l->cline);
+		warning("%.200s:%d: unbalanced '\"'", l->filename, l->cline);
 		return 0;
 	    }
 	}
@@ -242,13 +243,13 @@ lex_nexttoken(struct lex * l)
     /* 'delimited string' */
     if (l->buffer[l->curpos] == '\'') {
 	if (!lex_nextchar(l)) {
-	    warning("%s:%d: unbalanced \"\'\"", l->filename, l->cline);
+	    warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
 	    return 0;
 	}
 	while (l->buffer[l->curpos] != '\'') {
 	    lex_copychar(l);
 	    if (!lex_nextchar(l)) {
-		warning("%s:%d: unbalanced \"\'\"", l->filename, l->cline);
+		warning("%.200s:%d: unbalanced \"\'\"", l->filename, l->cline);
 		return 0;
 	    }
 	}
@@ -297,36 +298,55 @@ open_lex(const char *filename)
     struct lex *l;
 
     l = xmalloc(sizeof(struct lex));
+    reset_lex(l);
     l->buffer = NULL;
-    l->cline = 1;
-    l->curpos = 0;
-    l->endpos = 0;
     l->filename = filename;
-    l->op = LXT_BADTOKEN;
     l->token = xmalloc(_POSIX2_LINE_MAX);
-    l->tokpos = 0;
-    l->type = LXY_UNKNOWN;
-    l->unget = 0;
-    l->value = 0;
 
-    if ((l->fh = fopen(l->filename, "r")) == NULL) {
-	warning("could not open file '%s':%s",
+    if ((l->fh = open(l->filename, O_RDONLY)) < 0) {
+	warning("could not open file '%.200s':%.200s",
 		l->filename, strerror(errno));
-	xfree(l);
+	close_lex(l);
 	return NULL;
     }
 
     lex_readline(l);
     return l;
 }
+/* Prepare file for another lexer run */
+void
+rewind_lex(struct lex *l)
+{
+    off_t filepos;
+
+    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));
+    }
+}
+/* Reset lexer to start of file defaults */
+void
+reset_lex(struct lex *l)
+{
+    l->cline = 1;
+    l->curpos = 0;
+    l->endpos = 0;
+    l->op = LXT_BADTOKEN;
+    l->tokpos = 0;
+    l->type = LXY_UNKNOWN;
+    l->unget = 0;
+    l->value = 0;
+}
 /* Destroy a lexical analyser */
-void 
-close_lex(struct lex * l)
+void
+close_lex(struct lex *l)
 {
     if (l == NULL)
 	return;
     if (l->fh)
-	fclose(l->fh);
+	close(l->fh);
     if (l->buffer)
 	xfree(l->buffer);
     if (l->token)
@@ -334,9 +354,9 @@ close_lex(struct lex * l)
     xfree(l);
 }
 /* Signal a parse error */
-void 
-parse_error(struct lex * l, const char *s)
+void
+parse_error(struct lex *l, const char *s)
 {
-    warning("%s:%d: expected %s (found '%.8s')",
+    warning("%.200s:%d: expected '%.200s' found '%.8s')",
 	    l->filename, l->cline, s, l->token);
 }

+ 28 - 23
symon/lib/lex.h

@@ -1,4 +1,4 @@
-/* $Id: lex.h,v 1.17 2003/10/10 15:19:49 dijkstra Exp $ */
+/* $Id: lex.h,v 1.18 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2003 Willem Dijkstra
@@ -42,7 +42,7 @@
 
 #include <stdio.h>
 
-/* Tokens known to lex. */
+/* Tokens known to lex */
 #define LXT_BADTOKEN   0
 #define LXT_ACCEPT     1
 #define LXT_BEGIN      2
@@ -52,27 +52,30 @@
 #define LXT_DATADIR    6
 #define LXT_DEBUG      7
 #define LXT_END        8
-#define LXT_IF         9
-#define LXT_IN        10
-#define LXT_IO        11
-#define LXT_MEM       12
-#define LXT_MONITOR   13
-#define LXT_MUX       14
-#define LXT_OPEN      15
-#define LXT_PF        16
-#define LXT_PORT      17
-#define LXT_PROC      18
-#define LXT_SENSOR    19
-#define LXT_SOURCE    20
-#define LXT_STREAM    21
-#define LXT_TO        22
-#define LXT_WRITE     23
-#define LXT_MBUF      24
+#define LXT_EVERY      9
+#define LXT_IF        10
+#define LXT_IN        11
+#define LXT_IO        12
+#define LXT_MEM       13
+#define LXT_MONITOR   14
+#define LXT_MUX       15
+#define LXT_OPEN      16
+#define LXT_PF        17
+#define LXT_PORT      18
+#define LXT_PROC      19
+#define LXT_SECOND    20
+#define LXT_SECONDS   21
+#define LXT_SENSOR    22
+#define LXT_SOURCE    23
+#define LXT_STREAM    24
+#define LXT_TO        25
+#define LXT_WRITE     26
+#define LXT_MBUF      27
 
 struct lex {
     char *buffer;		/* current line(s) */
     const char *filename;
-    FILE *fh;
+    int fh;
     char *token;		/* last token seen */
     long value;			/* value of last token seen, if num */
     int bsize;			/* size of buffer  */
@@ -85,17 +88,19 @@ struct lex {
     enum {
 	LXY_STRING, LXY_NUMBER, LXY_UNKNOWN
     }
-         type;			/* type of token in buffer */
+	 type;			/* type of token in buffer */
 };
 
 __BEGIN_DECLS
+const char *parse_opcode(int);
+int lex_nexttoken(struct lex *);
+int parse_token(const char *);
 struct lex *open_lex(const char *);
 void close_lex(struct lex *);
-int lex_nexttoken(struct lex *);
 void lex_ungettoken(struct lex *);
-const char *parse_opcode(int);
-int parse_token(const char *);
 void parse_error(struct lex *, const char *);
+void reset_lex(struct lex *);
+void rewind_lex(struct lex *);
 __END_DECLS
 
 /* EXPECT(l,x) = next token in l must be opcode x or error.  */

+ 29 - 20
symon/lib/net.c

@@ -1,7 +1,7 @@
-/* $Id: net.c,v 1.7 2002/11/29 10:45:20 dijkstra Exp $ */
+/* $Id: net.c,v 1.9 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,8 +49,9 @@
  * aslo filled with sockaddr information that was obtained.
  */
 char res_host[NI_MAXHOST];
+char res_service[NI_MAXSERV];
 struct sockaddr_storage res_addr;
-int 
+int
 getip(char *name)
 {
     struct addrinfo hints, *res;
@@ -77,8 +78,7 @@ getip(char *name)
 
 	freeaddrinfo(res);
 	return 1;
-    }
-    else {
+    } else {
 	if (res->ai_addr) {
 	    if ((error = getnameinfo(res->ai_addr, res->ai_addrlen,
 				     res_host, NI_MAXHOST,
@@ -89,12 +89,10 @@ getip(char *name)
 
 		freeaddrinfo(res);
 		return 1;
-	    }
-	    else
+	    } else
 		warning("getnameinfo(%.200s): %.200s", name, gai_strerror(error));
-	}
-	else
-	    warning("getip(%s): could not get numeric host via getaddrinfo nor getnameinfo", name);
+	} else
+	    warning("getip(%.200s): could not get numeric host via getaddrinfo nor getnameinfo", name);
     }
 
     return 0;
@@ -105,7 +103,7 @@ getip(char *name)
  * getaddr returns a sockaddr structure in res_addr. it will only resolve
  * the address if that is necessary.
  */
-int 
+int
 getaddr(char *name, char *service, int socktype, int flags)
 {
     struct addrinfo hints, *res;
@@ -135,7 +133,18 @@ getaddr(char *name, char *service, int socktype, int flags)
 
     return 1;
 }
-void 
+int
+get_numeric_name(struct sockaddr_storage * source)
+{
+    snprintf(res_host, sizeof(res_host), "<unknown>");
+    snprintf(res_service, sizeof(res_service), "<unknown>");
+
+    return getnameinfo((struct sockaddr *)source, source->ss_len,
+		       res_host, sizeof(res_host),
+		       res_service, sizeof(res_service),
+		       NI_NUMERICHOST | NI_NUMERICSERV);
+}
+void
 cpysock(struct sockaddr * source, struct sockaddr_storage * dest)
 {
     bzero(dest, sizeof(struct sockaddr_storage));
@@ -146,7 +155,7 @@ cpysock(struct sockaddr * source, struct sockaddr_storage * dest)
  *
  * compare if two sockaddr are talking about the same host
  */
-int 
+int
 cmpsock_addr(struct sockaddr * first, struct sockaddr * second)
 {
 
@@ -180,7 +189,7 @@ cmpsock_addr(struct sockaddr * first, struct sockaddr * second)
     return 0;
 }
 /* generate INADDR_ANY info */
-void 
+void
 get_inaddrany_sockaddr(struct sockaddr_storage * sockaddr, int family, int socktype, char *port)
 {
     struct addrinfo hints, *res;
@@ -197,22 +206,22 @@ get_inaddrany_sockaddr(struct sockaddr_storage * sockaddr, int family, int sockt
     }
 }
 /* fill a source->sockaddr with a sockaddr for use in address compares */
-void 
+void
 get_source_sockaddr(struct source * source)
 {
     if (!getip(source->addr))
-	fatal("could not get address information for %s",
+	fatal("could not get address information for %.200s",
 	      source->addr);
 
-    cpysock((struct sockaddr *) & res_addr, &source->sockaddr);
+    cpysock((struct sockaddr *) &res_addr, &source->sockaddr);
 }
 /* fill mux->sockaddr with a udp listen sockaddr */
-void 
+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 %s %s",
+	fatal("could not get address information for %.200s %.200s",
 	      mux->addr, mux->port);
 
-    cpysock((struct sockaddr *) & res_addr, &mux->sockaddr);
+    cpysock((struct sockaddr *) &res_addr, &mux->sockaddr);
 }

+ 4 - 6
symon/lib/net.h

@@ -1,7 +1,7 @@
-/* $Id: net.h,v 1.9 2002/11/29 10:45:20 dijkstra Exp $ */
+/* $Id: net.h,v 1.11 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,14 +39,13 @@
 
 #define SYMUX_PORT  "2100"	/* default symux port */
 
-extern char lookup_hostname[];
-extern char lookup_address[];
-extern u_int32_t lookup_ip;
 extern char res_host[];
+extern char res_service[];
 extern struct sockaddr_storage res_addr;
 
 __BEGIN_DECLS
 int cmpsock_addr(struct sockaddr *, struct sockaddr *);
+int get_numeric_name(struct sockaddr_storage *);
 int getaddr(char *, char *, int, int);
 int getip(char *);
 int lookup(char *);
@@ -57,4 +56,3 @@ void get_source_sockaddr(struct source *);
 __END_DECLS
 
 #endif				/* _SYMON_LIB_NET_H */
-

+ 2 - 2
symon/lib/xmalloc.c

@@ -1,4 +1,4 @@
-/* $Id: xmalloc.c,v 1.5 2002/11/29 10:50:29 dijkstra Exp $ */
+/* $Id: xmalloc.c,v 1.6 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -55,7 +55,7 @@ xrealloc(void *ptr, size_t new_size)
     return new_ptr;
 }
 
-void 
+void
 xfree(void *ptr)
 {
     if (ptr == NULL)

+ 8 - 8
symon/ports/symon/Makefile

@@ -1,11 +1,11 @@
 # $OpenBSD: Makefile,v 1.7 2003/03/31 22:13:51 dhartmei Exp $
 
 COMMENT=		"active monitoring tool"
-V=			2.62
+V=			2.63
 DISTNAME=		symon-${V}
 CATEGORIES=		sysutils net
 
-HOMEPAGE=		http://www.xs4all.nl/~wpd/symon.new/philes
+HOMEPAGE=		http://www.xs4all.nl/~wpd/symon
 MAINTAINER=		Willem Dijkstra <wpd@xs4all.nl>
 
 # BSD
@@ -14,7 +14,7 @@ PERMIT_PACKAGE_FTP=	Yes
 PERMIT_DISTFILES_CDROM=	Yes
 PERMIT_DISTFILES_FTP=	Yes
 
-MASTER_SITES=		${HOMEPAGE}
+MASTER_SITES=		${HOMEPAGE}/philes/
 
 SUBPACKAGE?=
 
@@ -22,12 +22,12 @@ SUBPACKAGE?=
 MULTI_PACKAGES+=	-mon
 COMMENT-mon=		"active host monitor"
 MON_LIBDEPENDS=
-MON_RUNDEPENDS=		
+MON_RUNDEPENDS=
 # gatherer only package
 MULTI_PACKAGES+=	-mux
 COMMENT-mux=		"symon data gatherer"
-MUX_LIBDEPENDS=		rrd:rrdtool-*:net/rrdtool 
-MUX_RUNDEPENDS=		rrd:rrdtool-*:net/rrdtool 
+MUX_LIBDEPENDS=		rrd:rrdtool-*:net/rrdtool
+MUX_RUNDEPENDS=		rrd:rrdtool-*:net/rrdtool
 
 .for i in ${MULTI_PACKAGES}
 FULLPKGNAME${i}=        symon${i}-${V}
@@ -39,9 +39,9 @@ LIB_DEPENDS=            ${${MODULE_NAME:U}_LIBDEPENDS}
 RUN_DEPENDS=		${${MODULE_NAME:U}_RUNDEPENDS}
 MESSAGE=                ${PKGDIR}/MESSAGE${SUBPACKAGE}
 .else
-BUILD_DEPENDS=		rrd:rrdtool-*:net/rrdtool 
+BUILD_DEPENDS=		rrd:rrdtool-*:net/rrdtool
 RUN_DEPENDS=		rrd:rrdtool-*:net/rrdtool
-LIB_DEPENDS=		rrd:rrdtool-*:net/rrdtool 
+LIB_DEPENDS=		rrd:rrdtool-*:net/rrdtool
 .endif
 
 WRKDIST=		${WRKDIR}/symon

+ 4 - 0
symon/ports/symon/pkg/DEINSTALL

@@ -7,6 +7,8 @@ set -e
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 PREFIX=${PKG_PREFIX:-/usr/local}
 CONFIG_FILE=${SYSCONFDIR}/symon.conf
+SYMONUSER=_symon
+SYMONGROUP=_symon
 
 if [ -e $CONFIG_FILE ]; then
     echo
@@ -14,6 +16,8 @@ if [ -e $CONFIG_FILE ]; then
     echo "| To completely deinstall the $1 package you need to perform"
     echo "| this step as root:"
     echo "|"
+    echo "|           userdel $SYMONUSER"
+    echo "|           groupdel $SYMONGROUP"
     echo "|           rm -f $CONFIG_FILE"
     echo "|"
     echo "| Do not do this if you plan on re-installing $1"

+ 4 - 0
symon/ports/symon/pkg/DEINSTALL-mon

@@ -7,6 +7,8 @@ set -e
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 PREFIX=${PKG_PREFIX:-/usr/local}
 CONFIG_FILE=${SYSCONFDIR}/symon.conf
+SYMONUSER=_symon
+SYMONGROUP=_symon
 
 if [ -e $CONFIG_FILE ]; then
     echo
@@ -14,6 +16,8 @@ if [ -e $CONFIG_FILE ]; then
     echo "| To completely deinstall the $1 package you need to perform"
     echo "| this step as root:"
     echo "|"
+    echo "|           userdel $SYMONUSER"
+    echo "|           groupdel $SYMONGROUP"
     echo "|           rm -f $CONFIG_FILE"
     echo "|"
     echo "| Do not do this if you plan on re-installing $1"

+ 3 - 3
symon/ports/symon/pkg/DESCR

@@ -2,8 +2,8 @@ symon is a lightweight system monitor that measures cpu, memory,
 interface and disk statistics every 5 seconds. This information is
 then spooled over "the network" to symux for further processing.
 
-The port will yield 4 packages: 
-symon-mon-${V}.tgz : symon daemon and manual
-symon-mux-${V}.tgz : symux daemon, manual and auxiliary scripts
+The port will yield 3 packages:
+symon-mon-${V}.tgz : symon daemon and manual.
+symon-mux-${V}.tgz : symux daemon, manual and rrd creation script.
 symon-${V}.tgz     : all of the above rolled into a single package
 

+ 28 - 9
symon/ports/symon/pkg/INSTALL

@@ -9,7 +9,27 @@ set -e
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 PREFIX=${PKG_PREFIX:-/usr/local}
 CONFIG_FILE=${SYSCONFDIR}/symon.conf
-SAMPLE_CONFIG_FILE=$PREFIX/share/symon/symon.conf
+SAMPLE_CONFIG_FILE=$PREFIX/share/examples/symon/symon.conf
+SYMONUSER=_symon
+SYMONGROUP=_symon
+ID=525
+
+do_usergroup_install()
+{
+  # Create symon user and group
+  if groupinfo -e $SYMONGROUP; then
+    echo "===> Using $SYMONGROUP group for symon"
+  else
+    echo "===> Creating $SYMONGROUP group for symon"
+    groupadd -g $ID $SYMONGROUP
+  fi
+  if userinfo -e $SYMONUSER; then
+    echo "===> Using $SYMONUSER user for symon"
+  else
+    echo "===> Creating $SYMONUSER user for symon"
+    useradd -g $SYMONGROUP -d /var/empty -L daemon -c 'symon Account' -s /sbin/nologin -u $ID $SYMONUSER
+  fi
+}
 
 do_notice()
 {
@@ -34,7 +54,7 @@ do_install()
     echo "| pf, default disks and interfaces. Please review this file and change"
     echo "| the configuration to suit your needs."
     echo "+---------------"
-    echo 
+    echo
 }
 
 # verify proper execution
@@ -48,20 +68,19 @@ fi
 #
 case $2 in
     PRE-INSTALL)
-        : nothing to pre-install for this port
-        ;;
+	do_usergroup_install
+	;;
     POST-INSTALL)
 	if [ -f $CONFIG_FILE ]; then
 	    do_notice $1
 	else
 	    do_install $1
 	fi
-        ;;
+	;;
     *)
-        echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
-        exit 1
-        ;;
+	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
+	exit 1
+	;;
 esac
 
 exit 0
-

+ 29 - 9
symon/ports/symon/pkg/INSTALL-mon

@@ -9,7 +9,27 @@ set -e
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 PREFIX=${PKG_PREFIX:-/usr/local}
 CONFIG_FILE=${SYSCONFDIR}/symon.conf
-SAMPLE_CONFIG_FILE=$PREFIX/share/symon/symon.conf
+SAMPLE_CONFIG_FILE=$PREFIX/share/examples/symon/symon.conf
+SYMONUSER=_symon
+SYMONGROUP=_symon
+ID=525
+
+do_usergroup_install()
+{
+  # Create symon user and group
+  if groupinfo -e $SYMONGROUP; then
+    echo "===> Using $SYMONGROUP group for symon"
+  else
+    echo "===> Creating $SYMONGROUP group for symon"
+    groupadd -g $ID $SYMONGROUP
+  fi
+  if userinfo -e $SYMONUSER; then
+    echo "===> Using $SYMONUSER user for symon"
+  else
+    echo "===> Creating $SYMONUSER user for symon"
+    useradd -g $SYMONGROUP -d /var/empty -L daemon -c 'symon Account' -s /sbin/nologin -u $ID $SYMONUSER
+  fi
+}
 
 do_notice()
 {
@@ -34,7 +54,7 @@ do_install()
     echo "| pf, default disks and interfaces. Please review this file and change"
     echo "| the configuration to suit your needs."
     echo "+---------------"
-    echo 
+    echo
 }
 
 # verify proper execution
@@ -48,20 +68,20 @@ fi
 #
 case $2 in
     PRE-INSTALL)
-        : nothing to pre-install for this port
-        ;;
+	do_usergroup_install
+	;;
     POST-INSTALL)
 	if [ -f $CONFIG_FILE ]; then
 	    do_notice $1
 	else
 	    do_install $1
 	fi
-        ;;
+	;;
     *)
-        echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
-        exit 1
-        ;;
+	echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
+	exit 1
+	;;
 esac
 
 exit 0
-
+set -e

+ 1 - 1
symon/ports/symon/pkg/MESSAGE

@@ -1,6 +1,6 @@
 +---------------
 | Example configurations for both symon and symux have been installed
-| in ${PREFIX}/share/symon.
+| in ${PREFIX}/share/examples/symon.
 |
 | RRD files can be obtained by running
 | ${PREFIX}/share/symon/c_smrrds.sh

+ 1 - 1
symon/ports/symon/pkg/MESSAGE-mon

@@ -1,4 +1,4 @@
 +---------------
 | An example configuration for symon has been installed in
-| ${PREFIX}/share/symon.
+| ${PREFIX}/share/examples/symon.
 +---------------

+ 1 - 1
symon/ports/symon/pkg/MESSAGE-mux

@@ -1,6 +1,6 @@
 +---------------
 | An example configuration for symux has been installed in
-| ${PREFIX}/share/symon.
+| ${PREFIX}/share/examples/symon.
 |
 | RRD files can be obtained by running
 | ${PREFIX}/share/symon/c_smrrds.sh

+ 2 - 0
symon/ports/symon/pkg/PLIST

@@ -7,8 +7,10 @@ man/cat8/symux.0
 share/examples/symon/symon.conf
 share/examples/symon/symux.conf
 share/symon/c_smrrds.sh
+share/symon/c_config.sh
 share/symon/client/getsymonitem.pl
 share/symon/client/SymuxClient.pm
 share/symon/client/SymuxClient.0
+@dirrm share/examples/symon
 @dirrm share/symon/client
 @dirrm share/symon

+ 1 - 0
symon/ports/symon/pkg/PLIST-mon

@@ -4,4 +4,5 @@ libexec/symon
 man/cat8/symon.0
 share/examples/symon/symon.conf
 share/symon/c_config.sh
+@dirrm share/examples/symon
 @dirrm share/symon

+ 1 - 0
symon/ports/symon/pkg/PLIST-mux

@@ -7,5 +7,6 @@ share/examples/symon/symux.conf
 share/symon/client/getsymonitem.pl
 share/symon/client/SymuxClient.pm
 share/symon/client/SymuxClient.0
+@dirrm share/examples/symon
 @dirrm share/symon/client
 @dirrm share/symon

+ 3 - 3
symon/symon/Makefile

@@ -1,8 +1,8 @@
-# $Id: Makefile,v 1.32 2003/10/12 17:26:09 dijkstra Exp $
+# $Id: Makefile,v 1.34 2003/12/21 13:01:05 dijkstra Exp $
 .include "../Makefile.inc"
 
 LIBS=	-L../lib -lsymon
-SRCS=	symon.c sm_cpu.c sm_debug.c sm_mem.c sm_if.c sm_io.c sm_pf.c sm_mbuf.c sm_proc.c sm_sensor.c readconf.c symonnet.c 
+SRCS=	symon.c sm_cpu.c sm_debug.c sm_mem.c sm_if.c sm_io.c sm_pf.c sm_mbuf.c sm_proc.c sm_sensor.c readconf.c symonnet.c
 OBJS+=	${SRCS:R:S/$/.o/g}
 CFLAGS+=-I../lib -I.
 
@@ -15,7 +15,7 @@ symon: ${OBJS}
 .endif
 
 clean:
-	rm -f conf.h symon symon.cat8 ${OBJS}
+	rm -f conf.h symon symon.cat8 symon.core ${OBJS}
 
 install: symon symon.cat8 symon.conf
 	${INSTALL} -c -m 555  -g wheel -o root symon      ${PREFIX}/${BINDIR}

+ 6 - 7
symon/symon/c_config.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# $Id: c_config.sh,v 1.4 2003/06/20 08:41:19 dijkstra Exp $
+# $Id: c_config.sh,v 1.5 2003/12/20 16:30:44 dijkstra Exp $
 #
 # Create an example configuration file for symon on a host and print to stdout
 
@@ -31,11 +31,10 @@ host=${1:-127.0.0.1}
 port=${2:-2100}
 cat <<EOF
 #
-# symon configuration generated by  
-# `basename $0` $1 $2 
+# symon configuration generated by
+# `basename $0` $1 $2
 #
-monitor { $if 
-          $io 
-          cpu(0), mem } stream to $host $port
+monitor { $if
+	  $io
+	  cpu(0), mem } stream to $host $port
 EOF
-

+ 50 - 21
symon/symon/readconf.c

@@ -1,7 +1,7 @@
-/* $Id: readconf.c,v 1.15 2003/10/10 15:20:01 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.17 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,14 +50,14 @@ __END_DECLS
 const char *default_symux_port = SYMUX_PORT;
 
 /* <hostname> (port|:|,| ) <number> */
-int 
+int
 read_host_port(struct muxlist * mul, struct mux * mux, struct lex * l)
 {
     char muxname[_POSIX2_LINE_MAX];
 
     lex_nexttoken(l);
     if (!getip(l->token)) {
-	warning("%s:%d: could not resolve '%s'",
+	warning("%.200s:%d: could not resolve '%.200s'",
 		l->filename, l->cline, l->token);
 	return 0;
     }
@@ -74,15 +74,14 @@ read_host_port(struct muxlist * mul, struct mux * mux, struct lex * l)
     if (l->type != LXY_NUMBER) {
 	lex_ungettoken(l);
 	mux->port = xstrdup(default_symux_port);
-    }
-    else {
+    } else {
 	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("%s:%d: monitored data for host '%s' has already been specified",
+	warning("%.200s:%d: monitored data for host '%.200s' has already been specified",
 		l->filename, l->cline, muxname);
 	return 0;
     }
@@ -90,7 +89,7 @@ read_host_port(struct muxlist * mul, struct mux * mux, struct lex * l)
     return 1;
 }
 /* parse "<cpu(arg)|mem|if(arg)|io(arg)|debug|pf|proc(arg)>", end condition == "}" */
-int 
+int
 read_symon_args(struct mux * mux, struct lex * l)
 {
     char sn[_POSIX2_LINE_MAX];
@@ -126,14 +125,13 @@ read_symon_args(struct mux * mux, struct lex * l)
 		    parse_error(l, ")");
 		    return 0;
 		}
-	    }
-	    else {
+	    } else {
 		lex_ungettoken(l);
 		sa[0] = '\0';
 	    }
 
 	    if ((add_mux_stream(mux, st, sa)) == NULL) {
-		warning("%s:%d: stream %s(%s) redefined",
+		warning("%.200s:%d: stream %.200s(%.200s) redefined",
 			l->filename, l->cline, sn, sa);
 		return 0;
 	    }
@@ -152,38 +150,64 @@ read_symon_args(struct mux * mux, struct lex * l)
 }
 
 /* parse monitor <args> stream [to] <host>:<port> */
-int 
+int
 read_monitor(struct muxlist * mul, struct lex * l)
 {
     struct mux *mux;
 
     mux = add_mux(mul, SYMON_UNKMUX);
 
-    /* parse cpu|mem|if|io */
+    /* parse [stream(streamarg)]+ */
     if (!read_symon_args(mux, l))
 	return 0;
 
-    /* parse stream to */
-    EXPECT(l, LXT_STREAM);
     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);
+    }
+
+    /* parse [stream to] */
+    if (l->op != LXT_STREAM) {
+	parse_error(l, "stream");
+	return 0;
+    }
+
+    lex_nexttoken(l);
+
     if (l->op != LXT_TO)
 	lex_ungettoken(l);
 
-    /* parse host */
+    /* parse [host [port]?] */
     return read_host_port(mul, mux, l);
 }
 
 /* Read symon.conf */
-int 
-read_config_file(struct muxlist * muxlist, const char *filename)
+int
+read_config_file(struct muxlist *muxlist, char *filename)
 {
     struct lex *l;
     struct mux *mux;
 
     SLIST_INIT(muxlist);
 
-    if ((l = open_lex(filename)) == NULL)
-	return 0;
+    l = open_lex(filename);
 
     while (lex_nexttoken(l)) {
 	/* expecting keyword now */
@@ -206,12 +230,17 @@ read_config_file(struct muxlist * muxlist, const char *filename)
 	    return 0;
 	}
 	if (SLIST_EMPTY(&mux->sl)) {
-	    warning("%s: no monitors selected for mux '%s'",
+	    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);
+    }
+
     close_lex(l);
+
     return 1;
 }

+ 3 - 3
symon/symon/readconf.h

@@ -1,7 +1,7 @@
-/* $Id: readconf.h,v 1.5 2002/11/29 10:48:53 dijkstra Exp $ */
+/* $Id: readconf.h,v 1.6 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -36,6 +36,6 @@
 #include "data.h"
 
 __BEGIN_DECLS
-int read_config_file(struct muxlist *, const char *);
+int read_config_file(struct muxlist *, char *);
 __END_DECLS
 #endif				/* _SYMON_READCONF_H */

+ 8 - 7
symon/symon/sm_cpu.c

@@ -1,11 +1,11 @@
-/* $Id: sm_cpu.c,v 1.15 2003/10/10 15:20:01 dijkstra Exp $ */
+/* $Id: sm_cpu.c,v 1.16 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /* The author of this code is Willem Dijkstra (wpd@xs4all.nl).
  *
  * The percentages function was written by William LeFebvre and is part of the
  * 'top' utility. His copyright statement is below.
  *
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,8 @@
  * 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.
- *  */
+ *
+ */
 
 /*
  *  Top users/processes display for Unix
@@ -80,7 +81,7 @@ static int cp_states[CPUSTATES];
  *      The routine assumes modulo arithmetic.  This function is especially
  *      useful on BSD mchines for calculating cpu state percentages.
  */
-int 
+int
 percentages(int cnt, int *out, register long *new, register long *old, long *diffs)
 {
     register int i;
@@ -116,7 +117,7 @@ percentages(int cnt, int *out, register long *new, register long *old, long *dif
     return total_change;
 }
 /* Prepare cpu module for use */
-void 
+void
 init_cpu(char *s)
 {
     char buf[_POSIX2_LINE_MAX];
@@ -125,10 +126,10 @@ init_cpu(char *s)
     /* Call get_cpu once to fill the cp_old structure */
     get_cpu(buf, sizeof(buf), NULL);
 
-    info("started module cpu(%s)", s);
+    info("started module cpu(%.200s)", s);
 }
 /* Get new cpu measurements */
-int 
+int
 get_cpu(char *symon_buf, int maxlen, char *s)
 {
     int total;

+ 5 - 5
symon/symon/sm_debug.c

@@ -1,7 +1,7 @@
-/* $Id: sm_debug.c,v 1.2 2002/12/15 14:22:36 dijkstra Exp $ */
+/* $Id: sm_debug.c,v 1.3 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,13 +51,13 @@
 static int db_mib[] = {CTL_DEBUG, 0, CTL_DEBUG_VALUE};
 static int db_v[SYMON_MAXDEBUGID];
 /* Prepare if module for first use */
-void 
+void
 init_debug(char *s)
 {
-    info("started module debug(%s)", s);
+    info("started module debug(%.200s)", s);
 }
 /* Get debug statistics */
-int 
+int
 get_debug(char *symon_buf, int maxlen, char *s)
 {
     size_t len;

+ 6 - 6
symon/symon/sm_if.c

@@ -1,7 +1,7 @@
-/* $Id: sm_if.c,v 1.8 2002/12/15 14:22:36 dijkstra Exp $ */
+/* $Id: sm_if.c,v 1.9 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,7 @@
 /* Globals for this module start with if_ */
 static int if_s = -1;
 /* Prepare if module for first use */
-void 
+void
 init_if(char *s)
 {
     if (if_s == -1)
@@ -73,10 +73,10 @@ init_if(char *s)
 	    fatal("%s:%d: socket failed, %.200",
 		  __FILE__, __LINE__, strerror(errno));
 
-    info("started module if(%s)", s);
+    info("started module if(%.200s)", s);
 }
 /* Get interface statistics */
-int 
+int
 get_if(char *symon_buf, int maxlen, char *interface)
 {
     struct ifreq ifr;
@@ -87,7 +87,7 @@ get_if(char *symon_buf, int maxlen, char *interface)
     ifr.ifr_data = (caddr_t) & ifdata;
 
     if (ioctl(if_s, SIOCGIFDATA, &ifr)) {
-	warning("if(%s) failed (ioctl error)", interface);
+	warning("if(%.200s) failed (ioctl error)", interface);
 	return 0;
     }
 

+ 7 - 7
symon/symon/sm_io.c

@@ -1,7 +1,7 @@
-/* $Id: sm_io.c,v 1.12 2003/06/20 08:41:19 dijkstra Exp $ */
+/* $Id: sm_io.c,v 1.13 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@ static int io_dks = 0;
 static int io_maxdks = 0;
 static size_t io_maxstr = 0;
 
-void 
+void
 gets_io()
 {
     int mib[3];
@@ -122,7 +122,7 @@ gets_io()
 
     p = io_dkstr;
     io_dks = 0;
-    
+
     io_dknames[io_dks] = p;
 
     while ((*p != '\0') && ((p - io_dkstr) < io_maxstr)) {
@@ -135,13 +135,13 @@ gets_io()
     }
 }
 /* Prepare io module for first use */
-void 
+void
 init_io(char *s)
 {
-    info("started module io(%s)", s);
+    info("started module io(%.200s)", s);
 }
 /* Get new io statistics */
-int 
+int
 get_io(char *symon_buf, int maxlen, char *disk)
 {
     int i;

+ 17 - 17
symon/symon/sm_mbuf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_mbuf.c,v 1.2 2003/10/12 17:26:09 dijkstra Exp $ */
+/* $Id: sm_mbuf.c,v 1.3 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2003 Daniel Hartmeier
@@ -44,26 +44,26 @@
 #include "symon.h"
 
 #ifndef HAS_KERN_MBSTAT
-void 
+void
 init_mbuf(char *s)
 {
     fatal("mbuf module requires system upgrade (sysctl.h/KERN_MBSTAT)");
 }
-int 
+int
 get_mbuf(char *symon_buf, int maxlen, char *arg)
 {
     fatal("mbuf module requires system upgrade (sysctl.h/KERN_MBSTAT)");
 }
 #else
 /* Prepare if module for first use */
-void 
+void
 init_mbuf(char *s)
 {
-    info("started module mbuf(%s)", s);
+    info("started module mbuf(%.200s)", s);
 }
 
 /* Get mbuf statistics */
-int 
+int
 get_mbuf(char *symon_buf, int maxlen, char *arg)
 {
     struct mbstat mbstat;
@@ -78,24 +78,24 @@ get_mbuf(char *symon_buf, int maxlen, char *arg)
     int page_size = getpagesize();
     int totmem, totused, totmbufs, totpct;
     u_int32_t stats[15];
-    
+
     mib[0] = CTL_KERN;
     mib[1] = KERN_MBSTAT;
     size = sizeof(mbstat);
     if (sysctl(mib, 2, &mbstat, &size, NULL, 0) < 0) {
-	warning("mbuf(%s) failed (sysctl() %s)", arg, strerror(errno));
+	warning("mbuf(%.200s) failed (sysctl() %.200s)", arg, strerror(errno));
 	return (0);
     }
-    
+
     mib[0] = CTL_KERN;
     mib[1] = KERN_POOL;
     mib[2] = KERN_POOL_NPOOLS;
     size = sizeof(npools);
     if (sysctl(mib, 3, &npools, &size, NULL, 0) < 0) {
-	warning("mbuf(%s) failed (sysctl() %s)", arg, strerror(errno));
+	warning("mbuf(%.200s) failed (sysctl() %.200s)", arg, strerror(errno));
 	return (0);
     }
-    
+
     for (i = 1; npools; ++i) {
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_POOL;
@@ -103,14 +103,14 @@ get_mbuf(char *symon_buf, int maxlen, char *arg)
 	mib[3] = i;
 	size = sizeof(pool);
 	if (sysctl(mib, 4, &pool, &size, NULL, 0) < 0) {
-	    warning("mbuf(%s) failed (sysctl() %s)", arg, strerror(errno));
+	    warning("mbuf(%.200s) failed (sysctl() %.200s)", 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(%s) failed (sysctl() %s)", arg, strerror(errno));
+	    warning("mbuf(%.200s) failed (sysctl() %.200s)", arg, strerror(errno));
 	    return (0);
 	}
 	if (!strcmp(name, "mbpl")) {
@@ -124,10 +124,10 @@ get_mbuf(char *symon_buf, int maxlen, char *arg)
 	    break;
     }
     if (flag != 3) {
-	warning("mbuf(%s) failed (flag != 3)", arg);
+	warning("mbuf(%.200s) failed (flag != 3)", arg);
 	return (0);
     }
-    
+
     totmbufs = 0;
     for (i = 0; i < nmbtypes; ++i)
 	totmbufs += mbstat.m_mtypes[i];
@@ -135,7 +135,7 @@ get_mbuf(char *symon_buf, int maxlen, char *arg)
     totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
 	(mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
     totpct = (totmem == 0) ? 0 : ((totused * 100) / totmem);
-    
+
     stats[0] = totmbufs;
     stats[1] = mbstat.m_mtypes[MT_DATA];
     stats[2] = mbstat.m_mtypes[MT_OOBDATA];
@@ -151,7 +151,7 @@ get_mbuf(char *symon_buf, int maxlen, char *arg)
     stats[12] = mbstat.m_drops;
     stats[13] = mbstat.m_wait;
     stats[14] = mbstat.m_drain;
-    
+
     return snpack(symon_buf, maxlen, arg, MT_MBUF,
 		  stats[0],
 		  stats[1],

+ 5 - 5
symon/symon/sm_mem.c

@@ -1,7 +1,7 @@
-/* $Id: sm_mem.c,v 1.13 2002/11/29 10:48:53 dijkstra Exp $ */
+/* $Id: sm_mem.c,v 1.14 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -64,7 +64,7 @@ static int me_pagesize;
 static int me_nswap;
 struct swapent *me_swdev = NULL;
 /* Prepare mem module for first use */
-void 
+void
 init_mem(char *s)
 {
     me_pagesize = sysconf(_SC_PAGESIZE);
@@ -91,10 +91,10 @@ init_mem(char *s)
     if (me_swdev == NULL && me_nswap != 0)
 	me_nswap = 0;
 
-    info("started module mem(%s)", s);
+    info("started module mem(%.200s)", s);
 }
 /* Get memory statistics */
-int 
+int
 get_mem(char *symon_buf, int maxlen, char *s)
 {
     int i, rnswap;

+ 15 - 11
symon/symon/sm_pf.c

@@ -1,4 +1,4 @@
-/* $Id: sm_pf.c,v 1.5 2003/01/26 20:41:00 dijkstra Exp $ */
+/* $Id: sm_pf.c,v 1.7 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2002 Daniel Hartmeier
@@ -57,33 +57,37 @@
 #include "symon.h"
 
 /* Globals for this module start with pf_ */
-static int pf_dev = -1;
-
+int pf_dev = -1;
+/* Priviledged init, called before priviledges are dropped */
+void
+privinit_pf()
+{
+    if ((pf_dev = open("/dev/pf", O_RDONLY)) == -1)
+	warning("could not open \"/dev/pf\", %.200s", strerror(errno));
+}
 /* Prepare if module for first use */
-void 
+void
 init_pf(char *s)
 {
     if (pf_dev == -1)
-	if ((pf_dev = open("/dev/pf", O_RDWR)) == -1)
-	    fatal("%s:%d: open(\"/dev/pf\") failed, %.200s",
-		  __FILE__, __LINE__, strerror(errno));
+	privinit_pf();
 
-    info("started module pf(%s)", s);
+    info("started module pf(%.200s)", s);
 }
 /* Get pf statistics */
-int 
+int
 get_pf(char *symon_buf, int maxlen, char *arg)
 {
     struct pf_status s;
     u_int64_t n;
 
     if (pf_dev == -1) {
-	warning("pf(%s) failed (dev == -1)", arg);
+	warning("pf(%.200s) failed (dev == -1)", arg);
 	return 0;
     }
 
     if (ioctl(pf_dev, DIOCGETSTATUS, &s)) {
-	warning("pf(%s) failed (ioctl error)", arg);
+	warning("pf(%.200s) failed (ioctl error)", arg);
 	return 0;
     }
 

+ 18 - 18
symon/symon/sm_proc.c

@@ -1,7 +1,7 @@
-/* $Id: sm_proc.c,v 1.2 2002/12/15 15:00:01 dijkstra Exp $ */
+/* $Id: sm_proc.c,v 1.3 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,7 +33,7 @@
 /*
  * Get process statistics from kernel and return them in symon_buf as
  *
- * number of processes : ticks_user : ticks_system : ticks_interrupt : 
+ * number of processes : ticks_user : ticks_system : ticks_interrupt :
  * cpuseconds : procsizes : resident segment sizes
  *
  * Non re-entrant code: gets_proc messes with globals r/w without a semaphore.
@@ -65,31 +65,31 @@ static int proc_pagesize;
 typedef long pctcpu;
 #define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
 
-void 
+void
 gets_proc()
 {
     int mib[3];
     int procs;
     size_t size;
-	
+
     /* how much memory is needed */
     mib[0] = CTL_KERN;
     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",
+	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);
 	}
-	
+
 	proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc));
     }
 
@@ -105,15 +105,15 @@ gets_proc()
     }
 
     if (size % sizeof(struct kinfo_proc) != 0) {
-        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
+	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);
     }
 }
 /* Prepare io module for first use */
-void 
+void
 init_proc(char *s)
 {
     int mib[2] = {CTL_KERN, KERN_CLOCKRATE};
@@ -122,7 +122,7 @@ init_proc(char *s)
 
     /* 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;
 
@@ -134,10 +134,10 @@ init_proc(char *s)
 	proc_pagesize >>= 1;
     }
 
-    info("started module proc(%s)", s);
+    info("started module proc(%.200s)", s);
 }
 /* Get new io statistics */
-int 
+int
 get_proc(char *symon_buf, int maxlen, char *process)
 {
     int i;
@@ -170,13 +170,13 @@ get_proc(char *symon_buf, int maxlen, char *process)
 	     n++;
 	 }
     }
-    
-    /* calc total cpu_secs spent */ 
+
+    /* calc total cpu_secs spent */
     cpu_ticks = cpu_uticks + cpu_sticks + cpu_iticks;
-    cpu_secs = cpu_ticks / proc_stathz;  
+    cpu_secs = cpu_ticks / proc_stathz;
 
     return snpack(symon_buf, maxlen, process, MT_PROC,
-		  n, 
+		  n,
 		  cpu_uticks, cpu_sticks, cpu_iticks, cpu_secs, cpu_pcti,
 		  mem_procsize, mem_rss );
 }

+ 10 - 10
symon/symon/sm_sensor.c

@@ -1,4 +1,4 @@
-/* $Id: sm_sensor.c,v 1.1 2003/10/12 17:32:22 dijkstra Exp $ */
+/* $Id: sm_sensor.c,v 1.3 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
  * Copyright (c) 2001-2003 Willem Dijkstra
@@ -44,7 +44,7 @@
 
 #ifdef HAS_SENSORS_H
 #include <sys/sensors.h>
-#endif HAS_SENSORS_H
+#endif
 
 #include <errno.h>
 #include <limits.h>
@@ -58,12 +58,12 @@
 void
 init_sensor(char *s)
 {
-    fatal("sensor module requires system upgrade to OpenBSD 3.4");
+    fatal("sensor support not available");
 }
-int 
+int
 get_sensor(char *symon_buf, int maxlen, char *s)
 {
-    fatal("sensor module requires system upgrade to OpenBSD 3.4");
+    fatal("sensor support not available");
 }
 #else
 /* Globals for this module start with sn_ */
@@ -71,13 +71,13 @@ static int sn_mib[] = {CTL_HW, HW_SENSORS, 0};
 static struct sensor sn_sensor;
 
 /* Prepare if module for first use */
-void 
+void
 init_sensor(char *s)
 {
-    info("started module sensors(%s)", s);
+    info("started module sensors(%.200s)", s);
 }
 /* Get sensor statistics */
-int 
+int
 get_sensor(char *symon_buf, int maxlen, char *s)
 {
     size_t len;
@@ -89,11 +89,11 @@ get_sensor(char *symon_buf, int maxlen, char *s)
     l = strtol(s, NULL, 10);
     i = (int) (l & SYMON_SENSORMASK);
     sn_mib[2] = i;
-    
+
     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", 
+	warning("%s:%d: sensor can't get sensor %.200s -- %.200s",
 		__FILE__, __LINE__, s, strerror(errno));
 
 	return 0;

+ 57 - 43
symon/symon/symon.8

@@ -1,19 +1,19 @@
 .\"  -*- nroff -*-
 .\"
-.\" Copyright (c) 2001-2002 Willem Dijkstra
+.\" Copyright (c) 2001-2003 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
@@ -26,7 +26,7 @@
 .\" 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.
-.\" 
+.\"
 .Dd April 5, 2002
 .Dt SYMON 8
 .Os
@@ -34,8 +34,8 @@
 .Nm symon
 .Nd system monitor
 .Sh SYNOPSIS
-.Nm 
-.Op Fl vd
+.Nm
+.Op Fl duv
 .Op Fl f Ar filename
 .Pp
 .Sh DESCRIPTION
@@ -44,7 +44,7 @@ is a lightweight system monitor that measures cpu, memory, debug,
 process, interface and disk statistics every 5 seconds. This information
 is then spooled to
 .Xr symux 8
-for further processing. 
+for further processing.
 .Pp
 .Nm
 has been designed to inflict minimal performance and security impact on
@@ -52,39 +52,46 @@ the system it monitors.
 .Xr symux 8
 has performance impact proportional to the amount of streams it needs to
 manage. Ideally
-.Xr symux 
-should live on a different system and collect data from several 
+.Xr symux
+should live on a different system and collect data from several
 .Nm
-instances in a LAN. 
+instances in a LAN.
 .Lp
+By default,
 .Nm
-priviledge needs depend on the probes used. The cpu, mem, mbuf, disk,
-debug and interface probes will work even when symon runs as
-.Ar "nobody" . 
-For pf, read and write access to 
-.Pa /dev/pf
-is needed, so 
-.Nm 
-will have to run as
-.Ar "root".
+will drop priviledges and chroot(2) to home of
+.Ar "_symon".
+This behaviour is not strictly needed for the cpu, mem, mbuf, disk debug and
+interface probes as these will work even when
+.Nm
+is started as
+.Ar "nobody".
 .Lp
 The options:
 .Bl -tag -width Ds
-.It Fl v
-Show version information.
 .It Fl d
-Stop 
+Stop
 .Nm
 from becoming a daemon and show debug information on stdout.
 .It Fl f Ar filename
-Read configuration from 
+Read configuration from
 .Ar filename
-instead of 
+instead of
 .Pa /etc/symon.conf .
+.It Fl u
+By default
+.Nm
+will chroot(2) into
+.Pa _symon
+user home directory. The
+.Pa -u
+disables this behaviour.
+.It Fl v
+Show version information.
 .El
 .Sh CONFIGURATION
 .Nm
-obtains configuration data from 
+obtains configuration data from
 .Pa /etc/symon.conf .
 The configuration file contains monitor stanzas that define what
 resources should be monitored and to which
@@ -95,16 +102,22 @@ Multiple monitor statements to different muxes are allowed. Whitespace,
 newlines and text behind '#' are ignored. The format in BNF:
 .Pp
 .nf
-monitor-rule = "monitor" "{" resources "}" "stream" ["to"] host [ port ]
+monitor-rule = "monitor" "{" resources "}" [every]
+	       "stream" ["to"] host [ port ]
 resources    = resource ["(" argument ")"] [ ","|" " resources ]
-resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" | 
-               "proc" | "mbuf" | "sensor"
+argument     = number | interfacename | diskname
+resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" |
+	       "proc" | "mbuf" | "sensor"
+every        = "every" "second" | number "seconds"
 host         = ip4addr | ip6addr | hostname
 port         = [ "port" | "," ] portnumber
-argument     = number | interfacename | diskname
 .fi
+.Pp
+Note that symux(8) data files default to receiving data every 5
+seconds. Adjusting the monitoring interval will also require adjusting every
+symux(8) datafile.
 .Sh EXAMPLE
-Here is an example 
+Here is an example
 .Ar symon.conf
 that monitors cpu, memory, pf, interfaces xl0/de0/lo0/wi0, disks
 wd[0-3]/cd[0-1], debug variables debug0 to debug19 and streams that
@@ -112,20 +125,21 @@ information to localhost on port 2100.
 .Pp
 .nf
 monitor { cpu(0),  mem, pf, if(xl0), if(de0),
-          if(lo0), if(wi0), io(wd0), io(wd1), 
-          io(wd2), io(wd3), io(cd0), io(cd1), 
-          io(ccd0), debug, proc(httpd) } stream to 127.0.0.1 2100
+	  if(lo0), if(wi0), io(wd0), io(wd1),
+	  io(wd2), io(wd3), io(cd0), io(cd1),
+	  io(ccd0), debug, proc(httpd) } stream to 127.0.0.1 2100
 .fi
 .Sh SIGNALS
 .Bl -tag -width Ds
 .It SIGHUP
 Causes
 .Nm
-to read 
+to read
 .Pa /etc/symon.conf .
 .Nm
 will keep the old configuration if errors occured during parsing of the
-configuration file.
+configuration file. Note that the chroot(2) may cause resources to become
+unattainable, most notably the configuration file itself.
 .Sh FILES
 .Bl -tag -width Ds
 .It Pa /var/run/symon.pid
@@ -134,24 +148,24 @@ Contains the program id of the
 daemon.
 .It Pa /etc/symon.conf
 .Nm
-system wide configuration file. 
+system wide configuration file.
 .El
 .Sh BUGS
 Every monitored resource mentioned
-.Pa /etc/symon.conf 
+.Pa /etc/symon.conf
 gets queried. Mentioning, for example, cpu(0) twice for different muxes will
 result in two distinct cpu(0) measurement actions.
 .Pp
 The proc module is too simple: memory shared between two instances of the same
 process is simply counted twice.
 .Pp
-.Nm 
-does not check whether resources mentioned in 
+.Nm
+does not check whether resources mentioned in
 .Pa /etc/symon.conf
-exist. 
+exist.
+.Pp
 .Sh AUTHOR
 Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier <daniel@benzedrine.cx>
 contributed the pf probe and helped to port to big-endian architectures.
 .Sh SEE ALSO
-.Xr symux 8 
- 
+.Xr symux 8

+ 89 - 69
symon/symon/symon.c

@@ -1,7 +1,7 @@
-/* $Id: symon.c,v 1.30 2003/10/10 15:20:01 dijkstra Exp $ */
+/* $Id: symon.c,v 1.31 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -52,30 +53,33 @@
 
 __BEGIN_DECLS
 void alarmhandler(int);
+void drop_priviledges();
 void exithandler(int);
 void huphandler(int);
 void set_stream_use(struct muxlist *);
 __END_DECLS
 
+int flag_unsecure = 0;
 int flag_hup = 0;
+int symon_interval = SYMON_DEFAULT_INTERVAL;
 
 /* map stream types to inits and getters */
 struct funcmap streamfunc[] = {
-    {MT_IO, 0, init_io, gets_io, get_io},	/* gets_io obtains entire io state,
-					         * get_io = just a copy */
-    {MT_CPU, 0, init_cpu, NULL, get_cpu},
-    {MT_MEM, 0, init_mem, NULL, get_mem},
-    {MT_IF, 0, init_if, NULL, get_if},
-    {MT_PF, 0, init_pf, NULL, get_pf},
-    {MT_DEBUG, 0, init_debug, NULL, get_debug},
-    {MT_PROC, 0, init_proc, gets_proc, get_proc},
-    {MT_MBUF, 0, init_mbuf, NULL, get_mbuf},
-    {MT_SENSOR, 0, init_sensor, NULL, get_sensor},
-    {MT_EOT, 0, NULL, NULL}
+    {MT_IO, 0, NULL, init_io, gets_io, get_io},
+    {MT_CPU, 0, NULL, init_cpu, NULL, get_cpu},
+    {MT_MEM, 0, NULL, init_mem, NULL, get_mem},
+    {MT_IF, 0, NULL, init_if, NULL, get_if},
+    {MT_PF, 0, privinit_pf, init_pf, NULL, get_pf},
+    {MT_DEBUG, 0, NULL, init_debug, NULL, get_debug},
+    {MT_PROC, 0, NULL, init_proc, gets_proc, get_proc},
+    {MT_MBUF, 0, NULL, init_mbuf, NULL, get_mbuf},
+    {MT_SENSOR, 0, NULL, init_sensor, NULL, get_sensor},
+    {MT_EOT, 0, NULL, NULL, NULL}
 };
 
 void
-set_stream_use(struct muxlist *mul) {
+set_stream_use(struct muxlist *mul)
+{
     struct mux *mux;
     struct stream *stream;
     int i;
@@ -89,20 +93,45 @@ set_stream_use(struct muxlist *mul) {
 	    streamfunc[stream->type].used = 1;
     }
 }
-
-/* alarmhandler that gets called every SYMON_INTERVAL */
-void 
+void
+drop_priviledges(int unsecure)
+{
+    struct passwd *pw;
+
+    if (unsecure) {
+	if (setegid(getgid()) || setgid(getgid()) ||
+	    seteuid(getuid()) || setuid(getuid()))
+	    fatal("can't drop priviledges: %.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 (chroot(pw->pw_dir) < 0)
+	    fatal("chroot failed: %.200s", strerror(errno));
+
+	if (chdir("/") < 0)
+	    fatal("chdir / failed: %.200s", strerror(errno));
+
+	if (setgroups(1, &pw->pw_gid) ||
+	    setegid(pw->pw_gid) || setgid(pw->pw_gid) ||
+	    seteuid(pw->pw_uid) || setuid(pw->pw_uid))
+	    fatal("can't drop privileges: %.200s", strerror(errno));
+    }
+}
+/* alarmhandler that gets called every symon_interval */
+void
 alarmhandler(int s)
 {
     /* EMPTY */
 }
-void 
+void
 exithandler(int s)
 {
     info("received signal %d - quitting", s);
     exit(1);
 }
-void 
+void
 huphandler(int s)
 {
     info("hup received");
@@ -119,18 +148,15 @@ huphandler(int s)
  * Measurements are processed by a second program called symux. symon and symux
  * communicate via udp.
  */
-int 
+int
 main(int argc, char *argv[])
 {
     struct muxlist mul, newmul;
     struct itimerval alarminterval;
     struct stream *stream;
     struct mux *mux;
-    FILE *f;
-    char *cfgfile;
+    FILE *pidfile;
     char *cfgpath;
-    char *stringptr;
-    int maxstringlen;
     int ch;
     int i;
 
@@ -139,60 +165,57 @@ main(int argc, char *argv[])
     /* reset flags */
     flag_debug = 0;
     flag_daemon = 0;
-    cfgfile = SYMON_CONFIG_FILE;
+    flag_unsecure = 0;
 
-    while ((ch = getopt(argc, argv, "dvf:")) != -1) {
+    cfgpath = SYMON_CONFIG_FILE;
+
+    while ((ch = getopt(argc, argv, "dvuf:")) != -1) {
 	switch (ch) {
 	case 'd':
 	    flag_debug = 1;
 	    break;
+
 	case 'f':
-	    if (optarg && optarg[0] != '/') {
-		/* cfg path needs to be absolute, we will be a daemon soon */
-		if ((cfgpath = getwd(NULL)) == NULL)
-		    fatal("could not get working directory");
-
-		maxstringlen = strlen(cfgpath) + strlen(optarg) + 1;
-		cfgfile = xmalloc(maxstringlen);
-		strncpy(cfgfile, cfgpath, maxstringlen);
-		stringptr = cfgfile + strlen(cfgpath);
-		stringptr[0] = '/';
-		stringptr++;
-		strncpy(stringptr, optarg, maxstringlen - (cfgfile - stringptr));
-		cfgfile[maxstringlen] = '\0';
-
-		free(cfgpath);
-	    }
-	    else
-		cfgfile = xstrdup(optarg);
+	    cfgpath = xstrdup(optarg);
+	    break;
 
+	case 'u':
+	    flag_unsecure = 1;
 	    break;
+
 	case 'v':
 	    info("symon version %s", SYMON_VERSION);
 	default:
-	    info("usage: %s [-d] [-v] [-f cfgfile]", __progname);
+	    info("usage: %s [-d] [-u] [-v] [-f cfgfile]", __progname);
 	    exit(EX_USAGE);
 	}
     }
 
-    /* parse configuration file */
-    if (!read_config_file(&mul, cfgfile))
-	fatal("configuration contained errors; quitting");
+    if (!read_config_file(&mul, cfgpath))
+	fatal("configuration file contained errors - aborting");
+
+    set_stream_use(&mul);
+
+    /* open resources that might not be available after priviledge drop */
+    for (i = 0; i < MT_EOT; i++)
+	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));
 
-    setegid(getgid());
-    setgid(getgid());
+    drop_priviledges(flag_unsecure);
 
     if (flag_debug != 1) {
 	if (daemon(0, 0) != 0)
-	    fatal("daemonize failed");
+	    fatal("daemonize failed: %.200s", strerror(errno));
 
 	flag_daemon = 1;
 
-	/* record pid */
-	f = fopen(SYMON_PID_FILE, "w");
-	if (f) {
-	    fprintf(f, "%u\n", (u_int) getpid());
-	    fclose(f);
+	if (pidfile) {
+	    fprintf(pidfile, "%u\n", (u_int) getpid());
+	    fclose(pidfile);
 	}
     }
 
@@ -219,33 +242,32 @@ main(int argc, char *argv[])
 	}
     }
     set_stream_use(&mul);
-    
+
     /* setup alarm */
     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 -- %s", strerror(errno));
+	fatal("alarm setup failed: %.200s", strerror(errno));
     }
 
     for (;;) {			/* FOREVER */
-	sleep(SYMON_INTERVAL);	/* alarm will always interrupt sleep */
+	sleep(symon_interval);	/* alarm will interrupt sleep */
 
 	if (flag_hup == 1) {
 	    flag_hup = 0;
 
 	    SLIST_INIT(&newmul);
 
-	    if (!read_config_file(&newmul, cfgfile)) {
+	    if (!read_config_file(&newmul, cfgpath)) {
 		info("new configuration contains errors; keeping old configuration");
 		free_muxlist(&newmul);
-	    }
-	    else {
+	    } else {
 		free_muxlist(&mul);
 		mul = newmul;
-		info("read configuration file '%.100s' succesfully", cfgfile);
+		info("read configuration file '%.200s' succesfully", cfgpath);
 
 		/* init modules */
 		SLIST_FOREACH(mux, &mul, muxes) {
@@ -256,9 +278,7 @@ main(int argc, char *argv[])
 		}
 		set_stream_use(&mul);
 	    }
-	}
-	else {
-
+	} else {
 	    /* 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))
@@ -276,6 +296,6 @@ main(int argc, char *argv[])
 	    }
 	}
     }
-    /* NOTREACHED */
-    return (EX_SOFTWARE);
+
+    return (EX_SOFTWARE);     /* NOTREACHED */
 }

+ 11 - 6
symon/symon/symon.conf

@@ -1,10 +1,15 @@
 #
-# $Id: symon.conf,v 1.9 2002/10/18 12:29:48 dijkstra Exp $
+# $Id: symon.conf,v 1.11 2003/12/20 16:30:44 dijkstra Exp $
 #
 # Demo configuration for symon. See symon(8) for BNF.
 
-monitor { cpu(0),  mem,     if(xl0), if(de0),
-	  if(lo0), if(wi0), io(wd0), io(wd1), 
-          io(wd2), io(wd3), io(cd0), io(ccd0)}  
-		stream to 10.0.0.1 2100
-
+monitor { cpu(0),  mem, 
+	  if(lo0), 
+#	  pf, 
+#         mbuf,
+#         sensor(0),
+#         proc(httpd),
+#         if(xl0), if(de0), if(wi0), 
+#	  io(wd1), io(wd2), io(wd3), io(cd0)
+	  io(wd0), 
+} stream to 127.0.0.1 2100

+ 21 - 9
symon/symon/symon.h

@@ -1,7 +1,7 @@
-/* $Id: symon.h,v 1.26 2003/10/12 17:26:09 dijkstra Exp $ */
+/* $Id: symon.h,v 1.27 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,24 +40,35 @@
 #include "lex.h"
 #include "data.h"
 
-#define SYMON_PID_FILE    "/var/run/symon.pid"
-#define SYMON_INTERVAL 5	        /* measurement interval */
+#define SYMON_PID_FILE "/var/run/symon.pid"
+#define SYMON_USER "_symon"
+#define SYMON_DEFAULT_INTERVAL 5	/* measurement interval */
 #define SYMON_WARN_SENDERR 50	        /* warn every x errors */
-#define SYMON_MAX_DOBJECTS  2000	/* max dynamic allocation; local limit per
-				         * measurement module */
-#define SYMON_MAX_OBJSIZE  (_POSIX2_LINE_MAX)	/* max allocation unit =
-						 * _POSIX2_LINE_MAX */
-#define SYMON_SENSORMASK   0xFF         /* sensors 0-255 are allowed */
+#define SYMON_MAX_DOBJECTS 2000	        /* max dynamic allocation; local limit per
+					 * measurement module */
+#define SYMON_MAX_OBJSIZE (_POSIX2_LINE_MAX)
+#define SYMON_SENSORMASK 0xFF           /* sensors 0-255 are allowed */
 
+/* funcmap holds functions to be called for the individual monitors:
+ *
+ * - privinit = priviledged init, called before chroot
+ * - init     = called once, right after configuration
+ * - gets     = called every monitor interval, can be used by modules that get all
+ *              their measurements in one go.
+ * - get      = obtain measurement
+ */
 struct funcmap {
     int type;
     int used;
+    void (*privinit) ();
     void (*init) (char *);
     void (*gets) ();
     int (*get) (char *, int, char *);
 };
 extern struct funcmap streamfunc[];
 
+extern int symon_interval;
+
 /* prototypes */
 __BEGIN_DECLS
 /* sm_cpu.c */
@@ -78,6 +89,7 @@ extern void gets_io();
 extern int get_io(char *, int, char *);
 
 /* sm_pf.c */
+extern void privinit_pf();
 extern void init_pf(char *);
 extern int get_pf(char *, int, char *);
 

+ 9 - 9
symon/symon/symonnet.c

@@ -1,7 +1,7 @@
-/* $Id: symonnet.c,v 1.11 2002/11/29 10:45:21 dijkstra Exp $ */
+/* $Id: symonnet.c,v 1.12 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,7 @@
 #include "net.h"
 
 /* Fill a mux structure with inet details */
-void 
+void
 connect2mux(struct mux * mux)
 {
     struct sockaddr_storage sockaddr;
@@ -64,10 +64,10 @@ connect2mux(struct mux * mux)
     if (bind(mux->symuxsocket, (struct sockaddr *) & sockaddr, sockaddr.ss_len) == -1)
 	fatal("could not bind socket: %.200s", strerror(errno));
 
-    info("sending packets to udp %s", mux->name);
+    info("sending packets to udp %.200s", mux->name);
 }
 /* Send data stored in the mux structure to a mux */
-void 
+void
 send_packet(struct mux * mux)
 {
     if (sendto(mux->symuxsocket, (void *) &mux->packet.data,
@@ -78,13 +78,13 @@ send_packet(struct mux * mux)
     }
 
     if (mux->senderr >= SYMON_WARN_SENDERR) {
-	warning("%d updates to mux(%s) lost due to send errors",
+	warning("%d updates to mux(%.200s) lost due to send errors",
 		mux->senderr, mux->name);
 	mux->senderr = 0;
     }
 }
 /* Prepare a packet for data */
-void 
+void
 prepare_packet(struct mux * mux)
 {
     time_t t = time(NULL);
@@ -99,7 +99,7 @@ prepare_packet(struct mux * mux)
 		  &mux->packet.header);
 }
 /* Put a stream into the packet for a mux */
-void 
+void
 stream_in_packet(struct stream * stream, struct mux * mux)
 {
     mux->offset +=
@@ -109,7 +109,7 @@ stream_in_packet(struct stream * stream, struct mux * mux)
      stream->args);
 }
 /* Ready a packet for transmission, set length and crc */
-void 
+void
 finish_packet(struct mux * mux)
 {
     mux->packet.header.length = mux->offset;

+ 2 - 2
symon/symon/symonnet.h

@@ -1,7 +1,7 @@
-/* $Id: symonnet.h,v 1.5 2002/11/29 10:45:21 dijkstra Exp $ */
+/* $Id: symonnet.h,v 1.6 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 3 - 3
symon/symux/Makefile

@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.17 2003/10/12 17:26:10 dijkstra Exp $
+# $Id: Makefile,v 1.19 2003/12/21 13:01:05 dijkstra Exp $
 .include "../Makefile.inc"
 
 SRCS=	symux.c readconf.c symuxnet.c share.c
@@ -15,7 +15,7 @@ symux: ${OBJS}
 .endif
 
 clean:
-	rm -f conf.h symux symux.cat8 ${OBJS}
+	rm -f conf.h symux symux.cat8 symux.core ${OBJS}
 
 install: symux symux.cat8 c_smrrds.sh symux.conf
 	${INSTALL} -c -m 555 -g bin   -o root symux      ${PREFIX}/${BINDIR}
@@ -27,7 +27,7 @@ install: symux symux.cat8 c_smrrds.sh symux.conf
 
 cleanipc:
 	ipcs | egrep "^m" | awk '{print $$2}' | xargs -n1 ipcrm -m &
-	ipcs | egrep "^s" | awk '{print $$2}' | xargs -n1 ipcrm -s 
+	ipcs | egrep "^s" | awk '{print $$2}' | xargs -n1 ipcrm -s
 
 conf.h:  Makefile
 	@echo Generating conf.h

+ 132 - 123
symon/symux/c_smrrds.sh

@@ -1,21 +1,21 @@
 #!/bin/sh
-# $Id: c_smrrds.sh,v 1.21 2003/10/12 17:26:10 dijkstra Exp $
+# $Id: c_smrrds.sh,v 1.24 2003/12/21 13:23:15 dijkstra Exp $
 
 #
 # Copyright (c) 2001-2003 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
@@ -29,39 +29,39 @@
 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-# symon datafiles "make" file. Valid arguments:
-#       all      Makes all files for active interfaces and disks
-#       mem      Make memory file
-#       cpu?     Make cpu file
-#       pf       Make pf file
-#       mbuf     Make mbuf file
-
 # --- user configuration starts here
-INTERVAL=`grep SYMON_INTERVAL ../symon/symon.h 2>/dev/null | cut -f3 -d\ `
 INTERVAL=${INTERVAL:-5}
-RRD_ARGS="--step=$INTERVAL --start=0"
 # --- user configuration ends here
 
 # get arguments
+select_interval=""
 for i
 do
 case $i in
+interval)
+    select_interval="yes"
+    ;;
 child)
     child=1
     ;;
-oneday)	
+oneday)
     config=$i
 # today only RRA setup:
 # - 1   day  of  5 second  samples = 17280 x 5 second samples
-    RRA_SETUP=" RRA:AVERAGE:0.5:1:17280 
-	    RRA:MAX:0.5:1:17280 
+    RRA_SETUP=" RRA:AVERAGE:0.5:1:17280
+	    RRA:MAX:0.5:1:17280
 	    RRA:MIN:0.5:1:17280"
-    if [ X"$child" == "X" ]; then 
+    if [ X"$child" == "X" ]; then
 	echo "RRDs will only contain a single day of data"
     fi
     ;;
 *)
-    args="$args $i"
+    if [ -n "$select_interval" ]; then
+	INTERVAL=$i
+	select_interval=""
+    else
+	args="$args $i"
+    fi
     ;;
 esac
 done
@@ -69,20 +69,20 @@ done
 if [ X"$RRA_SETUP" == "X" ]; then
 # default RRA setup:
 # - 2   days of  5 second  samples = 34560 x 5 second samples
-# - 14  days of 30 minutes samples = 672 x 360 x 5 second samples 
+# - 14  days of 30 minutes samples = 672 x 360 x 5 second samples
 # - 50  days of  2 hour    samples = 600 x 1440 x 5 second samples
 # - 600 days of  1 day     samples = 600 x 17280 x 5 second samples
-RRA_SETUP=" RRA:AVERAGE:0.5:1:34560 
-	    RRA:AVERAGE:0.5:360:672 
-	    RRA:AVERAGE:0.5:1440:600 
-	    RRA:AVERAGE:0.5:17280:600 
-	    RRA:MAX:0.5:1:34560 
-	    RRA:MAX:0.5:360:672 
-	    RRA:MAX:0.5:1440:600 
-	    RRA:MAX:0.5:17280:600 
-	    RRA:MIN:0.5:1:34560 
-	    RRA:MIN:0.5:360:672 
-	    RRA:MIN:0.5:1440:600 
+RRA_SETUP=" RRA:AVERAGE:0.5:1:34560
+	    RRA:AVERAGE:0.5:360:672
+	    RRA:AVERAGE:0.5:1440:600
+	    RRA:AVERAGE:0.5:17280:600
+	    RRA:MAX:0.5:1:34560
+	    RRA:MAX:0.5:360:672
+	    RRA:MAX:0.5:1440:600
+	    RRA:MAX:0.5:17280:600
+	    RRA:MIN:0.5:1:34560
+	    RRA:MIN:0.5:360:672
+	    RRA:MIN:0.5:1440:600
 	    RRA:MIN:0.5:17280:600"
 fi
 
@@ -102,16 +102,48 @@ addsuffix() {
     echo $newlist | cut -b2-
 }
 
+DISKS=`addsuffix $DISKS [0-9]`
+INTERFACES=`addsuffix $INTERFACES [0-9]`
+VIRTUALINTERFACES=`addsuffix $VIRTUALINTERFACES \\.\\*`
+
 this=$0
 if [ X"$1$2$3$4$5$6$7$8$9" == "X" ]; then
-    sh $this help
+    cat <<EOF
+Create rrd files for symux.
+
+Usage: $0 [oneday] [interval <seconds>] all | cpu0 | mem |
+		   pf | mbuf | debug | proc_<process> |
+		   <if> | <io> | sensor[0-25]
+
+Where:
+oneday  = modify rrds to only contain one day of information
+seconds = modify rrds for non standard monitoring interval
+process = the name of a process as specified in sy{mon,mux}.conf
+	  e.g. proc(httpd) -> proc_httpd
+
+if=	`echo $INTERFACES|
+   awk 'BEGIN  {FS="|"}
+	   {for (i=1; i<=NF; i++) {
+	       printf("%s|",$i);
+	       if ((i%6)==0) {
+		  printf("%s","\n\t")
+	       }
+	   }
+	   print " ";}'`
+io=	`echo $DISKS|
+   awk 'BEGIN  {FS="|"}
+		{for (i=1; i<=NF; i++) {
+		    printf("%s|",$i);
+		    if ((i%6)==0) {
+			printf("%s","\n\t")
+		    }
+		}
+		print " ";}'`
+
+EOF
     exit 1;
 fi
 
-DISKS=`addsuffix $DISKS [0-9]`
-INTERFACES=`addsuffix $INTERFACES [0-9]`
-VIRTUALINTERFACES=`addsuffix $VIRTUALINTERFACES \\.\\*`
-
 for i in $args
 do
 # add if_*.rrd if it is an interface
@@ -127,15 +159,17 @@ if [ -f $i ]; then
     i="done"
 fi
 
+RRD_ARGS="--step=$INTERVAL --start=0"
+
 case $i in
 
 all)
     echo "Creating rrd files for {cpu0|mem|disks|interfaces|pf|mbuf}"
-    sh $this child $config cpu0 mem
-    sh $this child $config interfaces
-    sh $this child $config disks
-    sh $this child $config pf
-    sh $this child $config mbuf
+    sh $this interval $INTERVAL child $config cpu0 mem
+    sh $this interval $INTERVAL child $config interfaces
+    sh $this interval $INTERVAL child $config disks
+    sh $this interval $INTERVAL child $config pf
+    sh $this interval $INTERVAL child $config mbuf
     ;;
 
 if|interfaces)
@@ -151,11 +185,11 @@ io|disks)
 cpu[0-9].rrd)
     # Build cpu file
     rrdtool create $i $RRD_ARGS \
-	DS:user:GAUGE:5:0:100 \
-	DS:nice:GAUGE:5:0:100 \
-	DS:system:GAUGE:5:0:100 \
-	DS:interrupt:GAUGE:5:0:100 \
-	DS:idle:GAUGE:5:0:100 \
+	DS:user:GAUGE:$INTERVAL:0:100 \
+	DS:nice:GAUGE:$INTERVAL:0:100 \
+	DS:system:GAUGE:$INTERVAL:0:100 \
+	DS:interrupt:GAUGE:$INTERVAL:0:100 \
+	DS:idle:GAUGE:$INTERVAL:0:100 \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -163,7 +197,7 @@ cpu[0-9].rrd)
 sensor*.rrd)
     # Build sensor file
     rrdtool create $i $RRD_ARGS \
-	DS:value:GAUGE:5:-U:U \
+	DS:value:GAUGE:$INTERVAL:-U:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -171,11 +205,11 @@ sensor*.rrd)
 mem.rrd)
     # Build memory file
     rrdtool create $i $RRD_ARGS \
-	DS:real_active:GAUGE:5:0:U \
-	DS:real_total:GAUGE:5:0:U \
-	DS:free:GAUGE:5:0:U \
-	DS:swap_used:GAUGE:5:0:U \
-	DS:swap_total:GAUGE:5:0:U \
+	DS:real_active:GAUGE:$INTERVAL:0:U \
+	DS:real_total:GAUGE:$INTERVAL:0:U \
+	DS:free:GAUGE:$INTERVAL:0:U \
+	DS:swap_used:GAUGE:$INTERVAL:0:U \
+	DS:swap_total:GAUGE:$INTERVAL:0:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -183,11 +217,11 @@ mem.rrd)
 if_*.rrd)
     # Build interface files
     rrdtool create $i $RRD_ARGS \
-	DS:ipackets:COUNTER:5:U:U DS:opackets:COUNTER:5:U:U \
-	DS:ibytes:COUNTER:5:U:U DS:obytes:COUNTER:5:U:U \
-	DS:imcasts:COUNTER:5:U:U DS:omcasts:COUNTER:5:U:U \
-	DS:ierrors:COUNTER:5:U:U DS:oerrors:COUNTER:5:U:U \
-	DS:collisions:COUNTER:5:U:U DS:drops:COUNTER:5:U:U \
+	DS:ipackets:COUNTER:$INTERVAL:U:U DS:opackets:COUNTER:$INTERVAL:U:U \
+	DS:ibytes:COUNTER:$INTERVAL:U:U DS:obytes:COUNTER:$INTERVAL:U:U \
+	DS:imcasts:COUNTER:$INTERVAL:U:U DS:omcasts:COUNTER:$INTERVAL:U:U \
+	DS:ierrors:COUNTER:$INTERVAL:U:U DS:oerrors:COUNTER:$INTERVAL:U:U \
+	DS:collisions:COUNTER:$INTERVAL:U:U DS:drops:COUNTER:$INTERVAL:U:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -195,49 +229,49 @@ if_*.rrd)
 debug.rrd)
     # Build debug file
     rrdtool create $i $RRD_ARGS \
-	DS:debug0:GAUGE:5:U:U DS:debug1:GAUGE:5:U:U \
-	DS:debug2:GAUGE:5:U:U DS:debug3:GAUGE:5:U:U \
-	DS:debug4:GAUGE:5:U:U DS:debug5:GAUGE:5:U:U \
-	DS:debug6:GAUGE:5:U:U DS:debug7:GAUGE:5:U:U \
-	DS:debug8:GAUGE:5:U:U DS:debug9:GAUGE:5:U:U \
-	DS:debug10:GAUGE:5:U:U DS:debug11:GAUGE:5:U:U \
-	DS:debug12:GAUGE:5:U:U DS:debug13:GAUGE:5:U:U \
-	DS:debug14:GAUGE:5:U:U DS:debug15:GAUGE:5:U:U \
-	DS:debug16:GAUGE:5:U:U DS:debug17:GAUGE:5:U:U \
-	DS:debug18:GAUGE:5:U:U DS:debug19:GAUGE:5:U:U \
+	DS:debug0:GAUGE:$INTERVAL:U:U DS:debug1:GAUGE:$INTERVAL:U:U \
+	DS:debug2:GAUGE:$INTERVAL:U:U DS:debug3:GAUGE:$INTERVAL:U:U \
+	DS:debug4:GAUGE:$INTERVAL:U:U DS:debug5:GAUGE:$INTERVAL:U:U \
+	DS:debug6:GAUGE:$INTERVAL:U:U DS:debug7:GAUGE:$INTERVAL:U:U \
+	DS:debug8:GAUGE:$INTERVAL:U:U DS:debug9:GAUGE:$INTERVAL:U:U \
+	DS:debug10:GAUGE:$INTERVAL:U:U DS:debug11:GAUGE:$INTERVAL:U:U \
+	DS:debug12:GAUGE:$INTERVAL:U:U DS:debug13:GAUGE:$INTERVAL:U:U \
+	DS:debug14:GAUGE:$INTERVAL:U:U DS:debug15:GAUGE:$INTERVAL:U:U \
+	DS:debug16:GAUGE:$INTERVAL:U:U DS:debug17:GAUGE:$INTERVAL:U:U \
+	DS:debug18:GAUGE:$INTERVAL:U:U DS:debug19:GAUGE:$INTERVAL:U:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
 proc_*.rrd)
     # Build proc file
     rrdtool create $i $RRD_ARGS \
-	DS:number:GAUGE:5:0:U DS:uticks:GAUGE:5:0:U \
-	DS:sticks:GAUGE:5:0:U DS:iticks:GAUGE:5:0:U \
-	DS:cpusec:GAUGE:5:0:U DS:cpupct:GAUGE:5:0:100 \
-        DS:procsz:GAUGE:5:0:U DS:rsssz:GAUGE:5:0:U \
+	DS:number:GAUGE:$INTERVAL:0:U DS:uticks:GAUGE:$INTERVAL:0:U \
+	DS:sticks:GAUGE:$INTERVAL:0:U DS:iticks:GAUGE:$INTERVAL:0:U \
+	DS:cpusec:GAUGE:$INTERVAL:0:U DS:cpupct:GAUGE:$INTERVAL:0:100 \
+	DS:procsz:GAUGE:$INTERVAL:0:U DS:rsssz:GAUGE:$INTERVAL:0:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
-    
+
 pf.rrd)
     # Build pf file
     rrdtool create $i $RRD_ARGS \
-	DS:bytes_v4_in:DERIVE:5:0:U DS:bytes_v4_out:DERIVE:5:0:U \
-	DS:bytes_v6_in:DERIVE:5:0:U DS:bytes_v6_out:DERIVE:5:0:U \
-	DS:packets_v4_in_pass:DERIVE:5:0:U DS:packets_v4_in_drop:DERIVE:5:0:U \
-	DS:packets_v4_out_pass:DERIVE:5:0:U DS:packets_v4_out_drop:DERIVE:5:0:U \
-	DS:packets_v6_in_pass:DERIVE:5:0:U DS:packets_v6_in_drop:DERIVE:5:0:U \
-	DS:packets_v6_out_pass:DERIVE:5:0:U DS:packets_v6_out_drop:DERIVE:5:0:U \
-	DS:states_entries:ABSOLUTE:5:0:U \
-	DS:states_searches:DERIVE:5:0:U \
-	DS:states_inserts:DERIVE:5:0:U \
-	DS:states_removals:DERIVE:5:0:U \
-	DS:counters_match:DERIVE:5:0:U \
-	DS:counters_badoffset:DERIVE:5:0:U \
-	DS:counters_fragment:DERIVE:5:0:U \
-	DS:counters_short:DERIVE:5:0:U \
-	DS:counters_normalize:DERIVE:5:0:U \
-	DS:counters_memory:DERIVE:5:0:U \
+	DS:bytes_v4_in:DERIVE:$INTERVAL:0:U DS:bytes_v4_out:DERIVE:$INTERVAL:0:U \
+	DS:bytes_v6_in:DERIVE:$INTERVAL:0:U DS:bytes_v6_out:DERIVE:$INTERVAL:0:U \
+	DS:packets_v4_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_in_drop:DERIVE:$INTERVAL:0:U \
+	DS:packets_v4_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v4_out_drop:DERIVE:$INTERVAL:0:U \
+	DS:packets_v6_in_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_in_drop:DERIVE:$INTERVAL:0:U \
+	DS:packets_v6_out_pass:DERIVE:$INTERVAL:0:U DS:packets_v6_out_drop:DERIVE:$INTERVAL:0:U \
+	DS:states_entries:ABSOLUTE:$INTERVAL:0:U \
+	DS:states_searches:DERIVE:$INTERVAL:0:U \
+	DS:states_inserts:DERIVE:$INTERVAL:0:U \
+	DS:states_removals:DERIVE:$INTERVAL:0:U \
+	DS:counters_match:DERIVE:$INTERVAL:0:U \
+	DS:counters_badoffset:DERIVE:$INTERVAL:0:U \
+	DS:counters_fragment:DERIVE:$INTERVAL:0:U \
+	DS:counters_short:DERIVE:$INTERVAL:0:U \
+	DS:counters_normalize:DERIVE:$INTERVAL:0:U \
+	DS:counters_memory:DERIVE:$INTERVAL:0:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -245,14 +279,14 @@ pf.rrd)
 mbuf.rrd)
     # Build mbuf file
     rrdtool create $i $RRD_ARGS \
-	DS:totmbufs:GAUGE:5:0:U DS:mt_data:GAUGE:5:0:U \
-	DS:mt_oobdata:GAUGE:5:0:U DS:mt_control:GAUGE:5:0:U \
-	DS:mt_header:GAUGE:5:0:U DS:mt_ftable:GAUGE:5:0:U \
-	DS:mt_soname:GAUGE:5:0:U DS:mt_soopts:GAUGE:5:0:U \
-	DS:pgused:GAUGE:5:0:U DS:pgtotal:GAUGE:5:0:U \
-	DS:totmem:GAUGE:5:0:U DS:totpct:GAUGE:5:0:100 \
-	DS:m_drops:COUNTER:5:0:U DS:m_wait:COUNTER:5:0:U \
-	DS:m_drain:COUNTER:5:0:U \
+	DS:totmbufs:GAUGE:$INTERVAL:0:U DS:mt_data:GAUGE:$INTERVAL:0:U \
+	DS:mt_oobdata:GAUGE:$INTERVAL:0:U DS:mt_control:GAUGE:$INTERVAL:0:U \
+	DS:mt_header:GAUGE:$INTERVAL:0:U DS:mt_ftable:GAUGE:$INTERVAL:0:U \
+	DS:mt_soname:GAUGE:$INTERVAL:0:U DS:mt_soopts:GAUGE:$INTERVAL:0:U \
+	DS:pgused:GAUGE:$INTERVAL:0:U DS:pgtotal:GAUGE:$INTERVAL:0:U \
+	DS:totmem:GAUGE:$INTERVAL:0:U DS:totpct:GAUGE:$INTERVAL:0:100 \
+	DS:m_drops:COUNTER:$INTERVAL:0:U DS:m_wait:COUNTER:$INTERVAL:0:U \
+	DS:m_drain:COUNTER:$INTERVAL:0:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -260,9 +294,9 @@ mbuf.rrd)
 io_*.rrd)
     # Build disk files
     rrdtool create $i $RRD_ARGS \
-	DS:transfers:COUNTER:5:U:U \
-	DS:seeks:COUNTER:5:U:U \
-	DS:bytes:COUNTER:5:U:U \
+	DS:transfers:COUNTER:$INTERVAL:U:U \
+	DS:seeks:COUNTER:$INTERVAL:U:U \
+	DS:bytes:COUNTER:$INTERVAL:U:U \
 	$RRA_SETUP
     echo "$i created"
     ;;
@@ -273,31 +307,6 @@ io_*.rrd)
 *)
     # Default match
     echo $i - unknown
-    cat <<EOF
-Usage: $0 [oneday] all
-       $0 [oneday] cpu0|mem|pf|mbuf|debug|proc|<if>|<io>|sensor[0-25]
-
-Where:
-if=	`echo $INTERFACES|
-    awk 'BEGIN  {FS="|"}
-		{for (i=1; i<=NF; i++) { 
-		    printf("%s|",$i); 
-		    if ((i%6)==0) {
-			printf("%s","\n	")
-		    }
-		} 
-		print " ";}'`
-io=	`echo $DISKS|
-	awk 'BEGIN  {FS="|"}
-		{for (i=1; i<=NF; i++) { 
-		    printf("%s|",$i); 
-		    if ((i%6)==0) {
-			printf("%s","\n	")
-		    }
-		} 
-		print " ";}'`
-
-EOF
     ;;
 esac
 done

+ 41 - 52
symon/symux/readconf.c

@@ -1,7 +1,7 @@
-/* $Id: readconf.c,v 1.20 2003/10/10 15:20:03 dijkstra Exp $ */
+/* $Id: readconf.c,v 1.21 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ __END_DECLS
 
 const char *default_symux_port = SYMUX_PORT;
 
-int 
+int
 insert_filename(char *path, int maxlen, int type, char *args)
 {
     char *ts;
@@ -98,7 +98,7 @@ insert_filename(char *path, int maxlen, int type, char *args)
 	ta = args;
 	break;
     default:
-	warning("%s:%d: internal error: type (%d) unknown",
+	warning("%.200s:%d: internal error: type (%d) unknown",
 		__FILE__, __LINE__, type);
 	return 0;
     }
@@ -109,21 +109,21 @@ insert_filename(char *path, int maxlen, int type, char *args)
 	return 1;
 }
 /* mux <host> (port|,| ) <number> */
-int 
+int
 read_mux(struct muxlist * mul, struct lex * l)
 {
     char muxname[_POSIX2_LINE_MAX];
     struct mux *mux;
 
     if (!SLIST_EMPTY(mul)) {
-	warning("%s:%d: only one mux statement allowed",
+	warning("%.200s:%d: only one mux statement allowed",
 		l->filename, l->cline);
 	return 0;
     }
 
     lex_nexttoken(l);
     if (!getip(l->token)) {
-	warning("%s:%d: could not resolve '%s'",
+	warning("%.200s:%d: could not resolve '%s'",
 		l->filename, l->cline, l->token);
 	return 0;
     }
@@ -140,8 +140,7 @@ read_mux(struct muxlist * mul, struct lex * l)
     if (l->type != LXY_NUMBER) {
 	lex_ungettoken(l);
 	mux->port = xstrdup(default_symux_port);
-    }
-    else {
+    } else {
 	mux->port = xstrdup((const char *) l->token);
     }
 
@@ -155,7 +154,7 @@ read_mux(struct muxlist * mul, struct lex * l)
     return 1;
 }
 /* source <host> { accept ... | write ... | datadir ... } */
-int 
+int
 read_source(struct sourcelist * sol, struct lex * l)
 {
     struct source *source;
@@ -171,7 +170,7 @@ read_source(struct sourcelist * sol, struct lex * l)
     /* get hostname */
     lex_nexttoken(l);
     if (!getip(l->token)) {
-	warning("%s:%d: could not resolve '%s'",
+	warning("%.200s:%d: could not resolve '%s'",
 		l->filename, l->cline, l->token);
 	return 0;
     }
@@ -214,14 +213,13 @@ read_source(struct sourcelist * sol, struct lex * l)
 			    parse_error(l, ")");
 			    return 0;
 			}
-		    }
-		    else {
+		    } else {
 			lex_ungettoken(l);
 			sa[0] = '\0';
 		    }
 
 		    if ((stream = add_source_stream(source, st, sa)) == NULL) {
-			warning("%s:%d: stream %s(%s) redefined",
+			warning("%.200s:%d: stream %.200s(%.200s) redefined",
 				l->filename, l->cline, sn, sa);
 			return 0;
 		    }
@@ -242,7 +240,7 @@ read_source(struct sourcelist * sol, struct lex * l)
 	    lex_nexttoken(l);
 	    /* is path absolute */
 	    if (l->token && l->token[0] != '/') {
-		warning("%s:%d: datadir path '%s' is not absolute",
+		warning("%.200s:%d: datadir path '%.200s' is not absolute",
 			l->filename, l->cline, l->token);
 		return 0;
 	    }
@@ -252,13 +250,12 @@ read_source(struct sourcelist * sol, struct lex * l)
 
 	    if (stat(l->token, &sb) == 0) {
 		if (!(sb.st_mode & S_IFDIR)) {
-		    warning("%s:%d: datadir path '%s' is not a directory",
+		    warning("%.200s:%d: datadir path '%.200s' is not a directory",
 			    l->filename, l->cline, l->token);
 		    return 0;
 		}
-	    }
-	    else {
-		warning("%s:%d: could not stat datadir path '%s'",
+	    } else {
+		warning("%.200s:%d: could not stat datadir path '%.200s'",
 			l->filename, l->cline, l->token);
 		return 0;
 	    }
@@ -281,15 +278,14 @@ read_source(struct sourcelist * sol, struct lex * l)
 					  stream->type,
 					  stream->args))) {
 			if (stream->args && strlen(stream->args)) {
-			    warning("%s:%d: failed to construct stream "
-				    "%s(%s) filename using datadir '%s'",
+			    warning("%.200s:%d: failed to construct stream "
+				    "%.200s(%.200s) filename using datadir '%.200s'",
 				    l->filename, l->cline,
 				    type2str(stream->type),
 				    stream->args, l->token);
-			}
-			else {
-			    warning("%s:%d: failed to construct stream "
-				    "%s) filename using datadir '%s'",
+			} else {
+			    warning("%.200s:%d: failed to construct stream "
+				    "%.200s) filename using datadir '%.200s'",
 				    l->filename, l->cline,
 				    type2str(stream->type),
 				    l->token);
@@ -299,11 +295,10 @@ read_source(struct sourcelist * sol, struct lex * l)
 
 		    /* try filename */
 		    if ((fd = open(path, O_RDWR | O_NONBLOCK, 0)) == -1) {
-			warning("%s:%d: file '%s', guessed by datadir,  cannot be opened",
+			warning("%.200s:%d: file '%.200s', guessed by datadir,  cannot be opened",
 				l->filename, l->cline, path);
 			return 0;
-		    }
-		    else {
+		    } else {
 			close(fd);
 			stream->file = xstrdup(path);
 		    }
@@ -341,8 +336,7 @@ read_source(struct sourcelist * sol, struct lex * l)
 			parse_error(l, ")");
 			return 0;
 		    }
-		}
-		else {
+		} else {
 		    lex_ungettoken(l);
 		    sa[0] = '\0';
 		}
@@ -353,28 +347,25 @@ read_source(struct sourcelist * sol, struct lex * l)
 
 		if ((stream = find_source_stream(source, st, sa)) == NULL) {
 		    if (strlen(sa)) {
-			warning("%s:%d: stream %s(%s) is not accepted for %s",
+			warning("%.200s:%d: stream %.200s(%.200s) is not accepted for %.200s",
 				l->filename, l->cline, sn, sa, source->addr);
 			return 0;
-		    }
-		    else {
-			warning("%s:%d: stream %s is not accepted for %s",
+		    } else {
+			warning("%.200s:%d: stream %.200s is not accepted for %.200s",
 				l->filename, l->cline, sn, source->addr);
 			return 0;
 		    }
-		}
-		else {
+		} else {
 		    /* try filename */
 		    if ((fd = open(l->token, O_RDWR | O_NONBLOCK, 0)) == -1) {
-			warning("%s:%d: file '%s' cannot be opened",
+			warning("%.200s:%d: file '%.200s' cannot be opened",
 				l->filename, l->cline, l->token);
 			return 0;
-		    }
-		    else {
+		    } else {
 			close(fd);
 
 			if (stream->file != NULL) {
-			    warning("%s:%d: file '%s' overwrites previous definition '%s'",
+			    warning("%.200s:%d: file '%.200s' overwrites previous definition '%.200s'",
 			     l->filename, l->cline, l->token, stream->file);
 			    xfree(stream->file);
 			}
@@ -397,13 +388,13 @@ read_source(struct sourcelist * sol, struct lex * l)
 	}
     }
 
-    warning("%s:%d: missing close brace on source statement",
+    warning("%.200s:%d: missing close brace on source statement",
 	    l->filename, l->cline);
 
     return 0;
 }
 /* Read symux.conf */
-int 
+int
 read_config_file(struct muxlist * mul, const char *filename)
 {
     struct lex *l;
@@ -443,11 +434,10 @@ read_config_file(struct muxlist * mul, const char *filename)
     /* sanity checks */
     if (SLIST_EMPTY(mul)) {
 	free_sourcelist(&sol);
-	warning("%s: no mux statement seen",
+	warning("%.200s: no mux statement seen",
 		l->filename);
 	return 0;
-    }
-    else {
+    } else {
 	mux = SLIST_FIRST(mul);
 	mux->sol = sol;
 	if (strncmp(SYMON_UNKMUX, mux->name, sizeof(SYMON_UNKMUX)) == 0) {
@@ -457,21 +447,20 @@ read_config_file(struct muxlist * mul, const char *filename)
     }
 
     if (SLIST_EMPTY(&sol)) {
-	warning("%s: no source section seen",
+	warning("%.200s: no source section seen",
 		l->filename);
 	return 0;
-    }
-    else {
+    } else {
 	SLIST_FOREACH(source, &sol, sources) {
 	    if (SLIST_EMPTY(&source->sl)) {
-		warning("%s: no streams accepted for source '%s'",
+		warning("%.200s: no streams accepted for source '%.200s'",
 			l->filename, source->addr);
 		return 0;
-	    }
-	    else {
+	    } else {
 		SLIST_FOREACH(stream, &source->sl, streams) {
 		    if (stream->file == NULL) {
-			warning("%s: no filename specified for stream '%s(%s)' in source '%s'",
+			/* warn, but allow */
+			warning("%.200s: no filename specified for stream '%.200s(%.200s)' in source '%.200s'",
 				l->filename, type2str(stream->type), stream->args, source->addr);
 		    }
 		}

+ 2 - 2
symon/symux/readconf.h

@@ -1,7 +1,7 @@
-/* $Id: readconf.h,v 1.6 2002/11/29 10:49:35 dijkstra Exp $ */
+/* $Id: readconf.h,v 1.7 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 22 - 31
symon/symux/share.c

@@ -1,7 +1,7 @@
-/* $Id: share.c,v 1.12 2003/10/10 15:20:03 dijkstra Exp $ */
+/* $Id: share.c,v 1.14 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,11 +30,6 @@
  *
  */
 
-/* TODO:
- * Dynamically allocate buffer size
- * Check wether one buffer suffices, do some performance tests
- */
-
 /* Share contains all routines needed for the ipc between symuxes */
 #include <sys/types.h>
 #include <sys/ipc.h>
@@ -124,13 +119,13 @@ shared_getmem()
     return &shm->data;
 }
 /* Get max length of data stored in shared region */
-long 
+long
 shared_getmaxlen()
 {
     return shm->reglen - sizeof(struct sharedregion);
 }
 /* Set length of data stored in shared region */
-void 
+void
 shared_setlen(long length)
 {
     if (length > (shm->reglen - (long) sizeof(struct sharedregion)))
@@ -141,13 +136,13 @@ shared_setlen(long length)
     shm->ctlen = length;
 }
 /* Get length of data stored in shared region */
-long 
+long
 shared_getlen()
 {
     return shm->ctlen;
 }
 /* Check whether semaphore is available */
-void 
+void
 check_sem()
 {
     if (semstat != SIPC_KEYED)
@@ -156,7 +151,7 @@ check_sem()
 }
 
 /* Check whether process is the master process */
-void 
+void
 check_master()
 {
     if (master == 0)
@@ -165,7 +160,7 @@ check_master()
 }
 
 /* Reset semaphores before each distribution cycle */
-void 
+void
 master_resetsem()
 {
     union semun semarg;
@@ -181,7 +176,7 @@ master_resetsem()
 	      __FILE__, __LINE__);
 }
 /* Prepare for writing to shm */
-void 
+void
 master_forbidread()
 {
     int clientsread;
@@ -207,7 +202,7 @@ master_forbidread()
     master_resetsem();
 }
 /* Signal 'permit read' to all clients */
-void 
+void
 master_permitread()
 {
     union semun semarg;
@@ -221,7 +216,7 @@ master_permitread()
 	      __FILE__, __LINE__);
 }
 /* Make clients wait until master signals */
-void 
+void
 client_waitread()
 {
     struct sembuf sops;
@@ -239,7 +234,7 @@ client_waitread()
     seqnr = shm->seqnr;
 }
 /* Client signal 'done reading' to master */
-void 
+void
 client_doneread()
 {
     struct sembuf sops;
@@ -264,14 +259,14 @@ client_doneread()
     sleep(1);
 }
 /* Client signal handler => always exit */
-void 
+void
 client_signalhandler(int s)
 {
     debug("client(%d) received signal %d - quitting", clientpid, s);
     exit(EX_TEMPFAIL);
 }
 /* Prepare sharing structures for use */
-void 
+void
 initshare(int bufsize)
 {
     newclients = 0;
@@ -311,29 +306,25 @@ pid_t
 spawn_client(int sock)
 {
     pid_t pid;
-    char peername[NI_MAXHOST];
 
     check_master();
 
-    bzero(peername, sizeof(peername));
-    clientsock = accept_connection(sock, (char *) &peername[0], sizeof(peername));
+    clientsock = accept_connection(sock);
 
     if ((pid = fork())) {
 	/* server */
 	if (pid == -1) {
 	    info("could not fork client process");
-	}
-	else {
+	} else {
 	    newclients++;
-	    info("forked client(%d) for incoming connection from %.17s",
-		 pid, &peername[0]);
+	    info("forked client(%d) for incoming connection from %.200s:%.200s",
+		 pid, res_host, res_service);
 	}
 
 	close(clientsock);
 
 	return pid;
-    }
-    else {
+    } else {
 	/* client */
 	master = 0;
 
@@ -353,7 +344,7 @@ spawn_client(int sock)
     }
 }
 /* Reap exit/stopped clients */
-void 
+void
 reap_clients()
 {
     pid_t pid;
@@ -380,7 +371,7 @@ reap_clients()
     }
 }
 /* Remove shared memory and semaphores at exit */
-void 
+void
 exitmaster()
 {
     union semun semarg;
@@ -423,7 +414,7 @@ exitmaster()
 		__FILE__, __LINE__);
     }
 }
-void 
+void
 client_loop()
 {
     int total;

+ 2 - 2
symon/symux/share.h

@@ -1,7 +1,7 @@
-/* $Id: share.h,v 1.6 2002/11/29 10:49:41 dijkstra Exp $ */
+/* $Id: share.h,v 1.7 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 41 - 41
symon/symux/symux.8

@@ -1,19 +1,19 @@
 .\"  -*- nroff -*-
 .\"
-.\" Copyright (c) 2001-2002 Willem Dijkstra
+.\" Copyright (c) 2001-2003 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
@@ -26,7 +26,7 @@
 .\" 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.
-.\" 
+.\"
 .Dd April 5, 2002
 .Dt SYMUX 8
 .Os
@@ -34,7 +34,7 @@
 .Nm symux
 .Nd symon stream multiplexer
 .Sh SYNOPSIS
-.Nm 
+.Nm
 .Op Fl vd
 .Op Fl f Ar filename
 .Pp
@@ -44,7 +44,7 @@ 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
 .Nm
-for further processing. 
+for further processing.
 .Pp
 .Xr symon 8
 has been designed to inflict minimal performance and security impact on
@@ -52,15 +52,15 @@ the system it monitors.
 .Nm
 has performance impact proportional to the amount of streams it needs to
 manage. Ideally
-.Nm 
+.Nm
 should live on a different system and collect data from several
 .Xr symon 8
 instances in a LAN.
-.Nm 
+.Nm
 stores the incoming streams in .rrd files and distributes the
 information to connected listeners. Listeners can connect to
 .Nm
-on a tcp port and receive incoming 
+on a tcp port and receive incoming
 .Xr symon 8
 transmissions decoded into ascii.
 .Lp
@@ -74,21 +74,21 @@ The options:
 .It Fl v
 Show version information.
 .It Fl d
-Stop 
+Stop
 .Nm
 from becoming a daemon and show debug information on stdout.
 .It Fl f Ar filename
-Read configuration from 
+Read configuration from
 .Ar filename
-instead of 
+instead of
 .Pa /etc/symux.conf .
 .Sh CONFIGURATION
 .Nm
-obtains configuration data from 
+obtains configuration data from
 .Pa /etc/symux.conf .
 The configuration file contains one mux stanza that defines on what host
 address and port
-.Nm 
+.Nm
 should listen to for incoming monitored data. There is a source section
 for every host that is to be monitored. The source section defines what
 data to accept and where to write that data to. In the case that a
@@ -106,36 +106,36 @@ source-stmt  = "source" host "{" accept-stmts write-stmts [ datadir-stmt ] "}"
 accept-stmts = accept-stmt [accept-stmts]
 accept-stmt  = "accept" "{" resources "}"
 resources    = resource ["(" argument ")"] [ ","|" " resources ]
-resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" | 
-               "proc" | "mbuf" | "sensor"
+resource     = "cpu" | "mem" | "if" | "io" | "pf" | "debug" |
+	       "proc" | "mbuf" | "sensor"
 argument     = number | interfacename | diskname
 datadir-stmt = "datadir" dirname
 write-stmts  = write-stmt [write-stmts]
 write-stmt   = "write" resource "in" filename
 .fi
 .Pp
-Note that 
+Note that
 .Bl -tag -width Ds
 .It Va port
-in the 
+in the
 .Va mux-stmt
-specifies the port-number for both the udp port (incoming 
+specifies the port-number for both the udp port (incoming
 .Xr symon 8
 traffic) and the tcp port for incoming listeners.
 .It Va datadir
-will guess filenames for all 
-accepted streams. 
+will guess filenames for all
+accepted streams.
 .Va write
 statements always take precendence over a
 .Va datadir
-statement. 
+statement.
 .Sh EXAMPLE
-Here is an example 
+Here is an example
 .Ar symux.conf
 that listens to udp port 2100 on lo0, and accepts cpu, memory, pf,
 interfaces xl0/de0/lo0/wi0, disks wd[0-3]/cd[0-1] streams from a
 .Xr symon 8
-on localhost. 
+on localhost.
 .Nm
 will also listen on tcp port 2100 for incoming listeners.
 .Pp
@@ -143,18 +143,18 @@ will also listen on tcp port 2100 for incoming listeners.
 mux 127.0.0.1 2100
 source 127.0.0.1 {
     accept { cpu(0), mem, pf,
-             if(xl0), if(de0),
-             if(lo0), if(wi0), 
-             io(wd0), io(wd1), io(wd2), 
-             io(wd3), io(cd0), io(cd1) }
+	     if(xl0), if(de0),
+	     if(lo0), if(wi0),
+	     io(wd0), io(wd1), io(wd2),
+	     io(wd3), io(cd0), io(cd1) }
 
     datadir "/export/symon/localhost"
 }
 .fi
 .Sh LISTENERS
 .Nm
-offers received 
-.Xr symon 8 
+offers received
+.Xr symon 8
 data to other programs via tcp. An example of a listener session:
 .Pp
 .nf
@@ -179,7 +179,7 @@ telnet> close
 Connection closed.
 .fi
 .Lp
-The format is 
+The format is
 .Va symon-version
 :
 .Va symon-host-ip
@@ -235,10 +235,10 @@ precision. Value depends on sensor type.
 .It SIGHUP
 Causes
 .Nm
-to read 
-.Pa /etc/symux.conf 
-or the file specified by the 
-.Fl f 
+to read
+.Pa /etc/symux.conf
+or the file specified by the
+.Fl f
 flag.
 .Nm
 will keep the old configuration if errors occured during parsing of the
@@ -252,19 +252,19 @@ Contains the program id of the
 daemon.
 .It Pa /etc/symux.conf
 .Nm
-system wide configuration file. 
+system wide configuration file.
 .El
 .Sh BUGS
-.Nm 
+.Nm
 writes incoming data to rrd files "in process". An rrdupdate on a somewhat
 stale rrdfile -- with the last data from quite some time in the past -- is a
 very expensive operation. This can cause
-.Nm 
+.Nm
 to lockup while rrdupdate is updating the rrd file.
 .Nm
-will be unresponsive during this process. 
+will be unresponsive during this process.
 .Sh AUTHOR
 Willem Dijkstra <wpd@xs4all.nl>. Daniel Hartmeier <daniel@benzedrine.cx>
 contributed the pf probe and helped to port to big-endian architectures.
 .Sh SEE ALSO
-.Xr symon 8 
+.Xr symon 8

+ 13 - 19
symon/symux/symux.c

@@ -1,7 +1,7 @@
-/* $Id: symux.c,v 1.26 2002/11/29 10:45:22 dijkstra Exp $ */
+/* $Id: symux.c,v 1.27 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -64,13 +64,13 @@ int flag_hup = 0;
 fd_set fdset;
 int maxfd;
 
-void 
+void
 exithandler(int s)
 {
     info("received signal %d - quitting", s);
     exit(EX_TEMPFAIL);
 }
-void 
+void
 huphandler(int s)
 {
     info("hup received");
@@ -92,7 +92,7 @@ huphandler(int s)
  * Symon can keep track of cpu, memory, disk and network interface
  * interactions. Symon was built specifically for OpenBSD.
  */
-int 
+int
 main(int argc, char *argv[])
 {
     struct symonpacket packet;
@@ -141,8 +141,7 @@ main(int argc, char *argv[])
 		cfgfile[maxstringlen] = '\0';
 
 		free(cfgpath);
-	    }
-	    else
+	    } else
 		cfgfile = xstrdup(optarg);
 
 	    break;
@@ -214,8 +213,7 @@ main(int argc, char *argv[])
 	    if (!read_config_file(&newmul, cfgfile)) {
 		info("new configuration contains errors; keeping old configuration");
 		free_muxlist(&newmul);
-	    }
-	    else {
+	    } else {
 		info("read configuration file '%.100s' succesfully", cfgfile);
 		free_muxlist(&mul);
 		mul = newmul;
@@ -223,8 +221,7 @@ main(int argc, char *argv[])
 		get_symon_sockets(mux);
 		get_client_socket(mux);
 	    }
-	}
-	else {
+	} else {
 
 	    /*
 	     * Put information from packet into stringbuf (shared region).
@@ -283,21 +280,18 @@ main(int argc, char *argv[])
 			/*
 			 * This call will cost a lot (symux will become
 			 * unresponsive and eat up massive amounts of cpu) if
-			 * the rrdfile is out of sync. While I could update
-			 * the rrd in a separate process, I choose not to at
-			 * this time.
+			 * the rrdfile is out of sync.
 			 */
 			rrd_update(4, arg_ra);
 
 			if (rrd_test_error()) {
-			    warning("rrd_update:%s", rrd_get_error());
-			    warning("%s %s %s %s", arg_ra[0], arg_ra[1],
+			    warning("rrd_update:%.200s", rrd_get_error());
+			    warning("%.200s %.200s %.200s %.200s", arg_ra[0], arg_ra[1],
 				    arg_ra[2], arg_ra[3]);
 			    rrd_clear_error();
-			}
-			else {
+			} else {
 			    if (flag_debug == 1)
-				debug("%s %s %s %s", arg_ra[0], arg_ra[1],
+				debug("%.200s %.200s %.200s %.200s", arg_ra[0], arg_ra[1],
 				      arg_ra[2], arg_ra[3]);
 			}
 		    }

+ 29 - 19
symon/symux/symux.conf

@@ -1,27 +1,37 @@
 #
-# $Id: symux.conf,v 1.20 2002/11/29 10:49:41 dijkstra Exp $
+# $Id: symux.conf,v 1.21 2003/12/20 16:30:44 dijkstra Exp $
 #
 # Demo symux configuration. See symux(8) for BNF.
 
-mux 10.0.0.1 2100
+mux 127.0.0.1 2100
 
-source 10.0.0.1 {
-	accept { cpu(0), mem, if(xl0), if(de0),
-	         if(lo0), io(wd0), io(wd1), 
-                 io(wd2), io(wd3), io(cd0)}
+source 127.0.0.1 {
+	accept { cpu(0),  mem, 
+	  	 if(lo0), 
+#	  	 pf, 
+#         	 mbuf,
+#         	 sensor(0),
+#         	 proc(httpd),
+#         	 if(xl0), if(de0), if(wi0), 
+#	  	 io(wd1), io(wd2), io(wd3), io(cd0)
+	  	 io(wd0)
+	}
 
-	datadir "/export/symon/www"
+	datadir "/var/www/symon/rrds/localhost"
 }
 
-source 10.0.0.2 {
-	accept { cpu(0), mem, if(sis0), if(sis1),
-		 if(lo0), if(wi0), io(wd0) }
-
-	write cpu(0)   in "/export/symon/4512/cpu0.rrd"
-	write mem      in "/export/symon/4512/mem.rrd"
-	write if(sis0) in "/export/symon/4512/if_sis0.rrd"
-	write if(sis1) in "/export/symon/4512/if_sis1.rrd"
-	write if(lo0)  in "/export/symon/4512/if_lo0.rrd"
-	write if(wi0)  in "/export/symon/4512/if_wi0.rrd"
-	write io(wd0)  in "/export/symon/4512/io_wd0.rrd"
-}
+# an example showing the write directive
+#
+# source 10.0.0.2 {
+#	accept { cpu(0), mem, if(sis0), if(sis1),
+#		 if(lo0), if(wi0), io(wd0)
+#	}
+#
+#	write cpu(0)   in "/var/www/symon/rrds/4512/cpu0.rrd"
+#	write mem      in "/var/www/symon/rrds/4512/mem.rrd"
+#	write if(sis0) in "/var/www/symon/rrds/4512/if_sis0.rrd"
+#	write if(sis1) in "/var/www/symon/rrds/4512/if_sis1.rrd"
+#	write if(lo0)  in "/var/www/symon/rrds/if_lo0.rrd"
+#	write if(wi0)  in "/var/www/symon/rrds/4512/if_wi0.rrd"
+#	write io(wd0)  in "/var/www/symon/rrds/4512/io_wd0.rrd"
+# }

+ 2 - 2
symon/symux/symux.h

@@ -1,7 +1,7 @@
-/* $Id: symux.h,v 1.17 2003/10/12 17:26:10 dijkstra Exp $ */
+/* $Id: symux.h,v 1.18 2003/12/20 16:30:44 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

+ 33 - 57
symon/symux/symuxnet.c

@@ -1,7 +1,7 @@
-/* $Id: symuxnet.c,v 1.12 2002/11/29 10:45:22 dijkstra Exp $ */
+/* $Id: symuxnet.c,v 1.14 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,13 +52,12 @@ int check_crc_packet(struct symonpacket *);
 __END_DECLS
 
 /* Obtain sockets for incoming symon traffic */
-int 
+int
 get_symon_sockets(struct mux * mux)
 {
     struct source *source;
     struct sockaddr_storage sockaddr;
     int family, nsocks;
-    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
     nsocks = 0;
 
     /* generate the udp listen socket specified in the mux statement */
@@ -78,8 +77,7 @@ get_symon_sockets(struct mux * mux)
 		 */
 		if (mux->sockaddr.ss_family == family) {
 		    cpysock((struct sockaddr *) & mux->sockaddr, &sockaddr);
-		}
-		else {
+		} else {
 		    get_inaddrany_sockaddr(&sockaddr, family, SOCK_DGRAM, mux->port);
 		}
 
@@ -87,14 +85,12 @@ get_symon_sockets(struct mux * mux)
 			 sockaddr.ss_len) == -1)
 		    close(mux->symonsocket[family]);
 		else {
-		    if (getnameinfo((struct sockaddr *) & sockaddr, sockaddr.ss_len,
-				    hbuf, sizeof(hbuf), sbuf, sizeof(sbuf),
-				    NI_NUMERICHOST | NI_NUMERICSERV)) {
+		    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 %s %s", hbuf, sbuf);
+		    } else
+			info("listening for incoming symon traffic on udp %.200s %.200s",
+			     res_host, res_service);
 
 		    nsocks++;
 		}
@@ -104,7 +100,7 @@ get_symon_sockets(struct mux * mux)
     return nsocks;
 }
 /* Obtain a listen socket for new clients */
-int 
+int
 get_client_socket(struct mux * mux)
 {
     struct addrinfo hints, *res;
@@ -120,7 +116,7 @@ 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 %s:%s - %s",
+	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)
@@ -134,7 +130,7 @@ get_client_socket(struct mux * mux)
     fcntl(sock, O_NONBLOCK);
     mux->clientsocket = sock;
 
-    info("listening for incoming connections on tcp %s %s",
+    info("listening for incoming connections on tcp %.200s %.200s",
 	 mux->addr, mux->port);
 
     return sock;
@@ -144,7 +140,7 @@ get_client_socket(struct mux * mux)
  * Returns the <source> and <packet>
  * Silently forks off clienthandlers
  */
-void 
+void
 wait_for_traffic(struct mux * mux, struct source ** source,
 		 struct symonpacket * packet)
 {
@@ -181,8 +177,7 @@ wait_for_traffic(struct mux * mux, struct source ** source,
 		    if (recv_symon_packet(mux, i, source, packet))
 			return;
 		}
-	}
-	else {
+	} else {
 	    if (errno == EINTR)
 		return;		/* signal received while waiting, bail out */
 	}
@@ -191,11 +186,10 @@ wait_for_traffic(struct mux * mux, struct source ** source,
 /* Receive a symon packet for mux. Checks if the source is allowed and returns the source found.
  * return 0 if no valid packet found
  */
-int 
+int
 recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
 		  struct symonpacket * packet)
 {
-    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
     struct sockaddr_storage sind;
     socklen_t sl;
     int size, tries;
@@ -204,15 +198,14 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
 
     received = 0;
     tries = 0;
-    bzero((void *) hbuf, sizeof(hbuf));
-    bzero((void *) sbuf, sizeof(sbuf));
 
     do {
 	sl = sizeof(sind);
 
-	size = recvfrom(mux->symonsocket[socknr], (void *) packet->data + received,
+	size = recvfrom(mux->symonsocket[socknr],
+			(void *) (packet->data + received),
 			sizeof(struct symonpacket) - received,
-			0, (struct sockaddr *) & sind, &sl);
+			0, (struct sockaddr *) &sind, &sl);
 	if (size > 0)
 	    received += size;
 
@@ -226,15 +219,14 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
 	errno)
 	warning("recvfrom failed: %.200s", strerror(errno));
 
-    *source = find_source_sockaddr(&mux->sol, (struct sockaddr *) & sind);
+    *source = find_source_sockaddr(&mux->sol, (struct sockaddr *) &sind);
+
+    get_numeric_name(&sind);
 
     if (*source == NULL) {
-	getnameinfo((struct sockaddr *) & sind, sind.ss_len, hbuf, sizeof(hbuf),
-		    sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-	debug("ignored data from %s:%s", hbuf, sbuf);
+	debug("ignored data from %.200s:%.200s", res_host, res_service);
 	return 0;
-    }
-    else {
+    } else {
 	/* get header stream */
 	mux->offset = getheader(packet->data, &packet->header);
 	/* check crc */
@@ -243,51 +235,35 @@ recv_symon_packet(struct mux * mux, int socknr, struct source ** source,
 	setheader(packet->data, &packet->header);
 	crc ^= crc32(packet->data, received);
 	if (crc != 0) {
-	    getnameinfo((struct sockaddr *) & sind, sind.ss_len, hbuf, sizeof(hbuf),
-			sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-	    warning("ignored packet with bad crc from %s:%s",
-		    hbuf, sbuf);
+	    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) {
-	    getnameinfo((struct sockaddr *) & sind, sind.ss_len, hbuf, sizeof(hbuf),
-			sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-	    warning("ignored packet with wrong version %d from %s:%s",
-		    packet->header.symon_version, hbuf, sbuf);
+	    warning("ignored packet with wrong version %d from %.200s:%.200s",
+		    packet->header.symon_version, res_host, res_service);
 	    return 0;
-	}
-	else {
+	} else {
 	    if (flag_debug) {
-		getnameinfo((struct sockaddr *) & sind, sind.ss_len, hbuf, sizeof(hbuf),
-		       sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-		debug("good data received from %s:%s", hbuf, sbuf);
+		debug("good data received from %.200s:%.200s", res_host, res_service);
 	    }
 	    return 1;		/* good packet received */
 	}
     }
 }
-int 
-accept_connection(int sock, char *peername, int peernamesize)
+int
+accept_connection(int sock)
 {
-    char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
     struct sockaddr_storage sind;
     socklen_t len;
     int clientsock;
 
-    bzero((void *) hbuf, sizeof(hbuf));
-    bzero((void *) sbuf, sizeof(sbuf));
-
-    if ((clientsock = accept(sock, (struct sockaddr *) & sind, &len)) < 0)
-	fatal("failed to accept an incoming connection. (.200%s)",
+    if ((clientsock = accept(sock, (struct sockaddr *) &sind, &len)) < 0)
+	fatal("failed to accept an incoming connection. (%.200s)",
 	      strerror(errno));
 
-
-    if (getnameinfo((struct sockaddr *) & sind, sind.ss_len, hbuf, sizeof(hbuf),
-		    sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV))
-	snprintf(peername, peernamesize, "<unknown>");
-    else
-	snprintf(peername, peernamesize, "%s:%s", hbuf, sbuf);
+    get_numeric_name(&sind);
 
     return clientsock;
 }

+ 3 - 3
symon/symux/symuxnet.h

@@ -1,7 +1,7 @@
-/* $Id: symuxnet.h,v 1.8 2002/11/29 10:45:22 dijkstra Exp $ */
+/* $Id: symuxnet.h,v 1.10 2003/12/21 13:01:05 dijkstra Exp $ */
 
 /*
- * Copyright (c) 2001-2002 Willem Dijkstra
+ * Copyright (c) 2001-2003 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
 __BEGIN_DECLS
 int get_client_socket(struct mux *);
 int get_symon_sockets(struct mux *);
-int accept_connection(int, char *, int);
+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