Commit ae8797c8 authored by Alexandre Julliard's avatar Alexandre Julliard

tools: Add a common helper to setup signal handlers.

parent 9f0ae8c9
......@@ -20,7 +20,6 @@
#include "config.h"
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -478,11 +477,7 @@ int main(int argc, char **argv)
} else {
output_file = option_outfile_name;
atexit(cleanup_files);
signal(SIGTERM, exit_on_signal);
signal(SIGINT, exit_on_signal);
#ifdef SIGHUP
signal(SIGHUP, exit_on_signal);
#endif
init_signals( exit_on_signal );
if (!(outfile = fopen(output_file, "wb"))) {
perror(option_outfile_name);
goto error;
......
......@@ -27,7 +27,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
......@@ -4395,11 +4394,7 @@ int main( int argc, char *argv[] )
if (argc > 1) fatal_error( "Directory arguments not supported in this mode\n" );
atexit( cleanup_files );
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_signals( exit_on_signal );
for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
for (i = 0; i < HASH_SIZE; i++) list_init( &global_includes[i] );
......
......@@ -23,7 +23,6 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -912,11 +911,7 @@ int main(int argc, char **argv)
font_off = (fontdir_off + fontdir_len + 15) & ~0x0f;
atexit( cleanup );
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_signals( exit_on_signal );
if (!output_name) /* build a default output name */
output_name = strmake( "%s%s", get_basename_noext( input_file ),
......
......@@ -401,6 +401,16 @@ static inline void remove_temp_files(void)
}
static inline void init_signals( void (*cleanup)(int) )
{
signal( SIGTERM, cleanup );
signal( SIGINT, cleanup );
#ifdef SIGHUP
signal( SIGHUP, cleanup );
#endif
}
static inline void *read_file( const char *name, size_t *size )
{
struct stat st;
......
......@@ -28,7 +28,6 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>
#include <limits.h>
#include <sys/types.h>
......@@ -704,11 +703,7 @@ int main(int argc,char *argv[])
struct strarray files;
char *input;
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_signals( exit_on_signal );
init_argv0_dir( argv[0] );
target = init_argv0_target( argv[0] );
......
......@@ -26,7 +26,6 @@
#include <assert.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
......@@ -619,12 +618,7 @@ int main(int argc, char **argv)
struct strarray files;
DLLSPEC *spec = main_spec = alloc_dll_spec();
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
init_signals( exit_on_signal );
target = init_argv0_target( argv[0] );
if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
if (is_pe()) unwind_tables = 1;
......
......@@ -91,7 +91,6 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
......@@ -1488,11 +1487,7 @@ int main(int argc, char **argv)
char* lang = 0;
char* str;
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
init_signals( exit_on_signal );
init_argv0_dir( argv[0] );
/* setup tmp file removal at exit */
......
......@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <limits.h>
#include <sys/types.h>
......@@ -221,11 +220,7 @@ int main(int argc,char *argv[])
struct strarray files;
atexit( cleanup_files );
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_signals( exit_on_signal );
init_argv0_dir( argv[0] );
/* First rebuild the commandline to put in destination */
......
......@@ -26,7 +26,6 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>
#include <limits.h>
#include <sys/types.h>
......@@ -396,11 +395,7 @@ int main(int argc,char *argv[])
{
int i;
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_signals( exit_on_signal );
init_argv0_dir( argv[0] );
/* Set the default defined stuff */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment