Use "extern int daemonized;" in error.c and use this global in write_error()
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/error.c | 4 +++-
src/error.h | 2 +-
src/fltedit.c | 4 +---
src/fltlist.c | 2 +-
src/fltmgr.c | 8 +++-----
src/hostmon.c | 2 +-
src/ifaces.c | 4 +---
src/ifstats.c | 8 +++-----
src/instances.c | 4 +---
src/ipfilter.c | 2 --
src/itrafmon.c | 10 +++-------
src/pktsize.c | 4 ++--
src/promisc.c | 13 +++++--------
src/serv.c | 2 +-
14 files changed, 26 insertions(+), 43 deletions(-)
diff --git a/src/error.c b/src/error.c
index 5f39682..cd0e312 100644
--- a/src/error.c
+++ b/src/error.c
@@ -23,7 +23,9 @@ details.
#include "error.h"
#include "log.h"
-void write_error(char *msg, int daemonized)
+extern int daemonized;
+
+void write_error(char *msg)
{
if (daemonized)
write_daemon_err(msg);
diff --git a/src/error.h b/src/error.h
index 1e57c3d..0b070f6 100644
--- a/src/error.h
+++ b/src/error.h
@@ -1,6 +1,6 @@
#ifndef IPTRAF_NG_ERROR_H
#define IPTRAF_NG_ERROR_H
-void write_error(char *msg, int daemonized);
+void write_error(char *msg);
#endif /* IPTRAF_NG_ERROR_H */
diff --git a/src/fltedit.c b/src/fltedit.c
index 0566005..b8accac 100644
--- a/src/fltedit.c
+++ b/src/fltedit.c
@@ -29,8 +29,6 @@ details.
#include "error.h"
#include "cidr.h"
-extern int daemonized;
-
void init_filter_table(struct filterlist *fl)
{
fl->head = fl->tail = NULL;
@@ -56,7 +54,7 @@ int loadfilter(char *filename, struct filterlist *fl, int resolve)
if (pfd < 0) {
memset(err_msg, 0, 80);
snprintf(err_msg, 80, "Error opening IP filter data file");
- write_error(err_msg, daemonized);
+ write_error(err_msg);
fl->head = NULL;
return 1;
}
diff --git a/src/fltlist.c b/src/fltlist.c
index 15a93d1..c869755 100644
--- a/src/fltlist.c
+++ b/src/fltlist.c
@@ -23,7 +23,7 @@ int loadfilter(char *filename, struct filterlist *fl, int resolve)
if (pfd < 0) {
memset(err_msg, 0, 80);
snprintf(err_msg, 80, "Error opening IP filter data file");
- write_error(err_msg, daemonized);
+ write_error(err_msg);
fl->head = NULL;
return 1;
}
diff --git a/src/fltmgr.c b/src/fltmgr.c
index 25ddcee..d9f7b38 100644
--- a/src/fltmgr.c
+++ b/src/fltmgr.c
@@ -27,8 +27,6 @@ details.
#include "instances.h"
#include "error.h"
-extern int daemonized;
-
void makestdfiltermenu(struct MENU *menu)
{
tx_initmenu(menu, 9, 31, (LINES - 8) / 2, (COLS - 31) / 2 + 15, BOXATTR,
@@ -75,9 +73,9 @@ void clear_flt_tag(void)
void listfileerr(int code)
{
if (code == 1)
- write_error("Error loading filter list file", daemonized);
+ write_error("Error loading filter list file");
else
- write_error("Error writing filter list file", daemonized);
+ write_error("Error writing filter list file");
}
unsigned long int nametoaddr(char *ascname, int *err)
@@ -98,7 +96,7 @@ unsigned long int nametoaddr(char *ascname, int *err)
bcopy((he->h_addr_list)[0], &result, he->h_length);
else {
snprintf(imsg, 45, "Unable to resolve %s", ascname);
- write_error(imsg, daemonized);
+ write_error(imsg);
*err = 1;
return (-1);
}
diff --git a/src/hostmon.c b/src/hostmon.c
index 4c87890..53d1d8e 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -716,7 +716,7 @@ void hostmon(const struct OPTIONS *options, int facilitytime, char
*ifptr,
snprintf(msgstring, 80,
"LAN station monitor already running on %s",
gen_iface_msg(ifptr));
- write_error(msgstring, daemonized);
+ write_error(msgstring);
return;
}
diff --git a/src/ifaces.c b/src/ifaces.c
index 2e6e780..c1e0be5 100644
--- a/src/ifaces.c
+++ b/src/ifaces.c
@@ -21,8 +21,6 @@ details.
#include "error.h"
-extern int daemonized;
-
char *ltrim(char *buf)
{
while ((*buf == ' ') || (*buf == '\t'))
@@ -99,7 +97,7 @@ int iface_up(char *iface)
void err_iface_down(void)
{
- write_error("Specified interface not active", daemonized);
+ write_error("Specified interface not active");
}
void isdn_iface_check(int *fd, char *ifname)
diff --git a/src/ifstats.c b/src/ifstats.c
index 01e7343..b7405e9 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -209,8 +209,7 @@ void destroyiflist(struct iflist *list)
void no_ifaces_error(void)
{
write_error
- ("No active interfaces. Check their status or the /proc filesystem",
- daemonized);
+ ("No active interfaces. Check their status or the /proc filesystem");
}
void updaterates(struct iftab *table, int unit, time_t starttime, time_t now,
@@ -425,8 +424,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate
*ofilter,
mark_facility(GSTATIDFILE, "general interface statistics", "");
else {
write_error
- ("General interface stats already active in another process",
- daemonized);
+ ("General interface stats already active in another process");
return;
}
@@ -807,7 +805,7 @@ void detstats(char *iface, const struct OPTIONS *options, int
facilitytime,
snprintf(err_msg, 80,
"Detailed interface stats already monitoring %s",
iface);
- write_error(err_msg, daemonized);
+ write_error(err_msg);
return;
}
diff --git a/src/instances.c b/src/instances.c
index 265470f..2f4150c 100644
--- a/src/instances.c
+++ b/src/instances.c
@@ -22,8 +22,6 @@ details.
#include "dirs.h"
#include "instances.h"
-extern int daemonized;
-
void gen_lockfile_name(char *tagfile, char *iface, char *result)
{
if (iface == NULL)
@@ -43,7 +41,7 @@ void mark_facility(char *tagfile, char *facility, char *iface)
if (fd < 0) {
snprintf(errstring, 80, "Warning: unable to lock %s on %s",
facility, iface);
- write_error(errstring, daemonized);
+ write_error(errstring);
}
close(fd);
}
diff --git a/src/ipfilter.c b/src/ipfilter.c
index 518cf45..5bc6545 100644
--- a/src/ipfilter.c
+++ b/src/ipfilter.c
@@ -32,8 +32,6 @@ details.
#include "parseproto.h"
#include "cidr.h"
-extern int daemonized;
-
void gethostparams(struct hostparams *data, char *init_saddr, char *init_smask,
char *init_sport1, char *init_sport2, char *init_daddr,
char *init_dmask, char *init_dport1, char *init_dport2,
diff --git a/src/itrafmon.c b/src/itrafmon.c
index c541101..b841e20 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -520,9 +520,7 @@ int checkrvnamed(void)
die("unable execvp() rvnamed-ng");
} else if (cpid == -1) {
- write_error
- ("Can't spawn new process; lookups will block",
- daemonized);
+ write_error ("Can't spawn new process; lookups will block");
return 0;
} else {
while (waitpid(cpid, &cstat, 0) < 0)
@@ -530,9 +528,7 @@ int checkrvnamed(void)
break;
if (WEXITSTATUS(cstat) == 1) {
- write_error
- ("Can't start rvnamed; lookups will block",
- daemonized);
+ write_error ("Can't start rvnamed; lookups will block");
return 0;
} else {
sleep(1);
@@ -660,7 +656,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
snprintf(msgstring, 80,
"IP Traffic Monitor already listening on %s",
gen_iface_msg(ifptr));
- write_error(msgstring, daemonized);
+ write_error(msgstring);
return;
}
diff --git a/src/pktsize.c b/src/pktsize.c
index dcff0ee..5d01942 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -65,7 +65,7 @@ int initialize_brackets(char *ifname, struct ifstat_brackets *brackets,
close(fd);
if (istat < 0) {
- write_error("Unable to obtain interface MTU", daemonized);
+ write_error("Unable to obtain interface MTU");
return 1;
}
*interval = ifr.ifr_mtu / 20; /* There are 20 packet size brackets */
@@ -180,7 +180,7 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname,
else {
snprintf(msgstring, 80,
"Packet sizes already being monitored on %s", ifname);
- write_error(msgstring, daemonized);
+ write_error(msgstring);
return;
}
diff --git a/src/promisc.c b/src/promisc.c
index 167695c..f20f028 100644
--- a/src/promisc.c
+++ b/src/promisc.c
@@ -31,7 +31,6 @@ details.
#define PROMISC_MSG_MAX 80
-extern int daemonized;
extern int accept_unsupported_interfaces;
void init_promisc_list(struct promisc_states **list)
@@ -89,7 +88,7 @@ void init_promisc_list(struct promisc_states **list)
sprintf(err_msg,
"Unable to obtain interface parameters for %s",
buf);
- write_error(err_msg, daemonized);
+ write_error(err_msg);
ptmp->params.state_valid = 0;
} else {
ptmp->params.saved_state =
@@ -117,7 +116,7 @@ void save_promisc_list(struct promisc_states *list)
fd = open(PROMISCLISTFILE, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0) {
- write_error("Unable to save interface flags", daemonized);
+ write_error("Unable to save interface flags");
return;
}
@@ -143,8 +142,7 @@ void load_promisc_list(struct promisc_states **list)
fd = open(PROMISCLISTFILE, O_RDONLY);
if (fd < 0) {
- write_error("Unable to retrieve saved interface flags",
- daemonized);
+ write_error("Unable to retrieve saved interface flags");
*list = NULL;
return;
}
@@ -185,8 +183,7 @@ void srpromisc(int mode, struct promisc_states *list)
fd = socket(PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- write_error("Unable to open socket for flag change",
- daemonized);
+ write_error("Unable to open socket for flag change");
return;
}
@@ -213,7 +210,7 @@ void srpromisc(int mode, struct promisc_states *list)
if (istat < 0) {
sprintf(fullmsg, "Promisc change failed for %s",
ptmp->params.ifname);
- write_error(fullmsg, daemonized);
+ write_error(fullmsg);
}
}
ptmp = ptmp->next_entry;
diff --git a/src/serv.c b/src/serv.c
index ecc4af5..f7fcb7d 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -750,7 +750,7 @@ void servmon(char *ifname, struct porttab *ports, const struct OPTIONS
*options,
else {
snprintf(msgstring, 80, "TCP/UDP monitor already running on %s",
ifname);
- write_error(msgstring, daemonized);
+ write_error(msgstring);
return;
}
--
1.7.8.4