当前我使用以下方式来关闭多余的fd,单是我不能确定这样做有没有后遗症。
至少能解决我当前遇到的问题。
--- a/src/ngx_http_lua_pipe.c 2019-11-23 17:56:04.992591459 +0800
+++ b/src/ngx_http_lua_pipe.c 2019-11-23 17:56:10.667807727 +0800
@@ -679,16 +679,6 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua
exit(EXIT_FAILURE);
}
- /* close listening socket fd */
- ls = ngx_cycle->listening.elts;
- for (i = 0; i < ngx_cycle->listening.nelts; i++) {
- if (ngx_close_socket(ls[i].fd) == -1) {
- ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_socket_errno,
- "lua pipe child " ngx_close_socket_n
- " %V failed", &ls[i].addr_text);
- }
- }
-
/* close and dup pipefd */
if (close(in[1]) == -1) {
ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno,
@@ -758,6 +748,19 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua
}
}
+ /* close redundant fd */
+ int self_fd;
+ struct dirent *dir_entry;
+ DIR *dir = opendir("/proc/self/fd");
+ if(dir) {
+ while ((dir_entry = readdir(dir))) {
+ self_fd = strtol(dir_entry->d_name, NULL, 10);
+ if(self_fd > 2)
+ close(self_fd);
+ }
+ closedir(dir);
+ }
+
if (execvp(file, (char * const *) argv) == -1) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, ngx_errno,
"lua pipe child execvp() failed while executing %s",