From: sapanb Date: Mon, 14 Jan 2008 16:06:03 +0000 (+0000) Subject: Merged 4.1 branch X-Git-Tag: fprobe-ulog-1.1.3-3~46 X-Git-Url: http://git.onelab.eu/?p=fprobe-ulog.git;a=commitdiff_plain;h=d719b3c8fdc1685b5c090c0f32f4a66a6a2c6ac7 Merged 4.1 branch git-svn-id: http://svn.planet-lab.org/svn/fprobe-ulog/trunk@7783 8c455092-636d-4788-adf5-e71def0336e8 --- diff --git a/fprobe-initscript b/fprobe-initscript new file mode 100644 index 0000000..6cbae79 --- /dev/null +++ b/fprobe-initscript @@ -0,0 +1,71 @@ +#!/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 diff --git a/fprobe-ulog.spec b/fprobe-ulog.spec index 18a05eb..234da13 100644 --- a/fprobe-ulog.spec +++ b/fprobe-ulog.spec @@ -1,44 +1,30 @@ -# -# $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 -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 @@ -47,4 +33,26 @@ rm -rf %{buildroot} %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 diff --git a/src/Makefile b/src/Makefile index 163ffff..ef3c21a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -79,13 +79,13 @@ ETAGS = etags 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 @@ -93,7 +93,7 @@ CFLAGS = -g -O2 -D_BSD_SOURCE -D_REENTRANT -DWALL -W -Wall CPP = gcc -E CPPFLAGS = CYGPATH_W = echo -DATE = 2007-11-16 +DATE = 2007-11-26 DEFS = -DHAVE_CONFIG_H DEPDIR = .deps ECHO_C = @@ -109,7 +109,7 @@ LDFLAGS = 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 = @@ -140,7 +140,7 @@ build_cpu = i686 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 @@ -148,14 +148,14 @@ host_os = linux-gnu 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 diff --git a/src/fprobe-ulog.c b/src/fprobe-ulog.c index 5df381b..c825f5a 100644 --- a/src/fprobe-ulog.c +++ b/src/fprobe-ulog.c @@ -6,10 +6,13 @@ $Id: fprobe-ulog.c,v 1.1.2.4 2005/01/30 09:06:19 sla Exp $ - 7/11/2007 Sapan Bhatia + Sapan Bhatia - 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 @@ -31,7 +34,7 @@ /* statfs() */ -#include +#include #include struct ipulog_handle { @@ -92,6 +95,8 @@ struct ipulog_handle { #include #include +#define PIDFILE "/var/log/fprobe-ulog.pid" + enum { aflag, Bflag, @@ -422,19 +427,21 @@ unsigned get_log_fd(char *fname, int cur_fd) { 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 */ @@ -1244,6 +1251,44 @@ void *cap_thread() 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]; @@ -1492,6 +1537,9 @@ bad_collector: /* Daemonize (if log destination stdout-free) */ my_log_open(ident, verbosity, log_dest); + + init_daemon(); + if (!(log_dest & 2)) { /* Crash-proofing - Sapan*/ while (1) { diff --git a/src/libipulog/Makefile b/src/libipulog/Makefile index 0230e1d..6ed9c58 100644 --- a/src/libipulog/Makefile +++ b/src/libipulog/Makefile @@ -67,13 +67,13 @@ DIST_SOURCES = $(libipulog_a_SOURCES) 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 @@ -81,7 +81,7 @@ CFLAGS = -g -O2 -D_BSD_SOURCE -D_REENTRANT -DWALL -W -Wall CPP = gcc -E CPPFLAGS = CYGPATH_W = echo -DATE = 2007-11-16 +DATE = 2007-11-26 DEFS = -DHAVE_CONFIG_H DEPDIR = .deps ECHO_C = @@ -97,7 +97,7 @@ LDFLAGS = 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 = @@ -128,7 +128,7 @@ build_cpu = i686 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 @@ -136,14 +136,14 @@ host_os = linux-gnu 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