diff --git a/tools/make_xftmpl.c b/tools/make_xftmpl.c index d707dc06cd2..087020cdb99 100644 --- a/tools/make_xftmpl.c +++ b/tools/make_xftmpl.c @@ -20,7 +20,6 @@ #include "config.h" -#include #include #include #include @@ -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; diff --git a/tools/makedep.c b/tools/makedep.c index 6379b5b69d9..e91f5a3afe2 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -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] ); diff --git a/tools/sfnt2fon/sfnt2fon.c b/tools/sfnt2fon/sfnt2fon.c index b5a2086cac1..2c307dcce8a 100644 --- a/tools/sfnt2fon/sfnt2fon.c +++ b/tools/sfnt2fon/sfnt2fon.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -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 ), diff --git a/tools/tools.h b/tools/tools.h index 3c25bcc41a9..70ef4bd2584 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -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; diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 1b0a88e3709..7d3fa26f8d0 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -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] ); diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c index f416d9dd586..f216e4bf35d 100644 --- a/tools/winebuild/main.c +++ b/tools/winebuild/main.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -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; diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 2261eca6c1d..0770ccfbe2a 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -91,7 +91,6 @@ #include #include #include -#include #include #include #include @@ -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 */ diff --git a/tools/wmc/wmc.c b/tools/wmc/wmc.c index c2cf754f590..e4f2377e772 100644 --- a/tools/wmc/wmc.c +++ b/tools/wmc/wmc.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -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 */ diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c index 0fe104e2ad3..48d5d2033d8 100644 --- a/tools/wrc/wrc.c +++ b/tools/wrc/wrc.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -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 */