From 433291d60a8bfd9985cc0676210bba094b199049 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20K=C3=A1cha?= <ph@cesnet.cz>
Date: Wed, 23 Feb 2022 15:25:45 +0100
Subject: [PATCH] Close descriptors later to catch additional potential errors

---
 contrib/connectors/hp-labrea/labrea-idea.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/connectors/hp-labrea/labrea-idea.py b/contrib/connectors/hp-labrea/labrea-idea.py
index f8b323a..93fb9da 100755
--- a/contrib/connectors/hp-labrea/labrea-idea.py
+++ b/contrib/connectors/hp-labrea/labrea-idea.py
@@ -432,10 +432,6 @@ def daemonize(
                 os.close(fd)
             except Exception:
                 pass
-    # Redirect stdin, stdout, stderr to /dev/null
-    devnull = os.open(os.devnull, os.O_RDWR)
-    for fd in range(3):
-        os.dup2(devnull, fd)
     # PID file
     if pidfile is not None:
         pidd = os.open(pidfile, os.O_RDWR | os.O_CREAT | os.O_EXCL | os.O_TRUNC)
@@ -449,6 +445,10 @@ def daemonize(
                 os.unlink(pidfile)
             except Exception:
                 pass
+    # Redirect stdin, stdout, stderr to /dev/null
+    devnull = os.open(os.devnull, os.O_RDWR)
+    for fd in range(3):
+        os.dup2(devnull, fd)
 
 
 def save_events(aggr, filer):
-- 
GitLab