mirror of
https://github.com/arut/nginx-rtmp-module.git
synced 2025-08-06 15:00:18 +08:00
explicitly close file descriptors in child to escape epoll signaling wrong events
This commit is contained in:
@ -242,7 +242,7 @@ ngx_rtmp_enotify_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_rtmp_enotify_exec(ngx_rtmp_session_t *s, ngx_rtmp_enotify_conf_t *ec)
|
ngx_rtmp_enotify_exec(ngx_rtmp_session_t *s, ngx_rtmp_enotify_conf_t *ec)
|
||||||
{
|
{
|
||||||
#ifndef NGX_WIN32
|
#if !(NGX_WIN32)
|
||||||
int pid, fd;
|
int pid, fd;
|
||||||
ngx_str_t a, *arg;
|
ngx_str_t a, *arg;
|
||||||
char **args;
|
char **args;
|
||||||
|
@ -308,10 +308,10 @@ ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e, ngx_int_t term)
|
|||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
||||||
{
|
{
|
||||||
#ifndef NGX_WIN32
|
#if !(NGX_WIN32)
|
||||||
ngx_rtmp_exec_app_conf_t *eacf;
|
ngx_rtmp_exec_app_conf_t *eacf;
|
||||||
ngx_rtmp_exec_ctx_t *ctx;
|
ngx_rtmp_exec_ctx_t *ctx;
|
||||||
int pid, fd;
|
int pid, fd, maxfd;
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
int ret;
|
int ret;
|
||||||
ngx_rtmp_exec_conf_t *ec;
|
ngx_rtmp_exec_conf_t *ec;
|
||||||
@ -325,6 +325,8 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
|||||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
|
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
|
||||||
e = ctx->execs + n;
|
e = ctx->execs + n;
|
||||||
|
|
||||||
|
ngx_memzero(e, sizeof(*e));
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"exec: starting child '%V'",
|
"exec: starting child '%V'",
|
||||||
&ec->cmd);
|
&ec->cmd);
|
||||||
@ -360,6 +362,17 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
|
|||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
/* child */
|
/* child */
|
||||||
|
|
||||||
|
/* close all descriptors but pipe write end */
|
||||||
|
maxfd = sysconf(_SC_OPEN_MAX);
|
||||||
|
for (fd = 0; fd < maxfd; ++fd) {
|
||||||
|
if (fd == pipefd[1]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
fd = open("/dev/null", O_RDWR);
|
fd = open("/dev/null", O_RDWR);
|
||||||
|
|
||||||
dup2(fd, STDIN_FILENO);
|
dup2(fd, STDIN_FILENO);
|
||||||
|
Reference in New Issue
Block a user