From c99270fee1844f922c3472f45252ad1f792e80dd Mon Sep 17 00:00:00 2001 From: vacingFang Date: Sun, 7 Jan 2024 18:45:37 +0800 Subject: [PATCH 1/2] [fix]fix auto push unix socket bug unix socket name will conflict when gracefully update, because nginx master will recount the index of process --- ngx_rtmp_auto_push_module.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ngx_rtmp_auto_push_module.c b/ngx_rtmp_auto_push_module.c index a126575..b1f608f 100644 --- a/ngx_rtmp_auto_push_module.c +++ b/ngx_rtmp_auto_push_module.c @@ -141,6 +141,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle) ngx_socket_t s; size_t n; ngx_file_info_t fi; + ngx_pid_t pid; if (ngx_process != NGX_PROCESS_WORKER) { return NGX_OK; @@ -197,9 +198,10 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle) return NGX_ERROR; } saun->sun_family = AF_UNIX; + pid = ngx_getpid(); *ngx_snprintf((u_char *) saun->sun_path, sizeof(saun->sun_path), "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", - &apcf->socket_dir, ngx_process_slot) + &apcf->socket_dir, pid) = 0; ngx_log_debug1(NGX_LOG_DEBUG_RTMP, cycle->log, 0, @@ -352,6 +354,7 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle) ngx_listening_t *ls; ngx_connection_t *c; size_t n; + ngx_pid_t pid; apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_rtmp_auto_push_module); @@ -398,9 +401,10 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle) } } + pid = ngx_getpid(); *ngx_snprintf(path, sizeof(path), "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", - &apcf->socket_dir, ngx_process_slot) + &apcf->socket_dir, pid) = 0; ngx_delete_file(path); @@ -513,7 +517,7 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev) u = &at.url.url; p = ngx_snprintf(path, sizeof(path) - 1, "unix:%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", - &apcf->socket_dir, n); + &apcf->socket_dir, pid); *p = 0; if (ngx_file_info(path + sizeof("unix:") - 1, &fi) != NGX_OK) { From 6a871e30dee4280f0dd53c39a96641dd8e57babd Mon Sep 17 00:00:00 2001 From: winshining Date: Sun, 7 Jan 2024 19:30:36 +0800 Subject: [PATCH 2/2] [fix] fixed some format strings. --- ngx_rtmp_auto_push_module.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ngx_rtmp_auto_push_module.c b/ngx_rtmp_auto_push_module.c index b1f608f..6a381bc 100644 --- a/ngx_rtmp_auto_push_module.c +++ b/ngx_rtmp_auto_push_module.c @@ -200,7 +200,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle) saun->sun_family = AF_UNIX; pid = ngx_getpid(); *ngx_snprintf((u_char *) saun->sun_path, sizeof(saun->sun_path), - "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", + "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%P", &apcf->socket_dir, pid) = 0; @@ -403,7 +403,7 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle) pid = ngx_getpid(); *ngx_snprintf(path, sizeof(path), - "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", + "%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%P", &apcf->socket_dir, pid) = 0; @@ -516,7 +516,7 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev) ngx_memzero(&at.url, sizeof(at.url)); u = &at.url.url; p = ngx_snprintf(path, sizeof(path) - 1, - "unix:%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i", + "unix:%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%P", &apcf->socket_dir, pid); *p = 0;