diff options
Diffstat (limited to 'src/worker.c')
-rw-r--r-- | src/worker.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/worker.c b/src/worker.c index 4d2db69..f70f84b 100644 --- a/src/worker.c +++ b/src/worker.c @@ -8,6 +8,9 @@ #include <stdio.h> #include <string.h> +#include <stdlib.h> + +#include <signal.h> const char *worker_exection_mode_str( worker_execution_mode_t mode ) { @@ -30,15 +33,21 @@ worker_execution_mode_t worker_execution_mode_from_str( const char *s ) } } +typedef struct { + GPid pid; + gint out, err; +} direct_glib_execution_worker_data_t; + int worker_init( worker_t *worker ) { gchar *argv[] = { worker->command, NULL }; - GPid pid; - gint out, err; + worker->execution_data = malloc( sizeof( direct_glib_execution_worker_data_t ) ); + direct_glib_execution_worker_data_t *wed = + (direct_glib_execution_worker_data_t *)worker->execution_data; gboolean ret = g_spawn_async_with_pipes( NULL, argv, NULL, 0, NULL, - NULL, &pid, NULL, &out, &err, NULL ); + NULL, &wed->pid, NULL, &wed->out, &wed->err, NULL ); if( !ret ) { g_error( "Starting worker failed" ); return -1; @@ -47,8 +56,17 @@ int worker_init( worker_t *worker ) return 0; } -void worker_terminate( ) +void worker_terminate( worker_t *worker ) { + direct_glib_execution_worker_data_t *wed = (direct_glib_execution_worker_data_t *)worker->execution_data; + +#ifndef _WIN32 + kill( wed->pid, SIGTERM ); +#else +#error TODO kill on Windows +#endif + free( worker->execution_data ); + worker->execution_data = NULL; } int worker_free( ) |