Fix PR/21658: gdbserver doesn't start on some libcs

Message ID 20170623081805.16105-1-git@andred.net
State New, archived
Headers

Commit Message

André Draszik June 23, 2017, 8:18 a.m. UTC
  From: André Draszik <adraszik@tycoint.com>

gdbserver currently fails to start on musl-libc based systems
with 'sigprocmask: Invalid argument'

The reason is because it uses an invalid argument to sigprocmask():

  http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html

  The argument how indicates the way in which the set is changed, and
  the application shall ensure it consists of one of the following
  values
    SIG_BLOCK
    SIG_SETMASK
    SIG_UNBLOCK

  ...

  The pthread_sigmask() and sigprocmask() functions shall fail if:

  [EINVAL]
    The value of the how argument is not equal to one of
    the defined values.

This is what musl-libc implements, hence gdbserver fails to start.

Fix the call to use correct arguments.

gdb/ChangeLog:
2017-06-23  André Draszik  <adraszik@tycoint.com>

	PR gdb/21658
	* common/signals-state-save-restore.c
	(save_original_signals_state): Use POSIX-compliant arguments
	to sigprocmask().
---
 gdb/ChangeLog                           | 7 +++++++
 gdb/common/signals-state-save-restore.c | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
  

Comments

Pedro Alves June 23, 2017, 8:59 a.m. UTC | #1
On 06/23/2017 09:18 AM, André Draszik wrote:
> From: André Draszik <adraszik@tycoint.com>
> 
> gdbserver currently fails to start on musl-libc based systems
> with 'sigprocmask: Invalid argument'
> 
> The reason is because it uses an invalid argument to sigprocmask():

No it doesn't.  This has come up before:
 https://sourceware.org/ml/gdb-patches/2017-03/msg00426.html
which led to:
 http://austingroupbugs.net/view.php?id=1132

> This is what musl-libc implements, hence gdbserver fails to start.

Please fix musl...

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 95010fc612..ac298bc074 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@ 
+2017-06-23  André Draszik  <adraszik@tycoint.com>
+
+	PR gdb/21658
+	* common/signals-state-save-restore.c
+	(save_original_signals_state): Use POSIX-compliant arguments
+	to sigprocmask().
+
 2017-06-22  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* common/environ.c (gdb_environ::unset): Update comment.
diff --git a/gdb/common/signals-state-save-restore.c b/gdb/common/signals-state-save-restore.c
index d11a9ae006..734335c3a2 100644
--- a/gdb/common/signals-state-save-restore.c
+++ b/gdb/common/signals-state-save-restore.c
@@ -41,7 +41,7 @@  save_original_signals_state (void)
   int i;
   int res;
 
-  res = sigprocmask (0,  NULL, &original_signal_mask);
+  res = sigprocmask (SIG_BLOCK,  NULL, &original_signal_mask);
   if (res == -1)
     perror_with_name (("sigprocmask"));