From: Nils Durner Date: Mon, 22 Mar 2010 21:50:38 +0000 (+0000) Subject: (no commit message) X-Git-Tag: initial-import-from-subversion-38251~22386 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1d943b33c95c2d3f366d50e22e8b134029d5a579;p=oweals%2Fgnunet.git --- diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 9eb7e7534..2cc131c1c 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -986,7 +986,7 @@ run (void *cls, sched = s; server = serv; GNUNET_assert (serv != NULL); - shc_chld = GNUNET_SIGNAL_handler_install (SIGCHLD, &sighandler_child_death); + shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); GNUNET_assert (sigpipe == NULL); sigpipe = GNUNET_DISK_pipe (GNUNET_NO); GNUNET_assert (sigpipe != NULL); diff --git a/src/include/platform.h b/src/include/platform.h index 0e6c13c21..7bf2b2f8f 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -40,8 +40,10 @@ #ifdef WINDOWS #define BREAKPOINT asm("int $3;"); +#define GNUNET_SIGCHLD 17 #else #define BREAKPOINT +#define GNUNET_SIGCHLD SIGCHLD #endif #ifdef HAVE_SYS_TYPES_H diff --git a/src/util/os_priority.c b/src/util/os_priority.c index d501b3511..b68e6b8fa 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -29,6 +29,27 @@ #include "gnunet_os_lib.h" #include "disk.h" +#if WINDOWS +#include "gnunet_signal_lib.h" + +extern GNUNET_SIGNAL_Handler w32_sigchld_handler; + +/** + * @brief Waits for a process to terminate and invokes the SIGCHLD handler + * @param h handle to the process + */ +static DWORD WINAPI +ChildWaitThread (HANDLE h) +{ + WaitForSingleObject (h, INFINITE); + + if (w32_sigchld_handler) + w32_sigchld_handler (); + + CloseHandle (h); +} +#endif + /** * Set process priority * @@ -274,9 +295,11 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", fn); return -1; } + + CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL); + if (fn != filename) GNUNET_free (fn); - CloseHandle (proc.hProcess); CloseHandle (proc.hThread); GNUNET_free (cmd); @@ -365,9 +388,10 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); return -1; } - CloseHandle (proc.hProcess); - CloseHandle (proc.hThread); + CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL); + + CloseHandle (proc.hThread); GNUNET_free (cmd); return proc.dwProcessId; diff --git a/src/util/signal.c b/src/util/signal.c index 478551ca2..c8d6e04cd 100644 --- a/src/util/signal.c +++ b/src/util/signal.c @@ -39,8 +39,12 @@ struct GNUNET_SIGNAL_Context #endif }; +#ifdef WINDOWS +GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL; +#endif + struct GNUNET_SIGNAL_Context * -GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler) +GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) { struct GNUNET_SIGNAL_Context *ret; #ifndef MINGW @@ -48,7 +52,7 @@ GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler) #endif ret = GNUNET_malloc (sizeof (struct GNUNET_SIGNAL_Context)); - ret->sig = signal; + ret->sig = signum; ret->method = handler; #ifndef MINGW sig.sa_handler = (void *) handler; @@ -58,7 +62,12 @@ GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler) #else sig.sa_flags = SA_RESTART; #endif - sigaction (signal, &sig, &ret->oldsig); + sigaction (signum, &sig, &ret->oldsig); +#else + if (signum == GNUNET_SIGCHLD) + w32_sigchld_handler = handler; + else + signal (signum, handler); #endif return ret; }