From: Bruno Haible Date: Tue, 14 Oct 2003 10:27:30 +0000 (+0000) Subject: More reliable subprocess handling. X-Git-Tag: v0.13~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ee1e7c35a7586e56f49c09c35247e2bc686bc18;p=thirdparty%2Fgettext.git More reliable subprocess handling. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 8eaa4f1c8..3f4d08fe8 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,14 @@ +2003-10-05 Bruno Haible + + * 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 * xgettext.c (substring_match): Remove variable. diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index d8b200b90..187b34dd5 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #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; }