From 720079063a4e97794dada308faac5834c0c2b067 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 4 Dec 2014 18:43:32 +0100 Subject: adde a run time parameter to worktest reading worker command now with parameters as in the shell --- src/biruda.conf | 2 +- src/master.c | 2 +- src/worker.c | 17 ++++++++++++++--- src/workertest.c | 9 +++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/biruda.conf b/src/biruda.conf index 6862c7a..33bbca6 100644 --- a/src/biruda.conf +++ b/src/biruda.conf @@ -20,7 +20,7 @@ worker worker1 # control = "inproc://control" control = "tcp://localhost:5555" execution = direct - command = "./workertest" + command = "./workertest 60" # command = "workertest.exe" } diff --git a/src/master.c b/src/master.c index e1c53de..d7bc64c 100644 --- a/src/master.c +++ b/src/master.c @@ -137,7 +137,7 @@ static int register_coordinator( json_object *obj ) for( int i = 0; i < coord->nof_workers; i++ ) { json_object *worker_obj; - worker_obj= json_object_array_get_idx( worker_array, i ); + worker_obj = json_object_array_get_idx( worker_array, i ); json_object *name_obj; json_object_object_get_ex( worker_obj, "name", &name_obj ); diff --git a/src/worker.c b/src/worker.c index e915697..c347ee8 100644 --- a/src/worker.c +++ b/src/worker.c @@ -108,14 +108,23 @@ static void *worker_func( void *thread_data ) direct_glib_execution_worker_data_t *wed = (direct_glib_execution_worker_data_t *)thread_data; worker_t *worker = wed->worker; - gchar *argv[] = { worker->command, NULL }; - + gchar **args; + gint nof_args; GError *error = NULL; + if( !g_shell_parse_argv( worker->command, &nof_args, &args, &error ) ) { + fprintf( stderr, "ERROR: Failed to parse command of worker '%s', '%s': %s\n", + worker->name, worker->command, error->message ); + g_strfreev( args ); + return NULL; + } + + error = NULL; gboolean ret = g_spawn_async_with_pipes( NULL, - argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, + args, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &wed->pid, NULL, &wed->out, &wed->err, &error ); if( !ret ) { fprintf( stderr, "ERROR: Starting worker failed: %s\n", error->message ); + g_strfreev( args ); return NULL; } @@ -147,6 +156,8 @@ static void *worker_func( void *thread_data ) printf( "worker %s: leaving glib worker main loop..\n", worker->name ); worker->state = WORKER_STATE_STOPPED; + + g_strfreev( args ); return NULL; } diff --git a/src/workertest.c b/src/workertest.c index 51fc717..34f571b 100644 --- a/src/workertest.c +++ b/src/workertest.c @@ -1,12 +1,13 @@ #include +#include #include "port.h" -#define RUN_TIME 10 - -int main( void ) +int main( int argc, char *argv[] ) { - for( int i = 0; i < RUN_TIME; i++ ) { + int run_time = atoi( argv[1] ); + + for( int i = 0; i < run_time; i++ ) { char msg[1024]; snprintf( msg, sizeof( msg ), "Msg %d\n", i ); -- cgit v1.2.3-54-g00ecf