summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-14 21:30:40 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-14 21:30:40 +0100
commit6667d3c47662c03145c79aeed6ebe616a9f63f53 (patch)
tree96d8857b57ca1d380aa5baab95cdf363c7430172
parent34f82c793955bbd4e62679460afebcf9cc10d484 (diff)
downloadbiruda-6667d3c47662c03145c79aeed6ebe616a9f63f53.tar.gz
biruda-6667d3c47662c03145c79aeed6ebe616a9f63f53.tar.bz2
..
-rw-r--r--src/master.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/master.c b/src/master.c
index c2997da..45aa7d3 100644
--- a/src/master.c
+++ b/src/master.c
@@ -10,6 +10,9 @@
#include <stdio.h>
#include <string.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
static pthread_t master_thread;
static int control_sock;
@@ -171,6 +174,7 @@ static int register_coordinator( json_object *obj )
w->execution_data = malloc( sizeof( execution_worker_data_t ) );
execution_worker_data_t *wed = (execution_worker_data_t *)w->execution_data;
wed->spool_file = NULL;
+ wed->read_pos = 0;
json_object *state_obj;
json_object_object_get_ex( worker_obj, "state", &state_obj );
@@ -324,6 +328,10 @@ static int master_output_init( const char *spool_dir, const char *name )
spool_dir, PORT_DIR_SEPARATOR, worker->name );
execution_worker_data_t *wed = (execution_worker_data_t *)worker->execution_data;
+ if( wed->spool_file != NULL ) {
+ fprintf( stderr, "WARNING: truncating old output file of worker '%s'\n", name );
+ unlink( filename );
+ }
wed->spool_file = fopen( filename, "a+" );
wed->read_pos = 0;
@@ -346,12 +354,8 @@ static int master_output_free( const char *name )
return 0;
}
-static int master_output_write( const char *spool_dir, json_object *obj )
-{
- json_object *worker_obj;
- json_object_object_get_ex( obj, "worker", &worker_obj );
- const char *name = json_object_get_string( worker_obj );
-
+static int master_output_write( const char *spool_dir, const char *name, json_object *obj )
+{
worker_t *w = worker_by_name( name );
if( w == NULL ) return 0;
@@ -384,12 +388,8 @@ static int master_output_write( const char *spool_dir, json_object *obj )
return 0;
}
-static int master_output_write_started( const char *spool_dir, json_object *obj )
+static int master_output_write_started( const char *spool_dir, const char *name, json_object *obj )
{
- json_object *worker_obj;
- json_object_object_get_ex( obj, "worker", &worker_obj );
- const char *name = json_object_get_string( worker_obj );
-
worker_t *w = worker_by_name( name );
if( w == NULL ) return 0;
@@ -418,12 +418,8 @@ static int master_output_write_started( const char *spool_dir, json_object *obj
return 0;
}
-static int master_output_write_terminated( const char *spool_dir, json_object *obj )
+static int master_output_write_terminated( const char *spool_dir, const char *name, json_object *obj )
{
- json_object *worker_obj;
- json_object_object_get_ex( obj, "worker", &worker_obj );
- const char *name = json_object_get_string( worker_obj );
-
worker_t *w = worker_by_name( name );
if( w == NULL ) return 0;
@@ -562,21 +558,26 @@ NEXT_COMMAND:
}
}
} else if( strcmp( op, "started" ) == 0 ) {
+ // TODO: send confirmation to cli
+ } else if( strcmp( op, "stopped" ) == 0 ) {
+ // TODO: send confirmation to cli
+ } else if( strcmp( op, "created" ) == 0 ) {
json_object *worker_obj;
json_object_object_get_ex( recv_obj, "worker", &worker_obj );
const char *worker = json_object_get_string( worker_obj );
master_output_init( tdata->spool_dir, worker );
- } else if( strcmp( op, "stopped" ) == 0 ) {
+ master_output_write_started( tdata->spool_dir, worker, recv_obj );
+ } else if( strcmp( op, "terminated" ) == 0 ) {
json_object *worker_obj;
json_object_object_get_ex( recv_obj, "worker", &worker_obj );
const char *worker = json_object_get_string( worker_obj );
+ master_output_write_terminated( tdata->spool_dir, worker, recv_obj );
master_output_free( worker );
- } else if( strcmp( op, "created" ) == 0 ) {
- master_output_write_started( tdata->spool_dir, recv_obj );
- } else if( strcmp( op, "terminated" ) == 0 ) {
- master_output_write_terminated( tdata->spool_dir, recv_obj );
} else if( strcmp( op, "output" ) == 0 ) {
- master_output_write( tdata->spool_dir, recv_obj );
+ json_object *worker_obj;
+ json_object_object_get_ex( recv_obj, "worker", &worker_obj );
+ const char *worker = json_object_get_string( worker_obj );
+ master_output_write( tdata->spool_dir, worker, recv_obj );
} else {
fprintf( stderr, "WARNING: master received unkown message: %s\n", answer );
}