An unsuccessful attempt to fix output corruption in flood's relative_times. Index: flood_report_relative_times.c =================================================================== --- flood_report_relative_times.c (revision 449338) +++ flood_report_relative_times.c (working copy) @@ -27,10 +27,20 @@ extern apr_file_t *local_stdout; extern apr_file_t *local_stderr; +struct relative_times { + apr_thread_mutex_t *mutex; +}; + apr_status_t relative_times_report_init(report_t **report, config_t *config, const char *profile_name, apr_pool_t *pool) { - return APR_SUCCESS; + struct relative_times *me; + me = apr_palloc(pool, sizeof(struct relative_times)); + if (me == NULL) { + return APR_ENOMEM; + } + *report = me; + return apr_thread_mutex_create(&me->mutex, APR_THREAD_MUTEX_DEFAULT, pool); } apr_status_t relative_times_process_stats(report_t *report, int verified, request_t *req, response_t *resp, flood_timer_t *timer) @@ -38,6 +48,7 @@ #define FLOOD_PRINT_BUF 256 apr_size_t buflen; char buf[FLOOD_PRINT_BUF]; + struct relative_times *me = report; buflen = apr_snprintf(buf, FLOOD_PRINT_BUF, "%" APR_INT64_T_FMT " %" APR_INT64_T_FMT @@ -60,10 +71,15 @@ apr_snprintf(buf+buflen, FLOOD_PRINT_BUF-buflen, " %d ", verified); } - /* FIXME: this call may need to be in a critical section */ #if APR_HAS_THREADS + apr_thread_mutex_lock(me->mutex); + apr_file_lock(local_stdout, APR_FLOCK_EXCLUSIVE); apr_file_printf(local_stdout, "%s %ld %s\n", buf, apr_os_thread_current(), req->uri); + apr_file_flush(local_stdout); + apr_file_unlock(local_stdout); + apr_thread_mutex_unlock(me->mutex); #else +#error no threads? apr_file_printf(local_stdout, "%s %d %s\n", buf, getpid(), req->uri); #endif @@ -77,5 +93,7 @@ apr_status_t relative_times_destroy_report(report_t *report) { + struct relative_times *me = report; + apr_thread_mutex_destroy(me->mutex); return APR_SUCCESS; }