Skip to content

Commit

Permalink
[fix]fix auto push unix socket bug
Browse files Browse the repository at this point in the history
unix socket name will conflict when gracefully update, because nginx master will recount the index
of process
  • Loading branch information
vacingFang committed Jan 7, 2024
1 parent 3274d53 commit c99270f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ngx_rtmp_auto_push_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c99270f

Please sign in to comment.