aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryaworsky <yaworsky>2005-11-03 04:33:27 +0000
committeryaworsky <yaworsky>2005-11-03 04:33:27 +0000
commitd826fc5be99dc2d32d76d1c2afb2c45f2b09b67f (patch)
treefd1a2f1f8163a7999ea61563255023bf73afd812
parent5672ec2412c775691ee51f6427e3ba2d0a0b9457 (diff)
downloadsyslog-win32-d826fc5be99dc2d32d76d1c2afb2c45f2b09b67f.tar.gz
syslog-win32-d826fc5be99dc2d32d76d1c2afb2c45f2b09b67f.tar.xz
syslog-win32-d826fc5be99dc2d32d76d1c2afb2c45f2b09b67f.zip
Avoid race
-rw-r--r--daemon/dest_file.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/daemon/dest_file.c b/daemon/dest_file.c
index a1e917b..3925499 100644
--- a/daemon/dest_file.c
+++ b/daemon/dest_file.c
@@ -246,11 +246,13 @@ static void destroy_file_writer( struct file_writer* writer )
/******************************************************************************
* create_file_writer
*/
-static struct file_writer* create_file_writer( gchar* file_name )
+static struct file_writer* create_file_writer( gchar* file_name,
+ struct destination* destination )
{
struct file_writer *ret;
unsigned writer_thread_id;
HANDLE *writer_thread;
+ struct dest_extra *extra;
TRACE_ENTER( "file_name=%s\n", file_name );
ret = g_malloc0( sizeof(struct file_writer) );
@@ -268,14 +270,23 @@ static struct file_writer* create_file_writer( gchar* file_name )
ERR( "Cannot create event; error %lu\n", GetLastError() );
goto error;
}
+
writer_thread = (HANDLE) _beginthreadex( NULL, 0, writer_thread_proc, ret,
- 0, &writer_thread_id );
+ CREATE_SUSPENDED, &writer_thread_id );
if( !writer_thread )
{
ERR( "Cannot create thread; error %lu\n", GetLastError() );
goto error;
}
+
+ /* add writer to destination */
+ extra = destination->extra;
+ extra->file_writers = g_list_append( extra->file_writers, ret );
+ ret->destination = destination;
+
+ ResumeThread( writer_thread );
CloseHandle( writer_thread );
+
TRACE_LEAVE( "done; ret=%p\n", ret );
return ret;
@@ -464,12 +475,9 @@ static void put_message_to_file_dest( struct destination* destination, struct me
if( !writer )
{
/* create new writer */
- writer = create_file_writer( file_name );
+ writer = create_file_writer( file_name, destination );
if( !writer )
goto done;
- /* add writer to destination */
- extra->file_writers = g_list_append( extra->file_writers, writer );
- writer->destination = destination;
}
/* put message into queue */
reference_message( msg );