log.c -- 看文档,还不如看代码来的简单。[12]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 liangbowen 的 blog

        break;

    case apr_oc_reason_unregister:
        break;
    }
}


static apr_status_t piped_log_cleanup_for_exec(void *data)
{
    piped_log *pl = data;

    apr_file_close(ap_piped_log_read_fd(pl));
    apr_file_close(ap_piped_log_write_fd(pl));
    return apr_success;
}


static apr_status_t piped_log_cleanup(void *data)
{
    piped_log *pl = data;

    if (pl->pid != null) {
        apr_proc_kill(pl->pid, sigterm);
    }
    return piped_log_cleanup_for_exec(data);
}


ap_declare(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
{
    piped_log *pl;

    pl = apr_palloc(p, sizeof (*pl));
    pl->p = p;
    pl->program = apr_pstrdup(p, program);
    pl->pid = null;
    if (apr_file_pipe_create(&ap_piped_log_read_fd(pl),
                             &ap_piped_log_write_fd(pl), p) != apr_success) {
        return null;
    }
    apr_pool_cleanup_register(p, pl, piped_log_cleanup,
                              piped_log_cleanup_for_exec);
    if (piped_log_spawn(pl) == -1) {
        int save_errno = errno;
        apr_pool_cleanup_kill(p, pl, piped_log_cleanup);
        apr_file_close(ap_piped_log_read_fd(pl));
        apr_file_close(ap_piped_log_write_fd(pl));
        errno = save_errno;
        return null;
    }
    return pl;
}

#else /* !ap_have_reliable_piped_logs */

static apr_status_t piped_log_cleanup(void *data)
{
    piped_log *pl = data;

    apr_file_close(ap_piped_log_write_fd(pl));
    return apr_success;
}

ap_declare(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
{
    piped_log *pl;
    apr_file_t *dummy = null;
    int rc;

    rc = log_child(p, program, &dummy);
    if (rc != apr_success) {
        ap_log_error(aplog_mark, aplog_startup, rc, null,
                     "couldn't start piped log process");
        return null;
    }

    pl = apr_palloc(p, sizeof (*pl));
    pl->p = p;
    ap_piped_log_read_fd(pl) = null;
    ap_piped_log_write_fd(pl) = dummy;
    apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);

    return pl;
}

#endif

ap_declare(void) ap_close_piped_log(piped_log *pl)
{
    apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
}

ap_implement_hook_void(error_log,
                       (const char *file, int line, int level,
                        apr_status_t status, const server_rec *s,
                        const request_rec *r, apr_pool_t *pool,
                        const char *errstr), (file, line, level,
                        status, s, r, pool, errstr))

本文关键:log.c -- 看文档,还不如看代码来的简单。
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top