[
https://issues.apache.org/jira/browse/AXIS2C-1655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13842357#comment-13842357
]
Jake Scott commented on AXIS2C-1655:
------------------------------------
I can see several ways to fix this issue, all fairly simple :
1. Check that the file_name member of axutil_log_impl_t is populated and only
close the stream if it is :
{code}
--- util/src/log.c.orig 2013-12-07 19:11:47.515603093 -0500
+++ util/src/log.c 2013-12-07 19:12:02.266188064 -0500
@@ -76,7 +76,7 @@
{
axutil_thread_mutex_destroy(log_impl->mutex);
}
- if(log_impl->stream)
+ if(log_impl->stream && log_impl->file_name)
{
axutil_file_handler_close(log_impl->stream);
}
{code}
However, this relies on code setting file_name to NULL if the log file can't be
opened.
2. A more robust approach but slightly more code is to record whether the
library opened the stream or used some other stream :
{code}
(jacob@asbo) {0} ~/src/axis2/trunk >diff -u util/src/log.c.orig util/src/log.c
--- util/src/log.c.orig 2013-12-07 19:11:47.515603093 -0500
+++ util/src/log.c 2013-12-07 19:20:40.494660059 -0500
@@ -55,6 +55,7 @@
void *stream;
axis2_char_t *file_name;
axutil_thread_mutex_t *mutex;
+ int mystream;
};
#define AXUTIL_INTF_TO_IMPL(log) ((axutil_log_impl_t*)(log))
@@ -76,7 +77,7 @@
{
axutil_thread_mutex_destroy(log_impl->mutex);
}
- if(log_impl->stream)
+ if(log_impl->stream && log_impl->mystream)
{
axutil_file_handler_close(log_impl->stream);
}
@@ -108,6 +109,8 @@
if(!log_impl)
return NULL;
+ log_impl->mystream = 0;
+
log_impl->mutex = axutil_thread_mutex_create(allocator,
AXIS2_THREAD_MUTEX_DEFAULT);
if(!log_impl->mutex)
@@ -169,7 +172,11 @@
axutil_thread_mutex_unlock(log_impl->mutex);
- if(!log_impl->stream)
+ /* If we opened a file, mark this as our stream so that we know we can
+ * close it safely */
+ if(log_impl->stream)
+ log_impl->mystream = 1;
+ else
log_impl->stream = stderr;
/* by default, log is enabled */
@@ -505,6 +512,7 @@
log_impl->file_name = NULL;
log_impl->log.size = AXUTIL_LOG_FILE_SIZE;
log_impl->stream = stderr;
+ log_impl->mystream = 0; /* Don't allow stderr to be closed */
axutil_thread_mutex_unlock(log_impl->mutex);
/* by default, log is enabled */
log_impl->log.enabled = 1;
{code}
> Client library closes stderr on axutil_env_free()
> -------------------------------------------------
>
> Key: AXIS2C-1655
> URL: https://issues.apache.org/jira/browse/AXIS2C-1655
> Project: Axis2-C
> Issue Type: Bug
> Components: core/clientapi
> Affects Versions: 1.6.0
> Reporter: Jake Scott
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The client API defaults to using stderr when the specified log file cannot be
> opened. The axutil_log_impl_free() function blindly closes the log stream
> without checking whether it had opened the stream or not. This results in
> stderr being closed in certain conditions.
> This is effecting a custom Apache module; when Apache runs daemonized, it
> switches its working directory to the root. This causes the Axis2 log file
> open to fail and use stderr instead. When the module is done with the Axis2
> environment, it frees it - and at that time, Apache's stderr is closed. From
> then on, accept() returns fd2 and so the network ends up getting spammed with
> Apache log messages.
--
This message was sent by Atlassian JIRA
(v6.1#6144)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]