From c8e9df5b209a2465f668283b5b71c0157d1e028f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 29 Dec 2014 09:36:29 +0100 Subject: trying to map glib exit code in worker into message --- src/worker.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/worker.c b/src/worker.c index abf8404..2885400 100644 --- a/src/worker.c +++ b/src/worker.c @@ -103,7 +103,7 @@ static char *create_worker_output_answer( const char *name, const char *s, size_ return res; } -static char *create_worker_termination_answer( const char *name, GPid pid ) +static char *create_worker_termination_answer( const char *name, GPid pid, gint status, const char *exit_message ) { json_object *obj = json_object_new_object( ); json_object *op = json_object_new_string( "terminated" ); @@ -120,6 +120,12 @@ static char *create_worker_termination_answer( const char *name, GPid pid ) snprintf( pid_str, sizeof( pid_str ), PRIgid, pid ); json_object *pid_obj = json_object_new_string( pid_str ); json_object_object_add( obj, "pid", pid_obj ); + + json_object *exit_status_obj = json_object_new_int( status ); + json_object_object_add( obj, "exit_status", exit_status_obj ); + + json_object *exit_message_obj = json_object_new_string( exit_message ); + json_object_object_add( obj, "exit_message", exit_message_obj ); time_t ts; time( &ts ); @@ -194,10 +200,17 @@ static void watch_child( GPid pid, gint status, gpointer *data ) { direct_glib_execution_worker_data_t *wed = (direct_glib_execution_worker_data_t *)data; worker_t *worker = wed->worker; - - printf( "Worker child with PID " PRIgid " terminated.\n", wed->pid ); - char *msg = create_worker_termination_answer( worker->name, wed->pid ); + GError *error = NULL; + char *exit_message = ""; + if( g_spawn_check_exit_status( status, &error ) ) { + exit_message = error->message; + } + + printf( "Worker child with PID " PRIgid " terminated with status %d: %s.\n", + wed->pid, status, exit_message ); + + char *msg = create_worker_termination_answer( worker->name, wed->pid, status, exit_message ); worker_send_message( worker, msg ); free( msg ); -- cgit v1.2.3-54-g00ecf