View | Details | Raw Unified | Return to bug 60988
Collapse All | Expand All

(-)a/server/main.c (-11 / +34 lines)
Lines 260-284 static void show_compile_settings(void) Link Here
260
#endif
260
#endif
261
}
261
}
262
262
263
#define TASK_SWITCH_SLEEP 10000
263
#define DEFAULT_PRE_EXIT_PAUSE_TIME 10000
264
265
/*
266
 * Pauses before exiting by sleeping for a configurable amount of time,
267
 * defaulting to DEFAULT_PRE_EXIT_PAUSE_TIME. The goal is to allow any in-flight
268
 * log entries to be flushed to disk before exiting. Failure to do so can result
269
 * in some of the entries being lost. This is of particular importance for piped
270
 * loggers, which are outside of our control and can take an arbitrarily long
271
 * time to complete. The default is intended to at least cause a context switch
272
 * to give the other process(es) time. If that isn't enough, the
273
 * PRE_EXIT_PAUSE_TIME environment variable can be used to configure a longer
274
 * pause time.
275
 */
276
static void pre_exit_pause(void)
277
{
278
    apr_interval_time_t sleep_time;
279
    const char *sleep_time_env;
280
281
    sleep_time = DEFAULT_PRE_EXIT_PAUSE_TIME;
282
    sleep_time_env = getenv("PRE_EXIT_PAUSE_TIME");
283
284
    if (sleep_time_env) {
285
        if (ap_timeout_parameter_parse(sleep_time_env, &sleep_time, "ms") != APR_SUCCESS) {
286
            sleep_time = DEFAULT_PRE_EXIT_PAUSE_TIME;
287
        }
288
    }
289
290
    if (sleep_time < 0) {
291
        sleep_time = DEFAULT_PRE_EXIT_PAUSE_TIME;
292
    }
293
294
    apr_sleep(sleep_time);
295
}
264
296
265
static void destroy_and_exit_process(process_rec *process,
297
static void destroy_and_exit_process(process_rec *process,
266
                                     int process_exit_value)
298
                                     int process_exit_value)
267
{
299
{
268
    /*
269
     * Sleep for TASK_SWITCH_SLEEP micro seconds to cause a task switch on
270
     * OS layer and thus give possibly started piped loggers a chance to
271
     * process their input. Otherwise it is possible that they get killed
272
     * by us before they can do so. In this case maybe valueable log messages
273
     * might get lost.
274
     */
275
276
    /* If we are to print an error, we need the name before we destroy pool.
300
    /* If we are to print an error, we need the name before we destroy pool.
277
     * short_name is a pointer into argv, so remains valid.
301
     * short_name is a pointer into argv, so remains valid.
278
     */
302
     */
279
    const char *name = process->short_name ? process->short_name : "httpd";
303
    const char *name = process->short_name ? process->short_name : "httpd";
280
304
281
    apr_sleep(TASK_SWITCH_SLEEP);
305
    pre_exit_pause();
282
    ap_main_state = AP_SQ_MS_EXITING;
306
    ap_main_state = AP_SQ_MS_EXITING;
283
    apr_pool_destroy(process->pool); /* and destroy all descendent pools */
307
    apr_pool_destroy(process->pool); /* and destroy all descendent pools */
284
    apr_terminate();
308
    apr_terminate();
285
- 

Return to bug 60988