Skip to content

Commit c99270f

Browse files
author
vacingFang
committed
[fix]fix auto push unix socket bug
unix socket name will conflict when gracefully update, because nginx master will recount the index of process
1 parent 3274d53 commit c99270f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ngx_rtmp_auto_push_module.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
141141
ngx_socket_t s;
142142
size_t n;
143143
ngx_file_info_t fi;
144+
ngx_pid_t pid;
144145

145146
if (ngx_process != NGX_PROCESS_WORKER) {
146147
return NGX_OK;
@@ -197,9 +198,10 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
197198
return NGX_ERROR;
198199
}
199200
saun->sun_family = AF_UNIX;
201+
pid = ngx_getpid();
200202
*ngx_snprintf((u_char *) saun->sun_path, sizeof(saun->sun_path),
201203
"%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i",
202-
&apcf->socket_dir, ngx_process_slot)
204+
&apcf->socket_dir, pid)
203205
= 0;
204206

205207
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, cycle->log, 0,
@@ -352,6 +354,7 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle)
352354
ngx_listening_t *ls;
353355
ngx_connection_t *c;
354356
size_t n;
357+
ngx_pid_t pid;
355358

356359
apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(cycle->conf_ctx,
357360
ngx_rtmp_auto_push_module);
@@ -398,9 +401,10 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle)
398401
}
399402
}
400403

404+
pid = ngx_getpid();
401405
*ngx_snprintf(path, sizeof(path),
402406
"%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i",
403-
&apcf->socket_dir, ngx_process_slot)
407+
&apcf->socket_dir, pid)
404408
= 0;
405409

406410
ngx_delete_file(path);
@@ -513,7 +517,7 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev)
513517
u = &at.url.url;
514518
p = ngx_snprintf(path, sizeof(path) - 1,
515519
"unix:%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i",
516-
&apcf->socket_dir, n);
520+
&apcf->socket_dir, pid);
517521
*p = 0;
518522

519523
if (ngx_file_info(path + sizeof("unix:") - 1, &fi) != NGX_OK) {

0 commit comments

Comments
 (0)