]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap-file: don't kill engine in unix socket mode 260/head
authorEric Leblond <eric@regit.org>
Thu, 17 Jan 2013 10:12:27 +0000 (11:12 +0100)
committerEric Leblond <eric@regit.org>
Mon, 21 Jan 2013 07:34:29 +0000 (08:34 +0100)
This patch updates the cleaning code to avoid to exit from suricata
in unix socket mode when a invalid pcap is given.

src/source-pcap-file.c

index 46e977602211fd417f66c10291d3df261377c85b..c626e80bd3ca137dd4e52cf708f2ffe31f97a5c6 100644 (file)
@@ -182,10 +182,16 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot)
         if (unlikely(r == -1)) {
             SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s",
                        r, pcap_geterr(pcap_g.pcap_handle));
-
-            /* in the error state we just kill the engine */
-            EngineKill();
-            SCReturnInt(TM_ECODE_FAILED);
+            if (! RunModeUnixSocketIsActive()) {
+                /* in the error state we just kill the engine */
+                EngineKill();
+                SCReturnInt(TM_ECODE_FAILED);
+            } else {
+                pcap_close(pcap_g.pcap_handle);
+                pcap_g.pcap_handle = NULL;
+                UnixSocketPcapFile(TM_ECODE_DONE);
+                SCReturnInt(TM_ECODE_DONE);
+            }
         } else if (unlikely(r == 0)) {
             SCLogInfo("pcap file end of file reached (pcap err code %" PRId32 ")", r);
             if (! RunModeUnixSocketIsActive()) {
@@ -199,8 +205,15 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot)
             break;
         } else if (ptv->cb_result == TM_ECODE_FAILED) {
             SCLogError(SC_ERR_PCAP_DISPATCH, "Pcap callback PcapFileCallbackLoop failed");
-            EngineKill();
-            SCReturnInt(TM_ECODE_FAILED);
+            if (! RunModeUnixSocketIsActive()) {
+                EngineKill();
+                SCReturnInt(TM_ECODE_FAILED);
+            } else {
+                pcap_close(pcap_g.pcap_handle);
+                pcap_g.pcap_handle = NULL;
+                UnixSocketPcapFile(TM_ECODE_DONE);
+                SCReturnInt(TM_ECODE_DONE);
+            }
         }
         SCPerfSyncCountersIfSignalled(tv, 0);
     }