lib/util: use RUNNING_ON_VALGRIND to check if valgrind is used
authorStefan Metzmacher <metze@samba.org>
Wed, 31 May 2023 10:09:09 +0000 (12:09 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 1 Jun 2023 07:20:31 +0000 (07:20 +0000)
We should not skip all of close_low_fd() just because we
detected valgrind headers at build time.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/util/close_low_fd.c

index 5e74918711374865a68f4a6f7d75ebf8a23f7494..84a690676443e0df5094eb6eff3a54cc3e0c152d 100644 (file)
 #include "system/filesys.h"
 #include "close_low_fd.h"
 
+#ifdef HAVE_VALGRIND_VALGRIND_H
+#include <valgrind/valgrind.h>
+#elif defined(HAVE_VALGRIND_H)
+#include <valgrind.h>
+#else
+#define RUNNING_ON_VALGRIND 0
+#endif
+
 _PUBLIC_ int close_low_fd(int fd)
 {
-#ifndef VALGRIND
        int ret, dev_null;
 
+       if (RUNNING_ON_VALGRIND) {
+               return 0;
+       }
+
        dev_null = open("/dev/null", O_RDWR, 0);
 
        if ((dev_null == -1) && (errno == ENFILE)) {
@@ -60,6 +71,5 @@ _PUBLIC_ int close_low_fd(int fd)
                return err;
        }
        close(dev_null);
-#endif
        return 0;
 }