Bug 28469 - stderr is closed when it is used by jk_logger_file.c
Summary: stderr is closed when it is used by jk_logger_file.c
Status: RESOLVED FIXED
Alias: None
Product: Tomcat Connectors
Classification: Unclassified
Component: Common (show other bugs)
Version: unspecified
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-19 14:21 UTC by Max Kellermann
Modified: 2008-10-05 03:09 UTC (History)
0 users



Attachments
workaround patch (untested) (1.24 KB, patch)
2004-06-01 12:24 UTC, Max Kellermann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Kellermann 2004-04-19 14:21:10 UTC
I'm using mod_jk2 2.0.4. jk_logger_file.c uses apr_file_open_stderr to create a
stderr handle. jk2_logger_file_init is called twice - once from setProperty, and
once from jk2_workerEnv_init. on the second call, the previously created stderr
handle is closed, and another apr_file_t handle is created - on the already
closed file handle 2. nothing is logged from now on, EBADF.

(there is no separate bugzilla product for tomcat-connectors, so I put this
report into Tomcat 5/Native:JK, no idea if this is correct)
Comment 1 Yoav Shapira 2004-05-28 14:42:44 UTC
This is an OK place to put the bug.  So we should modify the jk2_workerEnv_init 
method so that if it already has a handle on stderr, it won't close and reopen? 
Why doesn't it work actually, after all the second stderr handle should still 
be valid, no?

If you have an actual patch to jk_logger_file.c it'd be welcome.
Comment 2 Max Kellermann 2004-06-01 09:02:45 UTC
Explanation: apr_file_open_stderr does not dup() the system stderr filehandle
(fd 2), it just creates a new APR wrapper for fd 2. If you close the APR handle,
the original system stderr is closed, and all APR wrappers for fd 2 become
invalid. This might be considered an APR bug, because the abstraction offered by
APR is not consistent here.

I'll attach my solution later today when I'm at my office.
Comment 3 Max Kellermann 2004-06-01 12:24:21 UTC
Created attachment 11708 [details]
workaround patch (untested)
Comment 4 Max Kellermann 2004-06-01 12:30:18 UTC
I have now attached a patch which works around the problem - it tests whether
the previous name was "stderr" and simply doesn't close stderr handles. I just
wrote down that patch without testing... just an idea to start with.

Previously, I have commented out the apr_file_close line in
jk2_logger_file_init. Object destruction and freeing memory doesn't really work
in jk2 anyways (ever tried to run a small JK2 test program with dmalloc or
similar heap debuggers? For some classes, there aren't even destructors
available.. - email me if you want my help with the code cleanup required here)
Comment 5 Yoav Shapira 2004-06-16 14:34:59 UTC
OK, patch applied to file.