gnupg 1.9.15 test fails on x86_64 and ppc

Werner Koch wk at gnupg.org
Fri May 13 14:34:59 CEST 2005


On Wed, 11 May 2005 15:46:30 +0200, Michael Schwendt said:

> I had added the following patch to 1.9.16 to get better output than
> just "some signal":

There are in fact two problems.  The first is a change in the name of
the test macro for sys_siglist and the second is that we did not print
the signal number if sys_siglist is not available.

> +  const char* tmp = strsignal(signum);

strsignal is a GNU extension, so at least a test would be needed.
Further it is not reentrant, so we better avoid it.

I have changed it in a better way by using onkly functions allowed
within a signal handler.  This will print all signal numbers in the
range 0 .. 99999 which should be sufficient.  On GNU systems
sys_siglist is available and thus the code is only used on some other
platforms.

Here is the patch:

Index: signal.c
===================================================================
RCS file: /cvs/gnupg/gnupg/common/signal.c,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.3
diff -u -p -r1.2.2.1 -r1.2.2.3
--- signal.c	21 Dec 2004 10:03:00 -0000	1.2.2.1
+++ signal.c	13 May 2005 12:43:07 -0000	1.2.2.3
@@ -1,5 +1,6 @@
 /* signal.c - signal handling
- * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002,
+ *               2005 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -73,10 +74,12 @@ init_one_signal (int sig, RETSIGTYPE (*h
 static const char *
 get_signal_name( int signum )
 {
-#if defined(SYS_SIGLIST_DECLARED) && defined(NSIG)
+  /* Note that we can't use strsignal(), because it is not
+     reentrant. */
+#if defined(HAVE_DECL_SYS_SIGLIST) && defined(NSIG)
   return (signum >= 0 && signum < NSIG) ? sys_siglist[signum] : "?";
 #else
-  return "some signal";
+  return NULL;
 #endif
 }
 #endif /*!HAVE_DOSISH_SYSTEM*/
@@ -93,19 +96,42 @@ got_fatal_signal (int sig)
 
   if (cleanup_fnc)
     cleanup_fnc ();
-  /* better don't translate these messages */
+  /* Better don't translate these messages. */
   write (2, "\n", 1 );
   s = log_get_prefix (NULL);
   if (s)
     write(2, s, strlen (s));
-  write (2, ": ", 2 );
+  write (2, ": signal ", 9 );
   s = get_signal_name(sig);
-  write (2, s, strlen(s) );
+  if (s)
+    write (2, s, strlen(s) );
+  else
+    {
+      /* We are in a signal handler so we can't use any kind of printf
+         even not sprintf.  USe a straightforward algorithm. */
+      if (sig < 0 || sig >= 100000)
+        write (2, "?", 1);
+      else 
+        {
+          int i, any=0;
+
+          for (i=10000; i; i /= 10)
+            {
+              if (sig >= i || ((any || i==1) && !(sig/i)))
+                {
+                  write (2, "0123456789"+(sig/i), 1);
+                  if ((sig/i))
+                    any = 1;
+                  sig %= i;
+                }
+            }
+        }
+    }
   write (2, " caught ... exiting\n", 20);
   
-  /* reset action to default action and raise signal again */
+  /* Reset action to default action and raise signal again */
   init_one_signal (sig, SIG_DFL, 0);
-  /* fixme: remove_lockfiles ();*/
+  /* Fixme: remove_lockfiles ();*/
 #ifdef __riscos__
   close_fds ();
 #endif /* __riscos__ */




Shalom-Salam,

   Werner




More information about the Gnupg-devel mailing list