]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-manager: prioritize the shutdown check
authorLukas Sismis <lsismis@oisf.net>
Mon, 25 Sep 2023 13:37:07 +0000 (15:37 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 30 Oct 2023 18:33:24 +0000 (19:33 +0100)
Make sure Suricata is in the running state before
you attempt to execute commands on the Unix sockets.
UnixMain is being called in an infinite loop where
TmThreadsCheckFlag(th_v, THV_KILL) is checked for the
deinit phase. However, it may take some time between
the start of Suricata's deinitialization and
the receipt of THV_KILL flag in the Unix thread.

In between this time period, the Unix manager can still
perform select() operation on the Unix socket while
the socket being already deinitialized.

Likely with a longer time span between the initial shutdown
command and actual closing of Unix sockets resulted in
an error of invalid file descriptors.

Ticket: #6272

src/unix-manager.c

index 9893553f429e76bfca0860da471f740fe09709c0..9fb5bd7935bcf372572f4f975013f01d40a5bac0 100644 (file)
@@ -628,6 +628,13 @@ static int UnixMain(UnixCommand * this)
     UnixClient *uclient;
     UnixClient *tclient;
 
+    if (suricata_ctl_flags & SURICATA_STOP) {
+        TAILQ_FOREACH_SAFE (uclient, &this->clients, next, tclient) {
+            UnixCommandClose(this, uclient->fd);
+        }
+        return 1;
+    }
+
     /* Wait activity on the socket */
     FD_ZERO(&select_set);
     FD_SET(this->socket, &select_set);
@@ -649,13 +656,6 @@ static int UnixMain(UnixCommand * this)
         return 0;
     }
 
-    if (suricata_ctl_flags & SURICATA_STOP) {
-        TAILQ_FOREACH_SAFE(uclient, &this->clients, next, tclient) {
-            UnixCommandClose(this, uclient->fd);
-        }
-        return 1;
-    }
-
     /* timeout: continue */
     if (ret == 0) {
         return 1;