Browse Source

Fix up sig handling so it is more in sync with glibc behavior

Eric Andersen 23 years ago
parent
commit
cd2b5379fc

+ 4 - 3
libc/signal/Makefile

@@ -23,9 +23,10 @@
 TOPDIR=../../
 include $(TOPDIR)Rules.mak
 
-CSRC=bsd_sig.c raise.c sigblock.c siggtmsk.c sigjmp.c signal.c sigintr.c\
-	sigpause.c sigstmsk.c sigaddset.c sigdelset.c sigismem.c \
-	sigemptyset.c sigfillset.c killpg.c allocrtsig.c
+CSRC=bsd_sig.c raise.c sigblock.c siggetmask.c sigjmp.c signal.c sigintr.c\
+	sigpause.c sigstmsk.c killpg.c allocrtsig.c sigsetops.c \
+	sigaddset.c sigandset.c sigdelset.c sigfillset.c sigorset.c \
+	sigempty.c sighold.c sigisempty.c sigismem.c sigrelse.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 
 OBJS=$(COBJS)

+ 16 - 16
libc/signal/sigaddset.c

@@ -2,31 +2,31 @@
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <features.h>
-#include <signal.h>
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
+#include "sigsetops.h"
 
 /* Add SIGNO to SET.  */
-int sigaddset ( sigset_t *set, int signo)
+int
+sigaddset (set, signo)
+     sigset_t *set;
+     int signo;
 {
-  if (set == NULL || signo <= 0 || signo >= NSIG) {
-      __set_errno(EINVAL);
+  if (set == NULL || signo <= 0 || signo >= NSIG)
+    {
+      __set_errno (EINVAL);
       return -1;
     }
 

+ 39 - 0
libc/signal/sigandset.c

@@ -0,0 +1,39 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#define __USE_GNU
+#include <signal.h>
+#define __need_NULL
+#include <stddef.h>
+
+/* Combine sets LEFT and RIGHT by logical AND and place result in DEST.  */
+int
+sigandset (dest, left, right)
+     sigset_t *dest;
+     const sigset_t *left;
+     const sigset_t *right;
+{
+  if (dest == NULL || left == NULL || right == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return __sigandset (dest, left, right);
+}

+ 38 - 27
libc/signal/sigblock.c

@@ -1,45 +1,56 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+/* Copyright (C) 1991, 94, 95, 96, 97, 98, 2001 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
 
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
-#include <stdlib.h>
 #include <errno.h>
+#define __USE_GNU
 #include <signal.h>
 
 /* Block signals in MASK, returning the old mask.  */
-int sigblock (int mask)
+int sigblock (mask)
+     int mask;
 {
-  register int sig;
+  register unsigned int sig;
   sigset_t set, oset;
 
-  if (sigemptyset(&set) < 0)
+  if (__sigemptyset (&set) < 0)
     return -1;
-  
-  for (sig = 1; sig < NSIG; ++sig)
-    if ((mask & sigmask(sig)) && sigaddset(&set, sig) < 0)
-      return -1;
 
-  if (sigprocmask(SIG_BLOCK, &set, &oset) < 0)
+  if (sizeof (mask) == sizeof (set))
+    *(int *) &set = mask;
+  else if (sizeof (unsigned long int) == sizeof (set))
+    *(unsigned long int *) &set = (unsigned int) mask;
+  else
+    for (sig = 1; sig < NSIG && sig <= sizeof (mask) * 8; ++sig)
+      if ((mask & sigmask (sig)) && __sigaddset (&set, sig) < 0)
+	return -1;
+
+  if (sigprocmask (SIG_BLOCK, &set, &oset) < 0)
     return -1;
 
-  mask = 0;
-  for (sig = 1; sig < NSIG; ++sig)
-    if (sigismember(&oset, sig))
-      mask |= sigmask(sig);
+  if (sizeof (mask) == sizeof (oset))
+    mask = *(int *) &oset;
+  else if (sizeof (unsigned long int) == sizeof (oset))
+    mask = *(unsigned long int*) &oset;
+  else
+    for (sig = 1, mask = 0; sig < NSIG && sig <= sizeof (mask) * 8; ++sig)
+      if (__sigismember (&oset, sig))
+	mask |= sigmask (sig);
 
   return mask;
 }
+

+ 16 - 15
libc/signal/sigdelset.c

@@ -2,30 +2,31 @@
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
-#include <stdlib.h>
-#include <errno.h>
-#include <features.h>
-#include <signal.h>
+#include "sigsetops.h"
 
 /* Add SIGNO to SET.  */
-int sigdelset ( sigset_t *set, int signo)
+int
+sigdelset (set, signo)
+     sigset_t *set;
+     int signo;
 {
-  if (set == NULL || signo <= 0 || signo >= NSIG) {
-      __set_errno(EINVAL);
+  if (set == NULL || signo <= 0 || signo >= NSIG)
+    {
+      __set_errno (EINVAL);
       return -1;
     }
 

+ 37 - 0
libc/signal/sigempty.c

@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+
+/* Clear all signals from SET.  */
+int
+sigemptyset (set)
+     sigset_t *set;
+{
+  if (set == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  memset (set, 0, sizeof (sigset_t));
+
+  return 0;
+}

+ 9 - 9
libc/signal/sigfillset.c

@@ -2,19 +2,19 @@
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
 #include <errno.h>
 #include <signal.h>
@@ -27,7 +27,7 @@ sigfillset (set)
 {
   if (set == NULL)
     {
-      __set_errno(EINVAL);
+      __set_errno (EINVAL);
       return -1;
     }
 

+ 30 - 0
libc/signal/siggetmask.c

@@ -0,0 +1,30 @@
+/* siggetmask -- useless alias for `sigblock (0)' for old Linux compatibility.
+   Copyright (C) 1996 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#define __USE_GNU
+#include <signal.h>
+
+int
+siggetmask (void)
+{
+  return sigblock (0);
+}
+
+link_warning (siggetmask,
+	      "warning: `siggetmask' is obsolete; `sigprocmask' is best")

+ 42 - 0
libc/signal/sighold.c

@@ -0,0 +1,42 @@
+/* Add SIG to the calling process' signal mask.
+   Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#define __need_NULL
+#include <stddef.h>
+#define __USE_GNU
+#include <signal.h>
+
+int
+sighold (sig)
+     int sig;
+{
+  sigset_t set;
+
+  /* Retrieve current signal set.  */
+  if (sigprocmask (SIG_SETMASK, NULL, &set) < 0)
+    return -1;
+
+  /* Add the specified signal.  */
+  if (__sigaddset (&set, sig) < 0)
+    return -1;
+
+  /* Set the new mask.  */
+  return sigprocmask (SIG_SETMASK, &set, NULL);
+}

+ 37 - 0
libc/signal/sigisempty.c

@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#define __USE_GNU
+#include <signal.h>
+#define __need_NULL
+#include <stddef.h>
+
+/* Test whether SET is empty.  */
+int
+sigisemptyset (set)
+     const sigset_t *set;
+{
+  if (set == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+    return __sigisemptyset (set);
+}

+ 16 - 17
libc/signal/sigismem.c

@@ -2,32 +2,31 @@
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
-#include <stdlib.h>
-#include <errno.h>
-#include <features.h>
-#define _EXTERN_INLINE
-#define __USE_EXTERN_INLINES   1
-#include <signal.h>
+#include "sigsetops.h"
 
 /* Return 1 if SIGNO is in SET, 0 if not.  */
-int sigismember ( const sigset_t *set, int signo)
+int
+sigismember (set, signo)
+     const sigset_t *set;
+     int signo;
 {
-  if (set == NULL || signo <= 0 || signo >= NSIG) {
-      __set_errno(EINVAL);
+  if (set == NULL || signo <= 0 || signo >= NSIG)
+    {
+      __set_errno (EINVAL);
       return -1;
     }
 

+ 39 - 0
libc/signal/sigorset.c

@@ -0,0 +1,39 @@
+/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#define __USE_GNU
+#include <signal.h>
+#define __need_NULL
+#include <stddef.h>
+
+/* Combine sets LEFT and RIGHT by logical OR and place result in DEST.  */
+int
+sigorset (dest, left, right)
+     sigset_t *dest;
+     const sigset_t *left;
+     const sigset_t *right;
+{
+  if (dest == NULL || left == NULL || right == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return __sigorset (dest, left, right);
+}

+ 42 - 0
libc/signal/sigrelse.c

@@ -0,0 +1,42 @@
+/* Remove SIG from the calling process' signal mask.
+   Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#define __need_NULL
+#include <stddef.h>
+#define __USE_GNU
+#include <signal.h>
+
+int
+sigrelse (sig)
+     int sig;
+{
+  sigset_t set;
+
+  /* Retrieve current signal set.  */
+  if (sigprocmask (SIG_SETMASK, NULL, &set) < 0)
+    return -1;
+
+  /* Remove the specified signal.  */
+  if (__sigdelset (&set, sig) < 0)
+    return -1;
+
+  /* Set the new mask.  */
+  return sigprocmask (SIG_SETMASK, &set, NULL);
+}

+ 11 - 0
libc/signal/sigsetops.c

@@ -0,0 +1,11 @@
+/* Define the real-function versions of all inline functions
+   defined in signal.h (or bits/sigset.h).  */
+
+#include <features.h>
+
+#define _EXTERN_INLINE
+#ifndef __USE_EXTERN_INLINES
+# define __USE_EXTERN_INLINES	1
+#endif
+
+#include "signal.h"

+ 34 - 0
libc/signal/sigsetops.h

@@ -0,0 +1,34 @@
+/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* Definitions relevant to functions that operate on `sigset_t's.  */
+
+#include <errno.h>
+#define __USE_GNU
+#include <signal.h>
+#include <string.h>
+
+#define	BITS		(_NSIG - 1)
+#define	ELT(signo)	(((signo) - 1) / BITS)
+#define	MASK(signo)	(1 << (((signo) - 1) % BITS))
+
+#undef	sigemptyset
+#undef	sigfillset
+#undef	sigaddset
+#undef	sigdelset
+#undef	sigismember