summaryrefslogtreecommitdiffstats
path: root/output/pcap/ulogd_output_PCAP.c
diff options
context:
space:
mode:
Diffstat (limited to 'output/pcap/ulogd_output_PCAP.c')
-rw-r--r--output/pcap/ulogd_output_PCAP.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/output/pcap/ulogd_output_PCAP.c b/output/pcap/ulogd_output_PCAP.c
index e7798f2..19ce47f 100644
--- a/output/pcap/ulogd_output_PCAP.c
+++ b/output/pcap/ulogd_output_PCAP.c
@@ -220,33 +220,26 @@ static int append_create_outfile(struct ulogd_pluginstance *upi)
{
struct pcap_instance *pi = (struct pcap_instance *) &upi->private;
char *filename = upi->config_kset->ces[0].u.string;
- struct stat st_dummy;
- int exist = 0;
-
- if (stat(filename, &st_dummy) == 0 && st_dummy.st_size > 0)
- exist = 1;
-
- if (!exist) {
- pi->of = fopen(filename, "w");
- if (!pi->of) {
- ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
- filename,
- strerror(errno));
- return -EPERM;
- }
- if (!write_pcap_header(pi)) {
- ulogd_log(ULOGD_ERROR, "can't write pcap header: %s\n",
- strerror(errno));
- return -ENOSPC;
- }
- } else {
- pi->of = fopen(filename, "a");
- if (!pi->of) {
- ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
- filename,
- strerror(errno));
- return -EPERM;
- }
+ struct stat st_of;
+ FILE *of;
+
+ of = fopen(filename, "a");
+ if (!of) {
+ ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
+ filename,
+ strerror(errno));
+ return -EPERM;
+ }
+
+ if (pi->of)
+ fclose(pi->of);
+ pi->of = of;
+
+ if (fstat(fileno(pi->of), &st_of) == 0 && st_of.st_size == 0 &&
+ !write_pcap_header(pi)) {
+ ulogd_log(ULOGD_ERROR, "can't write pcap header: %s\n",
+ strerror(errno));
+ return -ENOSPC;
}
return 0;
@@ -254,12 +247,9 @@ static int append_create_outfile(struct ulogd_pluginstance *upi)
static void signal_pcap(struct ulogd_pluginstance *upi, int signal)
{
- struct pcap_instance *pi = (struct pcap_instance *) &upi->private;
-
switch (signal) {
case SIGHUP:
ulogd_log(ULOGD_NOTICE, "reopening capture file\n");
- fclose(pi->of);
append_create_outfile(upi);
break;
default: