Don't call this function when logging not enabled.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 31 +++++++++++++++++--------------
src/hostmon.c | 22 +++++++++++++---------
src/ifstats.c | 23 +++++++++++++----------
src/itrafmon.c | 48 ++++++++++++++++++++++++------------------------
src/log.c | 4 ++--
src/log.h | 2 +-
src/pktsize.c | 20 ++++++++++++--------
src/serv.c | 21 ++++++++++++---------
8 files changed, 94 insertions(+), 77 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index 015621c..e3de9a0 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -365,12 +365,13 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
if (logfile == NULL)
logging = 0;
}
- if (logging)
+ if (logging) {
signal(SIGUSR1, rotate_dstat_log);
- rotate_flag = 0;
- writelog(logging, logfile,
- "******** Detailed interface statistics started ********");
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** Detailed interface statistics started ********");
+ }
printdetlabels(statwin);
printdetails(&ifcounts, statwin);
@@ -478,15 +479,18 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
if (pps_out > peakpps_out)
peakpps_out = pps_out;
}
- if ((now - startlog) >= options->logspan && logging) {
- writedstatlog(iface, options->actmode,
- peakactivity, peakpps, peakactivity_in,
- peakpps_in, peakactivity_out, peakpps_out,
- &ifcounts,
- time(NULL) - statbegin,
- logfile);
-
- startlog = now;
+ if (logging) {
+ check_rotate_flag(&logfile);
+ if ((now - startlog) >= options->logspan) {
+ writedstatlog(iface, options->actmode,
+ peakactivity, peakpps,
+ peakactivity_in, peakpps_in,
+ peakactivity_out, peakpps_out,
+ &ifcounts, time(NULL) - statbegin,
+ logfile);
+
+ startlog = now;
+ }
}
if (((options->updrate == 0)
@@ -499,7 +503,6 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
updtime_usec = unow;
updtime = now;
}
- check_rotate_flag(&logfile, logging);
if ((facilitytime != 0)
&& (((now - statbegin) / 60) >= facilitytime))
diff --git a/src/hostmon.c b/src/hostmon.c
index 186617b..e9f3dc0 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -848,12 +848,14 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
if (logfile == NULL)
logging = 0;
}
- if (logging)
+ if (logging) {
signal(SIGUSR1, rotate_lanlog);
- rotate_flag = 0;
- writelog(logging, logfile,
- "******** LAN traffic monitor started ********");
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** LAN traffic monitor started ********");
+ }
+
leaveok(table.tabwin, TRUE);
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
@@ -884,10 +886,13 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime,
char *ifptr,
idx);
starttime = now;
}
- if (((now - startlog) >= options->logspan) && (logging)) {
- writeethlog(table.head, options->actmode,
- now - statbegin, logfile);
- startlog = now;
+ if (logging) {
+ check_rotate_flag(&logfile);
+ if ((now - startlog) >= options->logspan) {
+ writeethlog(table.head, options->actmode,
+ now - statbegin, logfile);
+ startlog = now;
+ }
}
if (((options->updrate != 0)
&& (now - updtime >= options->updrate))
@@ -898,7 +903,6 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char
*ifptr,
updtime = now;
updtime_usec = unow;
}
- check_rotate_flag(&logfile, logging);
if ((facilitytime != 0)
&& (((now - statbegin) / 60) >= facilitytime))
diff --git a/src/ifstats.c b/src/ifstats.c
index fe3cadd..8b336bc 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -498,12 +498,13 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
if (logfile == NULL)
logging = 0;
}
- if (logging)
+ if (logging) {
signal(SIGUSR1, rotate_gstat_log);
- rotate_flag = 0;
- writelog(logging, logfile,
- "******** General interface statistics started ********");
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** General interface statistics started ********");
+ }
preparescreen(&table);
@@ -539,11 +540,14 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
starttime = now;
start_tv = tv;
}
- if (((now - startlog) >= options->logspan) && (logging)) {
- writegstatlog(&table, options->actmode,
- time(NULL) - statbegin,
- logfile);
- startlog = now;
+ if (logging) {
+ check_rotate_flag(&logfile);
+ if ((now - startlog) >= options->logspan) {
+ writegstatlog(&table, options->actmode,
+ time(NULL) - statbegin,
+ logfile);
+ startlog = now;
+ }
}
if (((options->updrate != 0)
&& (now - updtime >= options->updrate))
@@ -554,7 +558,6 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
updtime = now;
updtime_usec = unow;
}
- check_rotate_flag(&logfile, logging);
if ((facilitytime != 0)
&& (((now - statbegin) / 60) >= facilitytime))
diff --git a/src/itrafmon.c b/src/itrafmon.c
index e26f6b9..ebe053b 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -709,20 +709,21 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
}
}
- if (logging)
+ if (logging) {
opentlog(&logfile, current_logfile);
- if (logfile == NULL)
- logging = 0;
-
- if (logging)
+ if (logfile == NULL)
+ logging = 0;
+ }
+ if (logging) {
signal(SIGUSR1, rotate_ipmon_log);
- setprotoent(1);
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** IP traffic monitor started ********");
+ }
- rotate_flag = 0;
- writelog(logging, logfile,
- "******** IP traffic monitor started ********");
+ setprotoent(1);
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(fd == -1) {
@@ -811,7 +812,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
/*
* Close and rotate log file if signal was received
*/
- if ((rotate_flag == 1) && (logging)) {
+ if (logging && (rotate_flag == 1)) {
announce_rotate_prepare(logfile);
write_tcp_unclosed(logging, logfile, &table);
rotate_logfile(&logfile, target_logname);
@@ -1184,9 +1185,9 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
* updateentry()
*/
- if ((tcpentry->pcount == 1)
- && (!(tcpentry->stat & FLAG_RST))
- && (logging)) {
+ if (logging
+ && (tcpentry->pcount == 1)
+ && (!(tcpentry->stat & FLAG_RST))) {
strcpy(msgstring, "first packet");
if (transpacket->syn)
strcat(msgstring, " (SYN)");
@@ -1284,8 +1285,6 @@ err:
srpromisc(0, promisc_list);
destroy_promisc_list(&promisc_list);
}
- adjust_instance_count(PROCCOUNTFILE, -1);
- adjust_instance_count(ITRAFMONCOUNTFILE, -1);
attrset(STDATTR);
mvprintw(0, COLS - 20, " ");
@@ -1304,15 +1303,16 @@ err:
destroytcptable(&table);
destroyothptable(&othptbl);
pkt_cleanup();
- writelog(logging, logfile,
- "******** IP traffic monitor stopped ********\n");
- unmark_facility(IPMONIDFILE, ifptr);
- if (logfile != NULL)
- fclose(logfile);
-
- strcpy(current_logfile, "");
- signal(SIGUSR1, SIG_DFL);
+ if (logging) {
+ signal(SIGUSR1, SIG_DFL);
+ writelog(logging, logfile,
+ "******** IP traffic monitor stopped ********\n");
+ fclose(logfile);
+ strcpy(current_logfile, "");
+ }
- return;
+ adjust_instance_count(PROCCOUNTFILE, -1);
+ adjust_instance_count(ITRAFMONCOUNTFILE, -1);
+ unmark_facility(IPMONIDFILE, ifptr);
}
diff --git a/src/log.c b/src/log.c
index 2a3d12d..764c73b 100644
--- a/src/log.c
+++ b/src/log.c
@@ -143,9 +143,9 @@ void announce_rotate_complete(FILE * fd)
writelog(1, fd, "***** Logfile reopened *****");
}
-void check_rotate_flag(FILE ** logfile, int logging)
+void check_rotate_flag(FILE ** logfile)
{
- if ((rotate_flag == 1) && (logging)) {
+ if (rotate_flag == 1) {
announce_rotate_prepare(*logfile);
rotate_logfile(logfile, target_logname);
announce_rotate_complete(*logfile);
diff --git a/src/log.h b/src/log.h
index bb93de3..aa786f7 100644
--- a/src/log.h
+++ b/src/log.h
@@ -16,7 +16,7 @@ void writelog(int logging, FILE * fd, char *msg);
void genatime(time_t now, char *atime);
void write_daemon_err(char *msg, va_list vararg);
void rotate_logfile(FILE ** fd, char *name);
-void check_rotate_flag(FILE ** fd, int logging);
+void check_rotate_flag(FILE ** fd);
void announce_rotate_prepare(FILE * fd);
void announce_rotate_complete(FILE * fd);
diff --git a/src/pktsize.c b/src/pktsize.c
index 4715eff..7dfcb92 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -234,11 +234,13 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname,
if (logfile == NULL)
logging = 0;
}
- if (logging)
+ if (logging) {
signal(SIGUSR1, rotate_size_log);
- writelog(logging, logfile,
- "******** Packet size distribution facility started ********");
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** Packet size distribution facility started ********");
+ }
exitloop = 0;
gettimeofday(&tv, NULL);
@@ -284,12 +286,14 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname,
borderwin);
timeint = now;
}
- if ((now - startlog >= options->logspan) && (logging)) {
- write_size_log(brackets, now - starttime, ifname, mtu,
- logfile);
- startlog = now;
+ if (logging) {
+ check_rotate_flag(&logfile);
+ if ((now - startlog >= options->logspan)) {
+ write_size_log(brackets, now - starttime,
+ ifname, mtu, logfile);
+ startlog = now;
+ }
}
- check_rotate_flag(&logfile, logging);
if ((facilitytime != 0)
&& (((now - starttime) / 60) >= facilitytime))
diff --git a/src/serv.c b/src/serv.c
index 9a7e4e8..7bbcdf7 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -890,12 +890,13 @@ void servmon(char *ifname, struct porttab *ports, const struct
OPTIONS *options,
if (logfile == NULL)
logging = 0;
}
- if (logging)
+ if (logging) {
signal(SIGUSR1, rotate_serv_log);
- rotate_flag = 0;
- writelog(logging, logfile,
- "******** TCP/UDP service monitor started ********");
+ rotate_flag = 0;
+ writelog(logging, logfile,
+ "******** TCP/UDP service monitor started ********");
+ }
//isdnfd = -1;
exitloop = 0;
@@ -929,10 +930,13 @@ void servmon(char *ifname, struct porttab *ports, const struct
OPTIONS *options,
list.borderwin);
timeint = now;
}
- if (((now - startlog) >= options->logspan) && (logging)) {
- writeutslog(list.head, now - starttime,
- options->actmode, logfile);
- startlog = now;
+ if (logging) {
+ check_rotate_flag(&logfile);
+ if ((now - startlog) >= options->logspan) {
+ writeutslog(list.head, now - starttime,
+ options->actmode, logfile);
+ startlog = now;
+ }
}
if (list.barptr != NULL) {
@@ -952,7 +956,6 @@ void servmon(char *ifname, struct porttab *ports, const struct OPTIONS
*options,
updtime = now;
updtime_usec = unow;
}
- check_rotate_flag(&logfile, logging);
if ((facilitytime != 0)
&& (((now - starttime) / 60) >= facilitytime))
--
1.7.8.4