From 5d58d26edf14ace33aeb42c2212435404aaecd50 Mon Sep 17 00:00:00 2001 From: sapanb Date: Thu, 8 Nov 2007 18:37:25 +0000 Subject: [PATCH] Keep track of current log file in case fprobe is restarted git-svn-id: http://svn.planet-lab.org/svn/fprobe-ulog/trunk@5710 8c455092-636d-4788-adf5-e71def0336e8 --- src/Makefile | 18 +++++++++--------- src/fprobe-ulog.c | 23 +++++++++++++++++++++-- src/libipulog/Makefile | 18 +++++++++--------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/Makefile b/src/Makefile index f2ec840..0901bc5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,7 +24,7 @@ pkglibdir = $(libdir)/fprobe-ulog pkgincludedir = $(includedir)/fprobe-ulog top_builddir = .. am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = /bin/install -c +INSTALL = /usr/bin/install -c install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c @@ -79,13 +79,13 @@ ETAGS = etags CTAGS = ctags DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run aclocal-1.9 +ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run aclocal-1.9 AMDEP_FALSE = # AMDEP_TRUE = -AMTAR = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run tar -AUTOCONF = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run autoconf -AUTOHEADER = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run autoheader -AUTOMAKE = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run automake-1.9 +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 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-10-26 +DATE = 2007-11-08 DEFS = -DHAVE_CONFIG_H DEPDIR = .deps ECHO_C = @@ -109,7 +109,7 @@ LDFLAGS = LIBOBJS = LIBS = -lpthread LTLIBOBJS = -MAKEINFO = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run makeinfo +MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run makeinfo OBJEXT = o PACKAGE = fprobe-ulog PACKAGE_BUGREPORT = @@ -148,7 +148,7 @@ host_os = linux-gnu host_vendor = pc includedir = ${prefix}/include infodir = ${prefix}/info -install_sh = /home/sapan/fprobe-ulog-1.1/install-sh +install_sh = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/install-sh libdir = ${exec_prefix}/lib libexecdir = ${exec_prefix}/libexec localstatedir = ${prefix}/var diff --git a/src/fprobe-ulog.c b/src/fprobe-ulog.c index 0d84804..5e900f3 100644 --- a/src/fprobe-ulog.c +++ b/src/fprobe-ulog.c @@ -111,6 +111,7 @@ enum { Uflag, uflag, vflag, + Wflag, Xflag, }; @@ -257,7 +258,9 @@ void usage() "-y \tAddress of the NetFlow collector\n" "-f \tFile to write data into\n" "-T \tRotate log file every n epochs\n" - "-E <[1..60]>\tSize of an epoch in minutes\n", + "-W \tSet current epoch to n. Useful when restarting fprobe\n" + "-E <[1..60]>\tSize of an epoch in minutes\n" + , VERSION, BULK_QUANTITY_MAX, bulk_quantity, sched_min, sched_max); exit(0); } @@ -367,6 +370,19 @@ inline void copy_flow(struct Flow *src, struct Flow *dst) dst->flags = src->flags; } +void update_cur_epoch_file(int n) { + int fd, len; + char snum[7]; + len=snprintf(snum,6,"%d",n); + fd = open("/tmp/fprobe_last_epoch",O_WRONLY|O_CREAT); + if (fd == -1) { + my_log(LOG_ERR, "open() failed: /tmp/fprobe_last_epoch"); + return; + } + write(fd, snum, len); + close(fd); +} + unsigned get_log_fd(char *fname, unsigned cur_fd) { struct Time now; unsigned cur_uptime; @@ -383,9 +399,10 @@ unsigned get_log_fd(char *fname, unsigned cur_fd) { close(cur_fd); snprintf(nextname,MAX_PATH_LEN,"%s.%d",fname,cur_epoch); if ((write_fd = open(nextname, O_WRONLY|O_CREAT)) < 0) { - fprintf(stderr, "open(): %s (%s)\n", nextname, strerror(errno)); + my_log(LOG_ERR, "open(): %s (%s)\n", nextname, strerror(errno)); exit(1); } + update_cur_epoch_file(cur_epoch); ret_fd = write_fd; } else @@ -754,6 +771,7 @@ void *emit_thread() peers[i].write_fd = get_log_fd(peers[i].fname, peers[i].write_fd); ret = write(peers[0].write_fd, emit_packet, size); if (ret < size) { + #if ((DEBUG) & DEBUG_E) || defined MESSAGES my_log(LOG_ERR, "write(to #%d, seq %d, flows %d, size %d) == %d: %s", i + 1, peers[i].seq, emit_count, size, ret, strerror(errno)); @@ -1212,6 +1230,7 @@ int main(int argc, char **argv) } if (parms[Uflag].count) ulog_gmask = atoi(parms[Uflag].arg); + if (parms[Wflag].count) cur_epoch = atoi(parms[Wflag].arg); if (parms[Tflag].count) log_epochs = atoi(parms[Tflag].arg); if (parms[Eflag].count) epoch_length = atoi(parms[Eflag].arg); if (parms[sflag].count) scan_interval = atoi(parms[sflag].arg); diff --git a/src/libipulog/Makefile b/src/libipulog/Makefile index 2910065..8e0ace5 100644 --- a/src/libipulog/Makefile +++ b/src/libipulog/Makefile @@ -24,7 +24,7 @@ pkglibdir = $(libdir)/fprobe-ulog pkgincludedir = $(includedir)/fprobe-ulog top_builddir = ../.. am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = /bin/install -c +INSTALL = /usr/bin/install -c install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c @@ -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/fprobe-ulog-1.1/missing --run aclocal-1.9 +ACLOCAL = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run aclocal-1.9 AMDEP_FALSE = # AMDEP_TRUE = -AMTAR = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run tar -AUTOCONF = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run autoconf -AUTOHEADER = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run autoheader -AUTOMAKE = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run automake-1.9 +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 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-10-26 +DATE = 2007-11-08 DEFS = -DHAVE_CONFIG_H DEPDIR = .deps ECHO_C = @@ -97,7 +97,7 @@ LDFLAGS = LIBOBJS = LIBS = -lpthread LTLIBOBJS = -MAKEINFO = ${SHELL} /home/sapan/fprobe-ulog-1.1/missing --run makeinfo +MAKEINFO = ${SHELL} /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/missing --run makeinfo OBJEXT = o PACKAGE = fprobe-ulog PACKAGE_BUGREPORT = @@ -136,7 +136,7 @@ host_os = linux-gnu host_vendor = pc includedir = ${prefix}/include infodir = ${prefix}/info -install_sh = /home/sapan/fprobe-ulog-1.1/install-sh +install_sh = /home/sapan/Projects/planetlab/fprobe/fprobe-ulog/install-sh libdir = ${exec_prefix}/lib libexecdir = ${exec_prefix}/libexec localstatedir = ${prefix}/var -- 2.43.0