[pacman-dev,4/4] Fix build error when SIGPOLL is not available

Message ID 20210416194209.191245-5-mark.weiman@markzz.com
State New
Headers show
Series Various fixes for FreeBSD (and perhaps others) | expand

Commit Message

Mark Weiman April 16, 2021, 7:42 p.m. UTC
On Linux, SIGPOLL is a valid signal, but on systems like FreeBSD, it is
not. This patch adds a detection within meson.build to check if it's
available, and if not, make sure it's not included.

Signed-off-by: Mark Weiman <mark.weiman@markzz.com>
---
 lib/libalpm/util.c |  6 +++++-
 meson.build        | 13 +++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Andrew Gregory April 16, 2021, 8:08 p.m. UTC | #1
On 04/16/21 at 03:42pm, Mark Weiman wrote:
> On Linux, SIGPOLL is a valid signal, but on systems like FreeBSD, it is
> not. This patch adds a detection within meson.build to check if it's
> available, and if not, make sure it's not included.
> 
> Signed-off-by: Mark Weiman <mark.weiman@markzz.com>
> ---
>  lib/libalpm/util.c |  6 +++++-
>  meson.build        | 13 +++++++++++++
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
> index d2a688a2..db07502a 100644
> --- a/lib/libalpm/util.c
> +++ b/lib/libalpm/util.c
> @@ -561,7 +561,11 @@ static void _alpm_reset_signals(void)
>  	int *i, signals[] = {
>  		SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL,
>  		SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP,
> -		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP,
> +		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2,
> +#if defined(HAVE_SIGPOLL)
> +        SIGPOLL,
> +#endif
> +        SIGPROF, SIGSYS, SIGTRAP,
>  		SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ,

SIGPOLL is a macro, just check for it directly.  For the sake of
readability, leave the other three signals on the line they're already
on and put SIGPOLL at the end.  Please also add a comment that this is
for FreeBSD so we don't forget and revert it in the future.
Eli Schwartz April 16, 2021, 9:02 p.m. UTC | #2
On 4/16/21 3:42 PM, Mark Weiman wrote:
> On Linux, SIGPOLL is a valid signal, but on systems like FreeBSD, it is
> not. This patch adds a detection within meson.build to check if it's
> available, and if not, make sure it's not included.

I have seen this brought up before...

It solves one of the two problems brought up in
https://lists.archlinux.org/pipermail/pacman-dev/2020-September/024525.html

And it does so without keying off of #ifndef __APPLE__

:D

> Signed-off-by: Mark Weiman <mark.weiman@markzz.com>
> ---
>  lib/libalpm/util.c |  6 +++++-
>  meson.build        | 13 +++++++++++++
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
> index d2a688a2..db07502a 100644
> --- a/lib/libalpm/util.c
> +++ b/lib/libalpm/util.c
> @@ -561,7 +561,11 @@ static void _alpm_reset_signals(void)
>  	int *i, signals[] = {
>  		SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL,
>  		SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP,
> -		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP,
> +		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2,
> +#if defined(HAVE_SIGPOLL)
> +        SIGPOLL,
> +#endif
> +        SIGPROF, SIGSYS, SIGTRAP,
>  		SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ,
>  		0
>  	};
> diff --git a/meson.build b/meson.build
> index 0dc0d612..359e7f05 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -193,8 +193,21 @@ 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)
> +  include_signal = '''#include <signal.h>'''
> +else
> +  include_signal = ''
>  endif
>  
> +foreach sig : [
> +    'SIGPOLL',
> +  ]
> +  if cc.compiles(include_signal + '''
> +                 void foo() { int sig = ''' +
> +                sig + '''; }''', name : 'test for ' + sig)
> +    conf.set('HAVE_' + sig, true)
> +  endif
> +endforeach
> +
>  if get_option('debug')
>    extra_cflags = [
>      '-Wcast-align',
>

Patch

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index d2a688a2..db07502a 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -561,7 +561,11 @@  static void _alpm_reset_signals(void)
 	int *i, signals[] = {
 		SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL,
 		SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP,
-		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP,
+		SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2,
+#if defined(HAVE_SIGPOLL)
+        SIGPOLL,
+#endif
+        SIGPROF, SIGSYS, SIGTRAP,
 		SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ,
 		0
 	};
diff --git a/meson.build b/meson.build
index 0dc0d612..359e7f05 100644
--- a/meson.build
+++ b/meson.build
@@ -193,8 +193,21 @@  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)
+  include_signal = '''#include <signal.h>'''
+else
+  include_signal = ''
 endif
 
+foreach sig : [
+    'SIGPOLL',
+  ]
+  if cc.compiles(include_signal + '''
+                 void foo() { int sig = ''' +
+                sig + '''; }''', name : 'test for ' + sig)
+    conf.set('HAVE_' + sig, true)
+  endif
+endforeach
+
 if get_option('debug')
   extra_cflags = [
     '-Wcast-align',