pombreda / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

glog does not deal with forked child processes #101

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Fork a child process
2. log both the in parent as well as in the child

What is the expected output? What do you see instead?

Both child/parent logs go to the same log file. Expectation is that child will 
log to its own log files.

What version of the product are you using? On what operating system?

0.3.1-1. Ubuntu 11.04.

Please provide any additional information below.

I'm attaching a patch for the fix. The patch uses pthread_atfork() to call a 
handler in the child process that closes all the log files that  the child 
inherits from the parent.

Original issue reported on code.google.com by mohit.a...@gmail.com on 1 Oct 2011 at 8:23

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I should add that the patch I gave only supports forks in processes that are 
single-threaded. The problem in a multi-threaded process is that one thread in 
that process might be executing in the glog library while holding some locks 
and another thread calls a 'fork'. In the child, only the thread that called 
'fork' would be created - the remaining threads won't be - so there would be 
some locks that would never get unlocked by anyone. So there's potential for 
deadlock.

Here's a potential solution for supporting forks from multi-threaded 
applications:

All calls into glog would go through a reader-writers lock that would be 
acquired normally for read access. glog library would call pthread_atfork() 
that would provide all three handlers - 'prepare', 'parent', and 'child' (see 
http://linux.die.net/man/3/pthread_atfork). The 'prepare' handler would acquire 
the readers-writers lock with write access - this would ensure that no other 
application threads are executing within the glog library. Both the 'parent' 
and 'child' handlers would then release this lock. The child handler in 
addition to would delete the LogDestination objects as it is already being done 
by the patch I provided.

Original comment by mohit.a...@gmail.com on 16 Jun 2012 at 6:59

GoogleCodeExporter commented 9 years ago
Uploading patch with some minor fixes ...

Original comment by mohit.a...@gmail.com on 16 Jun 2012 at 7:48

Attachments: