Merge branch 'exec-static'

This commit is contained in:
Roman Arutyunyan 2013-02-02 17:14:46 +04:00
commit c0ad999f37
5 changed files with 324 additions and 118 deletions

View file

@ -32,6 +32,9 @@ static char * ngx_rtmp_merge_applications(ngx_conf_t *cf,
ngx_uint_t ngx_rtmp_max_module;
ngx_thread_volatile ngx_event_t *ngx_rtmp_init_process_events;
static ngx_command_t ngx_rtmp_commands[] = {
{ ngx_string("rtmp"),

View file

@ -570,6 +570,9 @@ ngx_rtmp_is_codec_header(ngx_chain_t *in)
}
extern ngx_thread_volatile ngx_event_t *ngx_rtmp_init_process_events;
extern ngx_rtmp_bandwidth_t ngx_rtmp_bw_out;
extern ngx_rtmp_bandwidth_t ngx_rtmp_bw_in;

View file

@ -16,12 +16,18 @@ static ngx_rtmp_publish_pt next_publish;
static ngx_rtmp_close_stream_pt next_close_stream;
static ngx_int_t ngx_rtmp_exec_init_process(ngx_cycle_t *cycle);
static ngx_int_t ngx_rtmp_exec_postconfiguration(ngx_conf_t *cf);
static void * ngx_rtmp_exec_create_main_conf(ngx_conf_t *cf);
static char * ngx_rtmp_exec_init_main_conf(ngx_conf_t *cf, void *conf);
static void * ngx_rtmp_exec_create_app_conf(ngx_conf_t *cf);
static char * ngx_rtmp_exec_merge_app_conf(ngx_conf_t *cf,
void *parent, void *child);
void *parent, void *child);
static char * ngx_rtmp_exec_exec(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
void *conf);
static char * ngx_rtmp_exec_exec_static(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static void ngx_rtmp_exec_respawn(ngx_event_t *ev);
#define NGX_RTMP_EXEC_RESPAWN 0x01
@ -30,41 +36,49 @@ static char * ngx_rtmp_exec_exec(ngx_conf_t *cf, ngx_command_t *cmd,
typedef struct {
ngx_str_t cmd;
ngx_array_t args; /* ngx_str_t */
ngx_array_t args; /* ngx_str_t */
} ngx_rtmp_exec_conf_t;
typedef struct {
ngx_array_t execs; /* ngx_rtmp_exec_conf_t */
ngx_msec_t respawn_timeout;
ngx_flag_t respawn;
ngx_int_t kill_signal;
} ngx_rtmp_exec_app_conf_t;
typedef struct {
ngx_rtmp_session_t *session;
size_t index;
ngx_rtmp_exec_conf_t *conf;
ngx_log_t *log;
ngx_rtmp_session_t *session; /* NULL for init execs */
unsigned active:1;
int pid;
ngx_pid_t pid;
ngx_pid_t *save_pid;
int pipefd;
ngx_connection_t dummy_conn; /*needed by ngx_xxx_event*/
ngx_event_t read_evt, write_evt;
ngx_event_t respawn_evt;
ngx_msec_t respawn_timeout;
} ngx_rtmp_exec_t;
typedef struct {
ngx_array_t confs; /* ngx_rtmp_exec_conf_t */
ngx_array_t execs; /* ngx_rtmp_exec_t */
ngx_msec_t respawn_timeout;
} ngx_rtmp_exec_main_conf_t;
typedef struct {
ngx_array_t confs; /* ngx_rtmp_exec_conf_t */
ngx_int_t kill_signal;
ngx_flag_t respawn;
} ngx_rtmp_exec_app_conf_t;
typedef struct {
u_char name[NGX_RTMP_MAX_NAME];
ngx_rtmp_exec_t *execs;
ngx_array_t execs;
} ngx_rtmp_exec_ctx_t;
static char *ngx_rtmp_exec_kill_signal(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static ngx_int_t ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e,
ngx_int_t term);
static ngx_int_t ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n);
static ngx_int_t ngx_rtmp_exec_kill(ngx_rtmp_exec_t *e, ngx_int_t kill_signal);
static ngx_int_t ngx_rtmp_exec_run(ngx_rtmp_exec_t *e);
static ngx_command_t ngx_rtmp_exec_commands[] = {
@ -75,6 +89,13 @@ static ngx_command_t ngx_rtmp_exec_commands[] = {
NGX_RTMP_APP_CONF_OFFSET,
0,
NULL },
{ ngx_string("exec_static"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_1MORE,
ngx_rtmp_exec_exec_static,
NGX_RTMP_MAIN_CONF_OFFSET,
0,
NULL },
{ ngx_string("respawn"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
@ -86,8 +107,8 @@ static ngx_command_t ngx_rtmp_exec_commands[] = {
{ ngx_string("respawn_timeout"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_exec_app_conf_t, respawn_timeout),
NGX_RTMP_MAIN_CONF_OFFSET,
offsetof(ngx_rtmp_exec_main_conf_t, respawn_timeout),
NULL },
{ ngx_string("exec_kill_signal"),
@ -104,8 +125,8 @@ static ngx_command_t ngx_rtmp_exec_commands[] = {
static ngx_rtmp_module_t ngx_rtmp_exec_module_ctx = {
NULL, /* preconfiguration */
ngx_rtmp_exec_postconfiguration, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
ngx_rtmp_exec_create_main_conf, /* create main configuration */
ngx_rtmp_exec_init_main_conf, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_rtmp_exec_create_app_conf, /* create app configuration */
@ -120,7 +141,7 @@ ngx_module_t ngx_rtmp_exec_module = {
NGX_RTMP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
ngx_rtmp_exec_init_process, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
@ -163,6 +184,64 @@ static ngx_rtmp_eval_t * ngx_rtmp_exec_eval_p[] = {
};
static void *
ngx_rtmp_exec_create_main_conf(ngx_conf_t *cf)
{
ngx_rtmp_exec_main_conf_t *emcf;
emcf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_exec_main_conf_t));
if (emcf == NULL) {
return NULL;
}
emcf->respawn_timeout = NGX_CONF_UNSET_MSEC;
if (ngx_array_init(&emcf->confs, cf->pool, 1,
sizeof(ngx_rtmp_exec_conf_t)) != NGX_OK)
{
return NULL;
}
return emcf;
}
static char *
ngx_rtmp_exec_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_rtmp_exec_main_conf_t *emcf = conf;
ngx_rtmp_exec_conf_t *ec;
ngx_rtmp_exec_t *e;
ngx_uint_t n;
if (emcf->respawn_timeout == NGX_CONF_UNSET_MSEC) {
emcf->respawn_timeout = 5000;
}
if (ngx_array_init(&emcf->execs, cf->pool, emcf->confs.nelts,
sizeof(ngx_rtmp_exec_t)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
e = ngx_array_push_n(&emcf->execs, emcf->confs.nelts);
if (e == NULL) {
return NGX_CONF_ERROR;
}
ec = emcf->confs.elts;
for (n = 0; n < emcf->confs.nelts; ++n, ++e, ++ec) {
ngx_memzero(e, sizeof(*e));
e->conf = ec;
e->log = &cf->cycle->new_log;
e->respawn_timeout = emcf->respawn_timeout;
}
return NGX_CONF_OK;
}
static void *
ngx_rtmp_exec_create_app_conf(ngx_conf_t *cf)
{
@ -174,11 +253,10 @@ ngx_rtmp_exec_create_app_conf(ngx_conf_t *cf)
}
eacf->respawn = NGX_CONF_UNSET;
eacf->respawn_timeout = NGX_CONF_UNSET;
eacf->kill_signal = NGX_CONF_UNSET;
if (ngx_array_init(&eacf->execs, cf->pool, 1,
sizeof(ngx_rtmp_exec_conf_t)) != NGX_OK)
if (ngx_array_init(&eacf->confs, cf->pool, 1,
sizeof(ngx_rtmp_exec_conf_t)) != NGX_OK)
{
return NULL;
}
@ -196,17 +274,15 @@ ngx_rtmp_exec_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_rtmp_exec_conf_t *ec, *pec;
ngx_conf_merge_value(conf->respawn, prev->respawn, 1);
ngx_conf_merge_msec_value(conf->respawn_timeout, prev->respawn_timeout,
5000);
ngx_conf_merge_value(conf->kill_signal, prev->kill_signal, SIGKILL);
if (prev->execs.nelts) {
ec = ngx_array_push_n(&conf->execs, prev->execs.nelts);
if (prev->confs.nelts) {
ec = ngx_array_push_n(&conf->confs, prev->confs.nelts);
if (ec == NULL) {
return NGX_CONF_ERROR;
}
pec = prev->execs.elts;
for (n = 0; n < prev->execs.nelts; ++n, ++ec, ++pec) {
pec = prev->confs.elts;
for (n = 0; n < prev->confs.nelts; ++n, ++ec, ++pec) {
*ec = *pec;
}
}
@ -215,61 +291,97 @@ ngx_rtmp_exec_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
}
static ngx_int_t
ngx_rtmp_exec_init_process(ngx_cycle_t *cycle)
{
ngx_rtmp_core_main_conf_t *cmcf = ngx_rtmp_core_main_conf;
ngx_rtmp_core_srv_conf_t **cscf;
ngx_rtmp_conf_ctx_t *cctx;
ngx_rtmp_exec_main_conf_t *emcf;
ngx_rtmp_exec_t *e;
ngx_uint_t n;
if (cmcf->servers.nelts == 0) {
return NGX_ERROR;
}
/* execs are always started by the first worker */
if (ngx_process_slot) {
return NGX_OK;
}
cscf = cmcf->servers.elts;
cctx = (*cscf)->ctx;
emcf = cctx->main_conf[ngx_rtmp_exec_module.ctx_index];
/* FreeBSD note:
* When worker is restarted, child process (ffmpeg) will
* not be terminated if it's connected to another
* (still alive) worker. That leads to starting
* another instance of exec_static process.
* Need to kill previously started processes.
*
* On Linux "prctl" syscall is used to kill child with
* SIGTERM when nginx worker is terminated.
*/
e = emcf->execs.elts;
for (n = 0; n < emcf->execs.nelts; ++n, ++e) {
e->respawn_evt.data = e;
e->respawn_evt.log = e->log;
e->respawn_evt.handler = ngx_rtmp_exec_respawn;
ngx_post_event((&e->respawn_evt), &ngx_rtmp_init_process_events);
}
return NGX_OK;
}
static void
ngx_rtmp_exec_respawn(ngx_event_t *ev)
{
ngx_rtmp_exec_t *e;
e = ev->data;
ngx_rtmp_exec_run(e->session, e->index);
ngx_rtmp_exec_run((ngx_rtmp_exec_t *) ev->data);
}
static void
ngx_rtmp_exec_child_dead(ngx_event_t *ev)
{
ngx_connection_t *dummy_conn;
ngx_rtmp_exec_t *e;
ngx_rtmp_session_t *s;
ngx_rtmp_exec_app_conf_t *eacf;
ngx_connection_t *dummy_conn = ev->data;
ngx_rtmp_exec_t *e;
dummy_conn = ev->data;
e = dummy_conn->data;
s = e->session;
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: child %ui exited; %s",
(ngx_int_t)e->pid,
eacf->respawn ? "respawning" : "ignoring");
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: child %ui exited; %s", (ngx_int_t) e->pid,
e->respawn_timeout == NGX_CONF_UNSET_MSEC ? "respawning" :
"ignoring");
ngx_rtmp_exec_kill(s, e, 0);
ngx_rtmp_exec_kill(e, 0);
if (!eacf->respawn) {
if (e->respawn_timeout == NGX_CONF_UNSET_MSEC) {
return;
}
if (eacf->respawn_timeout == 0) {
ngx_rtmp_exec_run(s, e->index);
if (e->respawn_timeout == 0) {
ngx_rtmp_exec_run(e);
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: shedule respawn %Mmsec", eacf->respawn_timeout);
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: shedule respawn %Mmsec", e->respawn_timeout);
e->respawn_evt.data = e;
e->respawn_evt.log = s->connection->log;
e->respawn_evt.log = e->log;
e->respawn_evt.handler = ngx_rtmp_exec_respawn;
ngx_add_timer(&e->respawn_evt, eacf->respawn_timeout);
ngx_add_timer(&e->respawn_evt, e->respawn_timeout);
}
static ngx_int_t
ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e, ngx_int_t term)
ngx_rtmp_exec_kill(ngx_rtmp_exec_t *e, ngx_int_t kill_signal)
{
ngx_rtmp_exec_app_conf_t *eacf;
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
if (e->respawn_evt.timer_set) {
ngx_del_timer(&e->respawn_evt);
}
@ -282,23 +394,26 @@ ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e, ngx_int_t term)
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: terminating child %ui",
(ngx_int_t)e->pid);
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: terminating child %ui",
(ngx_int_t) e->pid);
e->active = 0;
close(e->pipefd);
if (e->save_pid) {
*e->save_pid = NGX_INVALID_PID;
}
if (!term) {
if (kill_signal == 0) {
return NGX_OK;
}
if (kill(e->pid, eacf->kill_signal) == -1) {
ngx_log_error(NGX_LOG_INFO, s->connection->log, ngx_errno,
"exec: kill failed pid=%i", (ngx_int_t)e->pid);
if (kill(e->pid, kill_signal) == -1) {
ngx_log_error(NGX_LOG_INFO, e->log, ngx_errno,
"exec: kill failed pid=%i", (ngx_int_t) e->pid);
} else {
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: killed pid=%i", (ngx_int_t)e->pid);
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: killed pid=%i", (ngx_int_t) e->pid);
}
return NGX_OK;
@ -306,34 +421,32 @@ ngx_rtmp_exec_kill(ngx_rtmp_session_t *s, ngx_rtmp_exec_t *e, ngx_int_t term)
static ngx_int_t
ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
ngx_rtmp_exec_run(ngx_rtmp_exec_t *e)
{
#if !(NGX_WIN32)
ngx_rtmp_exec_app_conf_t *eacf;
ngx_rtmp_exec_ctx_t *ctx;
int pid, fd, maxfd;
ngx_pid_t pid;
int fd, maxfd;
int pipefd[2];
int ret;
ngx_rtmp_exec_conf_t *ec;
ngx_rtmp_exec_t *e;
ngx_str_t *arg, a;
char **args;
ngx_uint_t n;
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
ec = (ngx_rtmp_exec_conf_t *)eacf->execs.elts + n;
ec = e->conf;
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
e = ctx->execs + n;
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: starting child '%V'", &ec->cmd);
ngx_memzero(e, sizeof(*e));
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: starting child '%V'",
&ec->cmd);
if (e->active) {
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: already active '%V'", &ec->cmd);
return NGX_OK;
}
if (pipe(pipefd) == -1) {
ngx_log_error(NGX_LOG_INFO, s->connection->log, ngx_errno,
"exec: pipe failed");
ngx_log_error(NGX_LOG_INFO, e->log, ngx_errno,
"exec: pipe failed");
return NGX_ERROR;
}
@ -346,8 +459,8 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
if (ret == -1) {
close(pipefd[0]);
close(pipefd[1]);
ngx_log_error(NGX_LOG_INFO, s->connection->log, ngx_errno,
"exec: fcntl failed");
ngx_log_error(NGX_LOG_INFO, e->log, ngx_errno,
"exec: fcntl failed");
return NGX_ERROR;
}
@ -356,13 +469,17 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
case -1:
close(pipefd[0]);
close(pipefd[1]);
ngx_log_error(NGX_LOG_INFO, s->connection->log, ngx_errno,
"exec: fork failed");
ngx_log_error(NGX_LOG_INFO, e->log, ngx_errno,
"exec: fork failed");
return NGX_ERROR;
case 0:
/* child */
#if (NGX_LINUX)
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
#endif
/* close all descriptors but pipe write end */
maxfd = sysconf(_SC_OPEN_MAX);
for (fd = 0; fd < maxfd; ++fd) {
@ -379,19 +496,22 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
args = ngx_palloc(s->connection->pool,
(ec->args.nelts + 2) * sizeof(char *));
args = ngx_alloc((ec->args.nelts + 2) * sizeof(char *), e->log);
if (args == NULL) {
exit(1);
}
arg = ec->args.elts;
args[0] = (char *)ec->cmd.data;
args[0] = (char *) ec->cmd.data;
for (n = 0; n < ec->args.nelts; ++n, ++arg) {
ngx_rtmp_eval(s, arg, ngx_rtmp_exec_eval_p, &a);
if (e->session == NULL) {
a = *arg;
} else {
ngx_rtmp_eval(e->session, arg, ngx_rtmp_exec_eval_p, &a);
}
args[n + 1] = (char *) a.data;
}
args[n + 1] = NULL;
if (execvp((char *)ec->cmd.data, args) == -1) {
if (execvp((char *) ec->cmd.data, args) == -1) {
exit(1);
}
break;
@ -399,11 +519,12 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
default:
/* parent */
close(pipefd[1]);
e->session = s;
e->index = n;
e->active = 1;
e->pid = pid;
e->pipefd = pipefd[0];
if (e->save_pid) {
*e->save_pid = pid;
}
e->dummy_conn.fd = e->pipefd;
e->dummy_conn.data = e;
@ -412,17 +533,17 @@ ngx_rtmp_exec_run(ngx_rtmp_session_t *s, size_t n)
e->read_evt.data = &e->dummy_conn;
e->write_evt.data = &e->dummy_conn;
e->read_evt.log = s->connection->log;
e->read_evt.log = e->log;
e->read_evt.handler = ngx_rtmp_exec_child_dead;
if (ngx_add_event(&e->read_evt, NGX_READ_EVENT, 0) != NGX_OK) {
ngx_log_error(NGX_LOG_INFO, s->connection->log, ngx_errno,
"exec: failed to add child control event");
ngx_log_error(NGX_LOG_INFO, e->log, ngx_errno,
"exec: failed to add child control event");
}
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: child '%V' started pid=%ui",
&ec->cmd, (ngx_uint_t)pid);
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, e->log, 0,
"exec: child '%V' started pid=%i",
&ec->cmd, (ngx_int_t) pid);
break;
}
#endif /* NGX_WIN32 */
@ -444,16 +565,16 @@ ngx_rtmp_exec_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v)
}
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
if (ctx == NULL || ctx->execs == NULL) {
if (ctx == NULL || ctx->execs.nelts == 0) {
goto next;
}
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: delete %uz command(s)", eacf->execs.nelts);
"exec: delete %uz command(s)", ctx->execs.nelts);
e = ctx->execs;
for (n = 0; n < eacf->execs.nelts; ++n, ++e) {
ngx_rtmp_exec_kill(s, e, 1);
e = ctx->execs.elts;
for (n = 0; n < ctx->execs.nelts; ++n, ++e) {
ngx_rtmp_exec_kill(e, eacf->kill_signal);
}
next:
@ -464,13 +585,16 @@ next:
static ngx_int_t
ngx_rtmp_exec_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
{
ngx_rtmp_exec_main_conf_t *emcf;
ngx_rtmp_exec_app_conf_t *eacf;
ngx_rtmp_exec_t *e;
ngx_rtmp_exec_conf_t *ec;
ngx_rtmp_exec_ctx_t *ctx;
size_t n;
emcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_exec_module);
eacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_exec_module);
if (eacf == NULL || eacf->execs.nelts == 0) {
if (eacf == NULL || eacf->confs.nelts == 0) {
goto next;
}
@ -479,23 +603,45 @@ ngx_rtmp_exec_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
}
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_exec_module);
if (ctx == NULL) {
ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_rtmp_exec_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
}
ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_exec_module);
ctx->execs = ngx_pcalloc(s->connection->pool, eacf->execs.nelts
* sizeof(ngx_rtmp_exec_t));
if (ngx_array_init(&ctx->execs, s->connection->pool, eacf->confs.nelts,
sizeof(ngx_rtmp_exec_t)) != NGX_OK)
{
return NGX_ERROR;
}
e = ngx_array_push_n(&ctx->execs, eacf->confs.nelts);
if (e == NULL) {
return NGX_ERROR;
}
ec = eacf->confs.elts;
for (n = 0; n < eacf->confs.nelts; ++n, ++e, ++ec) {
ngx_memzero(e, sizeof(*e));
e->conf = ec;
e->log = s->connection->log;
e->session = s;
e->respawn_timeout = (eacf->respawn ? emcf->respawn_timeout :
NGX_CONF_UNSET_MSEC);
}
}
ngx_memcpy(ctx->name, v->name, NGX_RTMP_MAX_NAME);
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"exec: run %uz command(s)", eacf->execs.nelts);
"exec: run %uz command(s)", ctx->execs.nelts);
ec = eacf->execs.elts;
for (n = 0; n < eacf->execs.nelts; ++n, ++ec) {
ngx_rtmp_exec_run(s, n);
e = ctx->execs.elts;
for (n = 0; n < ctx->execs.nelts; ++n, ++e) {
ngx_rtmp_exec_run(e);
}
next:
@ -515,7 +661,7 @@ ngx_rtmp_exec_exec(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
eacf = ngx_rtmp_conf_get_module_app_conf(cf, ngx_rtmp_exec_module);
value = cf->args->elts;
ec = ngx_array_push(&eacf->execs);
ec = ngx_array_push(&eacf->confs);
if (ec == NULL) {
return NGX_CONF_ERROR;
}
@ -528,7 +674,46 @@ ngx_rtmp_exec_exec(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
nargs = cf->args->nelts - 2;
if (ngx_array_init(&ec->args, cf->pool, nargs,
sizeof(ngx_str_t)) != NGX_OK)
sizeof(ngx_str_t)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
s = ngx_array_push_n(&ec->args, nargs);
for (n = 2; n < cf->args->nelts; ++n, ++s) {
*s = value[n];
}
return NGX_CONF_OK;
}
static char *
ngx_rtmp_exec_exec_static(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_rtmp_exec_main_conf_t *emcf = conf;
ngx_str_t *value;
size_t n, nargs;
ngx_str_t *s;
ngx_rtmp_exec_conf_t *ec;
value = cf->args->elts;
ec = ngx_array_push(&emcf->confs);
if (ec == NULL) {
return NGX_CONF_ERROR;
}
ec->cmd = value[1];
if (cf->args->nelts == 2) {
return NGX_CONF_OK;
}
nargs = cf->args->nelts - 2;
if (ngx_array_init(&ec->args, cf->pool, nargs,
sizeof(ngx_str_t)) != NGX_OK)
{
return NGX_CONF_ERROR;
}

View file

@ -1592,7 +1592,7 @@ ngx_rtmp_relay_init_process(ngx_cycle_t *cycle)
rs->cctx = *lst->ctx;
rs->cctx.app_conf = cacf->app_conf;
ngx_post_event(event, &ngx_posted_events);
ngx_post_event(event, &ngx_rtmp_init_process_events);
}
}
}

View file

@ -15,6 +15,7 @@ static ngx_int_t ngx_rtmp_stat_postconfiguration(ngx_conf_t *cf);
static void * ngx_rtmp_stat_create_loc_conf(ngx_conf_t *cf);
static char * ngx_rtmp_stat_merge_loc_conf(ngx_conf_t *cf,
void *parent, void *child);
static ngx_int_t ngx_rtmp_stat_init_process(ngx_cycle_t *cycle);
static time_t start_time;
@ -87,7 +88,7 @@ ngx_module_t ngx_rtmp_stat_module = {
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
ngx_rtmp_stat_init_process, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
@ -96,6 +97,20 @@ ngx_module_t ngx_rtmp_stat_module = {
};
static ngx_int_t
ngx_rtmp_stat_init_process(ngx_cycle_t *cycle)
{
/* Run posted events;
* HTTP module's init_process is called after event module's
* init_process. That makes is possible to use event-related
* calls. RTMP modules are core modules with early
* initializers */
ngx_event_process_posted(cycle, &ngx_rtmp_init_process_events);
return NGX_OK;
}
#define NGX_RTMP_STAT_BUFSIZE 256