diff options
Diffstat (limited to 'daemon/writer.c')
-rw-r--r-- | daemon/writer.c | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/daemon/writer.c b/daemon/writer.c index e05a2c8..7761bbc 100644 --- a/daemon/writer.c +++ b/daemon/writer.c @@ -47,6 +47,12 @@ struct file_writer time_t max_hold; }; +struct dest_extra +{ + GList *file_writers; + CRITICAL_SECTION cs_file_writers; +}; + /* forward declarations */ static unsigned __stdcall writer_thread_proc( void* arg ); @@ -284,15 +290,18 @@ error: */ static void detach_writer_from_destination( struct file_writer* writer ) { + struct dest_extra *extra; + TRACE_ENTER( "%p\n", writer ); if( !writer->destination ) { TRACE_LEAVE( "done; already detached\n" ); return; } - EnterCriticalSection( &writer->destination->cs_file_writers ); - writer->destination->file_writers = g_list_remove( writer->destination->file_writers, writer ); - LeaveCriticalSection( &writer->destination->cs_file_writers ); + extra = writer->destination->extra; + EnterCriticalSection( &extra->cs_file_writers ); + extra->file_writers = g_list_remove( extra->file_writers, writer ); + LeaveCriticalSection( &extra->cs_file_writers ); writer->destination = NULL; TRACE_LEAVE( "done\n" ); } @@ -429,19 +438,20 @@ static void make_file_name( char* pattern, struct message* message, char* buffer } /****************************************************************************** - * write_message + * put_message_to_file_dest */ -void write_message( struct message* msg, struct destination* destination ) +static void put_message_to_file_dest( struct destination* destination, struct message* msg ) { + struct dest_extra *extra = destination->extra; char file_name[ MAX_PATH ]; GList *item; struct file_writer *writer; TRACE_ENTER( "msg=%p, destination=%s\n", msg, destination->name ); - make_file_name( destination->file, msg, file_name ); - EnterCriticalSection( &destination->cs_file_writers ); + make_file_name( destination->u.file.name_pattern, msg, file_name ); + EnterCriticalSection( &extra->cs_file_writers ); /* find existing writer */ - for( writer = NULL, item = destination->file_writers; item; item = item->next ) + for( writer = NULL, item = extra->file_writers; item; item = item->next ) if( strcmp( ((struct file_writer*) (item->data))->file_name, file_name ) == 0 ) { writer = item->data; @@ -454,7 +464,7 @@ void write_message( struct message* msg, struct destination* destination ) if( !writer ) goto done; /* add writer to destination */ - destination->file_writers = g_list_append( destination->file_writers, writer ); + extra->file_writers = g_list_append( extra->file_writers, writer ); writer->destination = destination; } /* put message into queue */ @@ -463,41 +473,50 @@ void write_message( struct message* msg, struct destination* destination ) ReleaseSemaphore( writer->fifo_semaphore, 1, NULL ); done: - LeaveCriticalSection( &destination->cs_file_writers ); + LeaveCriticalSection( &extra->cs_file_writers ); TRACE_LEAVE( "done\n" ); } /****************************************************************************** - * fini_writer + * finalize_file_dest + * + * stop all writers */ -void fini_writer() +static void finalize_file_dest( struct destination* destination ) { - GList *dest_item; + struct dest_extra *extra = destination->extra; + GList *wr_item; - TRACE_ENTER( "\n" ); + TRACE_ENTER( "destination=%s\n", destination->name ); /* setting shutdown event */ - for( dest_item = destinations; dest_item; dest_item = dest_item->next ) + EnterCriticalSection( &extra->cs_file_writers ); + for( wr_item = extra->file_writers; wr_item; wr_item = wr_item->next ) { - struct destination *destination = dest_item->data; - GList *wr_item; - - EnterCriticalSection( &destination->cs_file_writers ); - for( wr_item = destination->file_writers; wr_item; wr_item = wr_item->next ) - { - struct file_writer *writer = wr_item->data; - SetEvent( writer->shutdown_event ); - } - LeaveCriticalSection( &destination->cs_file_writers ); + struct file_writer *writer = wr_item->data; + SetEvent( writer->shutdown_event ); } + LeaveCriticalSection( &extra->cs_file_writers ); TRACE_2( "waiting for shutdown\n" ); - for(;;) + while( extra->file_writers ) { - for( dest_item = destinations; dest_item; dest_item = dest_item->next ) - if( ((struct destination*) (dest_item->data))->file_writers ) - break; - if( !dest_item ) - break; Sleep( 60 ); } TRACE_LEAVE( "done\n" ); } + +/****************************************************************************** + * init_destination_file + * + * initialize file destination + */ +gboolean init_destination_file( struct destination* destination ) +{ + struct dest_extra *extra = g_malloc( sizeof(struct dest_extra) ); + + destination->extra = extra; + destination->put = put_message_to_file_dest; + destination->fini = finalize_file_dest; + extra->file_writers = NULL; + InitializeCriticalSection( &extra->cs_file_writers ); + return TRUE; +} |