Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file descriptor leak on /dev/urandom each time nginx reloads #6

Merged
merged 1 commit into from
Feb 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ngx_txid_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ngx_txid_get(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data
}

static ngx_int_t
ngx_txid_init_module(ngx_cycle_t *cycle) {
ngx_txid_init_process(ngx_cycle_t *cycle) {
txid_dev_urandom = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (txid_dev_urandom == -1) {
ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
Expand All @@ -130,6 +130,13 @@ ngx_txid_init_module(ngx_cycle_t *cycle) {
return NGX_OK;
}

static void
ngx_txid_exit_process(ngx_cycle_t *cycle) {
if (txid_dev_urandom && txid_dev_urandom != -1) {
close(txid_dev_urandom);
}
}

static ngx_str_t ngx_txid_variable_name = ngx_string("txid");

static ngx_int_t ngx_txid_add_variables(ngx_conf_t *cf)
Expand Down Expand Up @@ -172,11 +179,11 @@ ngx_module_t ngx_txid_module = {
ngx_txid_module_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
ngx_txid_init_module, /* init module */
NULL, /* init process */
NULL, /* init module */
ngx_txid_init_process, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
ngx_txid_exit_process, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
Expand Down