--- /dev/null
+#!/bin/sh
+#
+# chkconfig: 2345 56 25
+# description: Fprobe-ulog initscript
+#
+
+PROC=fprobe-ulog
+
+. /etc/rc.d/init.d/functions
+
+RETVAL=0
+
+pidfile=/var/run/$PROC.pid
+
+check_status() {
+ pid=`cat $pidfile 2>/dev/null`
+ #
+ # this eliminates a race condition between checking existence of pidfile
+ # and reading its value
+ #
+ [ -n "$pid" -a -d /proc/$pid ]
+}
+
+case "$1" in
+ start)
+ echo -n "starting $PROC:"
+ pid=`cat $pidfile 2>/dev/null`
+ if [ -n "$pid" ]; then
+ # check whether process really exists
+ # yes - don't try to start
+ [ -d /proc/$pid ] && action "already running" /bin/true && exit 1
+
+ # no - PID file is stale
+ rm -f $pidfile
+ fi
+
+ /sbin/fprobe-ulog -M -E 60 -T 168 -f pf2 -q 1000 -s 30 -D 250000
+ sleep 1
+
+ cmd=success
+ check_status && touch /var/lock/subsys/$PROC || cmd=failure
+ $cmd "$PROC startup"
+ echo
+ ;;
+
+ stop)
+ echo -n "shutting down $PROC: "
+ killproc $PROC
+ killproc $PROC
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROC
+ ;;
+
+ restart|reload)
+ $0 stop
+ $0 start
+ RETVAL=$?
+ ;;
+
+ status)
+ check_status && echo 'running' && exit 0 || \
+ echo 'not running' && exit 1
+ ;;
+
+ *)
+ echo "Usage: $0 {start|stop|restart|status}"
+ RETVAL=1
+esac
+
+exit $RETVAL
-#
-# $Id$
-#
-%define url $URL$
-
-%define name fprobe-ulog
-%define version 1.1.1
-%define taglevel 1
-
-%define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}}
-
+Name: fprobe-ulog
+Version: 1.1.1
+Release: 1
Summary: fprobe-ulog: a NetFlow probe
-Name: %{name}
-Version: %{version}
-Release: %{release}
Group: Network/Monitoring
License: GPL
-#URL: http://fprobe.sourceforge.net
+URL: http://fprobe.sourceforge.net
Source0: %{name}-%{version}.tar.bz2
Buildroot: %{_tmppath}/%{name}-buildroot
Provides: fprobe-ulog
-Vendor: PlanetLab
-Packager: PlanetLab Central <support@planet-lab.org>
-Distribution: PlanetLab %{plrelease}
-URL: %(echo %{url} | cut -d ' ' -f 2)
-
%description
fprobe-ulog - libipulog-based tool that collect network traffic data and emit
-it as NetFlow flows towards the specified collector.
+it as NetFlow flows towards the specified collector. PlanetLab vesion.
%prep
%setup -q
%build
-./configure --sbindir=%{_sbindir} --mandir=%{_mandir} --enable-uptime_trick=no $EXTRA_OPTIONS
+./configure --sbindir=/sbin --mandir=%{_mandir} --enable-uptime_trick=no $EXTRA_OPTIONS
make
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
+install -d -v %{buildroot}/etc/init.d
+install -m 755 -v fprobe-initscript %{buildroot}/etc/init.d/fprobe-ulog
gzip --best %{buildroot}%{_mandir}/man8/fprobe-ulog.8
%clean
%files
%defattr(-,root,root)
%doc AUTHORS ChangeLog NEWS README COPYING TODO
-/*
+/etc/init.d/fprobe-ulog
+/sbin/fprobe-ulog
+%{_mandir}/man8/fprobe-ulog.8.gz
+
+%post
+chkconfig --add fprobe-ulog
+chkconfig fprobe-ulog on
+if [ "$PL_BOOTCD" != "1" ] ; then
+ service fprobe-ulog start
+ fi
+
+%preun
+# 0 = erase, 1 = upgrade
+if [ "$1" -eq 0 ]; then
+ if [ "$PL_BOOTCD" != "1" ] ; then
+ service fprobe-ulog stop
+ fi
+ chkconfig fprobe-ulog off
+ chkconfig --del fprobe-ulog
+fi
+
+
+%changelog
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run aclocal-1.9
+ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
-AMTAR = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run tar
-AUTOCONF = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run autoconf
-AUTOHEADER = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run autoheader
-AUTOMAKE = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run automake-1.9
+AMTAR = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run tar
+AUTOCONF = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run autoconf
+AUTOHEADER = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run autoheader
+AUTOMAKE = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
-DATE = 2007-11-16
+DATE = 2007-11-26
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO_C =
LIBOBJS =
LIBS = -lpthread
LTLIBOBJS =
-MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run makeinfo
+MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run makeinfo
OBJEXT = o
PACKAGE = fprobe-ulog
PACKAGE_BUGREPORT =
build_os = linux-gnu
build_vendor = pc
datadir = ${prefix}/share
-exec_prefix = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/boo
+exec_prefix = ${prefix}
host = i686-pc-linux-gnu
host_alias =
host_cpu = i686
host_vendor = pc
includedir = ${prefix}/include
infodir = ${prefix}/info
-install_sh = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/install-sh
+install_sh = /home/sapan/Projects/planetlab/4.1/fprobe/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
-prefix = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/boo
+prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
$Id: fprobe-ulog.c,v 1.1.2.4 2005/01/30 09:06:19 sla Exp $
- 7/11/2007 Sapan Bhatia <sapanb@cs.princeton.edu>
+ Sapan Bhatia <sapanb@cs.princeton.edu>
- Added data collection (-f) functionality, xid support in the header and log file
- rotation.
+ 7/11/2007 Added data collection (-f) functionality, xid support in the header and log file
+ rotation.
+
+ 15/11/2007 Added check to make sure fprobe doesn't overflow the disk. Also added a test facility.
+
*/
#include <common.h>
/* statfs() */
-#include <sys/statfs.h>
+#include <sys/vfs.h>
#include <libipulog/libipulog.h>
struct ipulog_handle {
#include <hash.h>
#include <mem.h>
+#define PIDFILE "/var/log/fprobe-ulog.pid"
+
enum {
aflag,
Bflag,
cur_uptime = getuptime_minutes(&now);
- if (fstatfs(cur_fd, &statfs) && cur_fd!=START_VALUE) {
- my_log(LOG_ERR, "PANIC! Can't stat disk to calculate free blocks");
- }
- else {
- if (min_free && (statfs.f_bfree < min_free))
- switch(cur_epoch) {
- case 0: /* Uh oh. Our first file filled up all of the free space. Just bail out. */
- my_log(LOG_ERR, "The first epoch filled up all the free space on disk. Bailing out.");
- exit(1);
- default:
- my_log(LOG_INFO, "Disk almost full. I'm going to drop data. Max epochs = %d\n",cur_epoch);
- cur_epoch = -1;
- }
+ if (cur_fd!=START_VALUE) {
+ if (fstatfs(cur_fd, &statfs) == -1) {
+ my_log(LOG_ERR, "PANIC! Can't stat disk to calculate free blocks");
+ }
+ else {
+ if (min_free && (statfs.f_bavail < min_free))
+ switch(cur_epoch) {
+ case 0: /* Uh oh. Our first file filled up all of the free space. Just bail out. */
+ my_log(LOG_ERR, "The first epoch filled up all the free space on disk. Bailing out.");
+ exit(1);
+ default:
+ my_log(LOG_INFO, "Disk almost full (%u free blocks). I'm going to drop data. Max epochs = %d\n",statfs.f_bavail,cur_epoch);
+ cur_epoch = -1;
+ }
+ }
}
/* Epoch length in minutes */
return 0;
}
+/* Copied out of CoDemux */
+
+static int init_daemon() {
+ pid_t pid;
+ FILE *pidfile;
+
+ pidfile = fopen(PIDFILE, "w");
+ if (pidfile == NULL) {
+ my_log(LOG_ERR, "%s creation failed\n", PIDFILE);
+ }
+
+ if ((pid = fork()) < 0) {
+ fclose(pidfile);
+ my_log(LOG_ERR, "Could not fork!\n");
+ return(-1);
+ }
+ else if (pid != 0) {
+ /* i'm the parent, writing down the child pid */
+ fprintf(pidfile, "%u\n", pid);
+ fclose(pidfile);
+ exit(0);
+ }
+
+ /* close the pid file */
+ fclose(pidfile);
+
+ /* routines for any daemon process
+ 1. create a new session
+ 2. change directory to the root
+ 3. change the file creation permission
+ */
+ setsid();
+ chdir("/root");
+ umask(0);
+
+ return(0);
+}
+
int main(int argc, char **argv)
{
char errpbuf[512];
/* Daemonize (if log destination stdout-free) */
my_log_open(ident, verbosity, log_dest);
+
+ init_daemon();
+
if (!(log_dest & 2)) {
/* Crash-proofing - Sapan*/
while (1) {
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run aclocal-1.9
+ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
-AMTAR = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run tar
-AUTOCONF = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run autoconf
-AUTOHEADER = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run autoheader
-AUTOMAKE = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run automake-1.9
+AMTAR = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run tar
+AUTOCONF = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run autoconf
+AUTOHEADER = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run autoheader
+AUTOMAKE = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CPP = gcc -E
CPPFLAGS =
CYGPATH_W = echo
-DATE = 2007-11-16
+DATE = 2007-11-26
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO_C =
LIBOBJS =
LIBS = -lpthread
LTLIBOBJS =
-MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run makeinfo
+MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/4.1/fprobe/missing --run makeinfo
OBJEXT = o
PACKAGE = fprobe-ulog
PACKAGE_BUGREPORT =
build_os = linux-gnu
build_vendor = pc
datadir = ${prefix}/share
-exec_prefix = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/boo
+exec_prefix = ${prefix}
host = i686-pc-linux-gnu
host_alias =
host_cpu = i686
host_vendor = pc
includedir = ${prefix}/include
infodir = ${prefix}/info
-install_sh = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/install-sh
+install_sh = /home/sapan/Projects/planetlab/4.1/fprobe/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
-prefix = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/boo
+prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com