]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
More reliable subprocess handling.
authorBruno Haible <bruno@clisp.org>
Tue, 14 Oct 2003 10:27:30 +0000 (10:27 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:03 +0000 (12:11 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/write-java.c

index 8eaa4f1c82e20f5d16efa128f7e0388aaf6fbd7e..3f4d08fe89dfe0f6f6f1410d8eab702a3e0abfbe 100644 (file)
@@ -1,3 +1,14 @@
+2003-10-05  Bruno Haible  <bruno@clisp.org>
+
+       * write-java.c: Include fatal-signal.h, not signal.h.
+       (uninstall_handlers): Remove function.
+       (cleanup): Remove signal argument. Don't execute the signal's default
+       action; leave that to the caller.
+       (install_handlers, init_signal_set, block, unblock): Remove functions.
+       (msgdomain_write_java): Invoke at_fatal_signal instead of
+       install_handlers/uninstall_handlers. Invoke [un]block_fatal_signals
+       instead of [un]block.
+
 2003-10-05  Bruno Haible  <bruno@clisp.org>
 
        * xgettext.c (substring_match): Remove variable.
index d8b200b903653422031c379c0071bc26c6c0d8e6..187b34dd5c97ad608dd5fbf697db5cd411f3eadb 100644 (file)
@@ -30,7 +30,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <signal.h>
 
 #include <sys/stat.h>
 #if STAT_MACROS_BROKEN
@@ -74,6 +73,7 @@
 #include "po-charset.h"
 #include "xmalloc.h"
 #include "pathname.h"
+#include "fatal-signal.h"
 #include "fwriteerror.h"
 #include "tmpdir.h"
 #include "utf8-ucs4.h"
@@ -894,26 +894,9 @@ static struct
   const char *file_name;
 } cleanup_list;
 
-static void
-uninstall_handlers ()
-{
-#ifdef SIGHUP
-  signal (SIGHUP, SIG_DFL);
-#endif
-#ifdef SIGINT
-  signal (SIGINT, SIG_DFL);
-#endif
-#ifdef SIGPIPE
-  signal (SIGPIPE, SIG_DFL);
-#endif
-#ifdef SIGTERM
-  signal (SIGTERM, SIG_DFL);
-#endif
-}
-
 /* The signal handler.  It gets called asynchronously.  */
 static void
-cleanup (int sig)
+cleanup ()
 {
   unsigned int i;
 
@@ -940,83 +923,8 @@ cleanup (int sig)
     if (filename != NULL)
       rmdir (filename);
   }
-
-  /* Now execute the signal's default action.  */
-  uninstall_handlers ();
-#if HAVE_RAISE
-  raise (sig);
-#else
-  kill (getpid (), sig);
-#endif
-}
-
-static void
-install_handlers ()
-{
-#ifdef SIGHUP
-  signal (SIGHUP, &cleanup);
-#endif
-#ifdef SIGINT
-  signal (SIGINT, &cleanup);
-#endif
-#ifdef SIGPIPE
-  signal (SIGPIPE, &cleanup);
-#endif
-#ifdef SIGTERM
-  signal (SIGTERM, &cleanup);
-#endif
-}
-
-#if HAVE_POSIX_SIGNALBLOCKING
-
-static sigset_t signal_set;
-
-static void
-init_signal_set ()
-{
-  static bool signal_set_initialized = false;
-  if (!signal_set_initialized)
-    {
-      sigemptyset (&signal_set);
-
-#ifdef SIGHUP
-      sigaddset (&signal_set, SIGHUP);
-#endif
-#ifdef SIGINT
-      sigaddset (&signal_set, SIGINT);
-#endif
-#ifdef SIGPIPE
-      sigaddset (&signal_set, SIGPIPE);
-#endif
-#ifdef SIGTERM
-      sigaddset (&signal_set, SIGTERM);
-#endif
-
-      signal_set_initialized = true;
-    }
-}
-
-static void
-block ()
-{
-  init_signal_set ();
-  sigprocmask (SIG_BLOCK, &signal_set, NULL);
 }
 
-static void
-unblock ()
-{
-  init_signal_set ();
-  sigprocmask (SIG_UNBLOCK, &signal_set, NULL);
-}
-
-#else
-
-#define block() /* nothing */
-#define unblock() /* nothing */
-
-#endif
-
 
 int
 msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
@@ -1046,7 +954,14 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   cleanup_list.tmpdir = NULL;
   cleanup_list.subdir_count = 0;
   cleanup_list.file_name = NULL;
-  install_handlers ();
+  {
+    static bool cleanup_already_registered = false;
+    if (!cleanup_already_registered)
+      {
+       at_fatal_signal (&cleanup);
+       cleanup_already_registered = true;
+      }
+  }
 
   /* Create a temporary directory where we can put the Java file.  */
   template = (char *) alloca (PATH_MAX);
@@ -1056,10 +971,10 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
             _("cannot find a temporary directory, try setting $TMPDIR"));
       goto quit1;
     }
-  block ();
+  block_fatal_signals ();
   tmpdir = mkdtemp (template);
   cleanup_list.tmpdir = tmpdir;
-  unblock ();
+  unblock_fatal_signals ();
   if (tmpdir == NULL)
     {
       error (0, errno,
@@ -1197,6 +1112,6 @@ compilation of Java class failed, please try --verbose or set $JAVAC"));
   rmdir (tmpdir);
  quit1:
   cleanup_list.tmpdir = NULL;
-  uninstall_handlers ();
+  /* Here we could unregister the cleanup() handler.  */
   return retval;
 }