summaryrefslogtreecommitdiff
path: root/src/master.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-21 13:39:06 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-21 13:39:06 +0100
commite8d7e3401051dd9d8e2992ae0ed0d5149a6bdcc5 (patch)
treeeaeab3af96f568dd04e27d31be3471b7fe9dc9ea /src/master.c
parent4ed9394c0c2ba0ae65a20861fa998d7b701f8640 (diff)
downloadbiruda-e8d7e3401051dd9d8e2992ae0ed0d5149a6bdcc5.tar.gz
biruda-e8d7e3401051dd9d8e2992ae0ed0d5149a6bdcc5.tar.bz2
added a tail of worker output messages (needed for a web client showing the last lines of output)
Diffstat (limited to 'src/master.c')
-rw-r--r--src/master.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/master.c b/src/master.c
index d22a489..ad266e2 100644
--- a/src/master.c
+++ b/src/master.c
@@ -451,7 +451,7 @@ static int master_output_write_terminated( const char *spool_dir, const char *na
return 0;
}
-void master_output_tail( const char *name, char *s, size_t len )
+void master_output_outstanding_messages( const char *name, char *s, size_t len )
{
worker_t *w = worker_by_name( name );
@@ -476,7 +476,53 @@ void master_output_tail( const char *name, char *s, size_t len )
fgets( line, sizeof( line ), wed->spool_file );
cur += snprintf( cur, end - cur, "%s", line );
wed->read_pos += strlen( line );
- fprintf( stderr, "%lu %lu %s", wed->read_pos, end_pos, line );
+ }
+}
+
+void master_output_tail( const char *name, char *s, size_t len )
+{
+ worker_t *w = worker_by_name( name );
+
+ *s = '\0';
+
+ if( w == NULL ) return;
+
+ execution_worker_data_t *wed = (execution_worker_data_t *)w->execution_data;
+
+ if( wed->spool_file == NULL ) return;
+
+ long end_pos = ftell( wed->spool_file );
+ fseek( wed->spool_file, 0, SEEK_SET );
+ long pos = 0;
+
+ char *last_lines[25];
+ memset( last_lines, 0, sizeof( last_lines ) );
+ int last_lines_pos = 0;
+ char line[100];
+ while( pos < end_pos ) {
+ fgets( line, sizeof( line ), wed->spool_file );
+ if( last_lines[last_lines_pos] != NULL ) {
+ free( last_lines[last_lines_pos] );
+ }
+ last_lines[last_lines_pos] = strdup( line );
+ last_lines_pos++;
+ if( last_lines_pos >= 25 ) {
+ last_lines_pos = 0;
+ }
+ pos += strlen( line );
+ }
+
+ char *cur = s;
+ char *end = s + len;
+ for( int i = last_lines_pos; i < 25; i++ ) {
+ if( last_lines[i] != NULL ) {
+ cur += snprintf( cur, end - cur, "%s", last_lines[i] );
+ }
+ }
+ for( int i = 0; i < last_lines_pos; i++ ) {
+ if( last_lines[i] != NULL ) {
+ cur += snprintf( cur, end - cur, "%s", last_lines[i] );
+ }
}
}