[pacman-dev] [PATCH 3/4] Add an include for signal.h when needed

Mark Weiman mark.weiman at markzz.com
Fri Apr 16 19:42:08 UTC 2021


On Linux, signal.h is not required to have access to the signal
constants. On FreeBSD, this is not the case and requires signal.h to be
explicitly included.

This patch checks if SIGINT can be used without signal.h and if not,
make sure its included in the files that need it.

Signed-off-by: Mark Weiman <mark.weiman at markzz.com>
---
 lib/libalpm/util.c | 4 ++++
 meson.build        | 6 ++++++
 src/pacman/conf.c  | 4 ++++
 3 files changed, 14 insertions(+)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index b386fde6..d2a688a2 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -34,6 +34,10 @@
 #include <fnmatch.h>
 #include <poll.h>
 
+#if defined(INCLUDE_SIGNAL_H)
+#include <signal.h>
+#endif
+
 /* libarchive */
 #include <archive.h>
 #include <archive_entry.h>
diff --git a/meson.build b/meson.build
index 14b3381a..0dc0d612 100644
--- a/meson.build
+++ b/meson.build
@@ -189,6 +189,12 @@ if not conf.get('HAVE_STRUCT_STATVFS_F_MNTONNAME', false) and conf.get('HAVE_STR
   conf.set('FSSTATSTYPE', 'struct statfs')
 endif
 
+signal_code = '''void foo() { int sig = SIGINT; }'''
+signal_test = cc.compiles(signal_code, name : 'test if signal.h is not needed')
+if not signal_test
+  conf.set('INCLUDE_SIGNAL_H', true)
+endif
+
 if get_option('debug')
   extra_cflags = [
     '-Wcast-align',
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index a4f2ba35..fcb1ccd8 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -32,6 +32,10 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#if defined(INCLUDE_SIGNAL_H)
+#include <signal.h>
+#endif
+
 /* pacman */
 #include "conf.h"
 #include "ini.h"
-- 
2.31.1


More information about the pacman-dev mailing list