summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 18:43:32 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 18:43:32 +0100
commit720079063a4e97794dada308faac5834c0c2b067 (patch)
treea08ac3c9aee0df89c5870f59c308b23b9d971122
parent8717001af5170c3b63f9db543986b87ea7dd2049 (diff)
downloadbiruda-720079063a4e97794dada308faac5834c0c2b067.tar.gz
biruda-720079063a4e97794dada308faac5834c0c2b067.tar.bz2
adde a run time parameter to worktest
reading worker command now with parameters as in the shell
-rw-r--r--src/biruda.conf2
-rw-r--r--src/master.c2
-rw-r--r--src/worker.c17
-rw-r--r--src/workertest.c9
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 <stdio.h>
+#include <stdlib.h>
#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 );