]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-sysdeps-unix.c: Fix unused function warning on FreeBSD
authorAlex Richardson <arichardson@FreeBSD.org>
Mon, 8 Aug 2022 19:17:12 +0000 (19:17 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 10 Aug 2022 11:18:20 +0000 (11:18 +0000)
The function close_ignore_error() is only used in some cases. To avoid
duplicating the #ifdef condition, this patch moves the check just before
the definition of _dbus_close_all().

dbus/dbus-sysdeps-unix.c

index 252798e3649bab72776a0abac981cad36de8ddfe..b702d93524cfccbddba0f374f59a34c95c45aefe 100644 (file)
@@ -4741,12 +4741,6 @@ _dbus_socket_can_pass_unix_fd (DBusSocket fd)
 #endif
 }
 
-static void
-close_ignore_error (int fd)
-{
-  close (fd);
-}
-
 /*
  * Similar to Solaris fdwalk(3), but without the ability to stop iteration,
  * and may call func for integers that are not actually valid fds.
@@ -4812,6 +4806,25 @@ act_on_fds_3_and_up (void (*func) (int fd))
     func (i);
 }
 
+/* Some library implementations of closefrom() are not async-signal-safe,
+ * and we call _dbus_close_all() after forking, so we only do this on
+ * operating systems where we know that closefrom() is a system call */
+#if defined(HAVE_CLOSEFROM) && ( \
+    defined(__FreeBSD__) || \
+    defined(__NetBSD__) || \
+    defined(__OpenBSD__) || \
+    defined(__sun__) && defined(F_CLOSEFROM) \
+)
+#define CLOSEFROM_SIGNAL_SAFE 1
+#else
+#define CLOSEFROM_SIGNAL_SAFE 0
+static void
+close_ignore_error (int fd)
+{
+  close (fd);
+}
+#endif
+
 /**
  * Closes all file descriptors except the first three (i.e. stdin,
  * stdout, stderr).
@@ -4824,15 +4837,7 @@ _dbus_close_all (void)
     return;
 #endif
 
-  /* Some library implementations of closefrom() are not async-signal-safe,
-   * and we call _dbus_close_all() after forking, so we only do this on
-   * operating systems where we know that closefrom() is a system call */
-#if defined(HAVE_CLOSEFROM) && ( \
-    defined(__FreeBSD__) || \
-    defined(__NetBSD__) || \
-    defined(__OpenBSD__) || \
-    defined(__sun__) && defined(F_CLOSEFROM) \
-)
+#if CLOSEFROM_SIGNAL_SAFE
   closefrom (3);
 #else
   act_on_fds_3_and_up (close_ignore_error);