From 262da2492d77f2a6feab3a99a725dbddf6d16188 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 30 Nov 2014 21:01:31 +0100 Subject: trying to catch termination of worker, but the glib main loop would be needed, I think I need a new way of executing processes without glib --- src/worker.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/worker.c') diff --git a/src/worker.c b/src/worker.c index 06ecc7e..9fec49b 100644 --- a/src/worker.c +++ b/src/worker.c @@ -57,23 +57,37 @@ worker_state_t worker_state_from_str( const char *s ) typedef struct { GPid pid; gint out, err; + worker_t *worker; } direct_glib_execution_worker_data_t; +static void watch_child( GPid pid, gint status, gpointer *data ) +{ + printf( "ENDENDEND %d\n", pid ); + g_spawn_close_pid( pid ); +} + int worker_init( worker_t *worker ) { + if( worker->state == WORKER_STATE_RUNNING ) { + return 0; + } + gchar *argv[] = { worker->command, NULL }; 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; + wed->worker = worker; gboolean ret = g_spawn_async_with_pipes( NULL, - argv, NULL, 0, NULL, + argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &wed->pid, NULL, &wed->out, &wed->err, NULL ); if( !ret ) { g_error( "Starting worker failed" ); return -1; } + g_child_watch_add( wed->pid, (GChildWatchFunc)watch_child, (gpointer *)wed ); + worker->state = WORKER_STATE_RUNNING; return 0; -- cgit v1.2.3-54-g00ecf