+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.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <signal.h>
#include <sys/stat.h>
#if STAT_MACROS_BROKEN
#include "po-charset.h"
#include "xmalloc.h"
#include "pathname.h"
+#include "fatal-signal.h"
#include "fwriteerror.h"
#include "tmpdir.h"
#include "utf8-ucs4.h"
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;
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,
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);
_("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,
rmdir (tmpdir);
quit1:
cleanup_list.tmpdir = NULL;
- uninstall_handlers ();
+ /* Here we could unregister the cleanup() handler. */
return retval;
}