Mercurial > hg > nginx
comparison src/core/ngx_cycle.c @ 9269:4eb02e5ddb48
Core: added realpath() checking when testing PID files.
This ensures that if the PID file path is changed, yet resolves to the
same file via symbolic links, trying to recreate the PID file won't
remove it. In particular, this resolves issues as observed on Linux
systems with "/var/run/nginx.pid" changed to "/run/nginx.pid".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 13 May 2024 06:13:12 +0300 |
parents | 6a3ee145d0b5 |
children |
comparison
equal
deleted
inserted
replaced
9268:6a3ee145d0b5 | 9269:4eb02e5ddb48 |
---|---|
11 | 11 |
12 | 12 |
13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); | 13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); |
14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, | 14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, |
15 ngx_shm_zone_t *shm_zone); | 15 ngx_shm_zone_t *shm_zone); |
16 static ngx_int_t ngx_pidfile_changed(ngx_str_t *name1, ngx_str_t *name2, | |
17 ngx_log_t *log); | |
16 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); | 18 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); |
17 static void ngx_clean_old_cycles(ngx_event_t *ev); | 19 static void ngx_clean_old_cycles(ngx_event_t *ev); |
18 static void ngx_shutdown_timer_handler(ngx_event_t *ev); | 20 static void ngx_shutdown_timer_handler(ngx_event_t *ev); |
19 | 21 |
20 | 22 |
330 * because we need to write the demonized process pid | 332 * because we need to write the demonized process pid |
331 */ | 333 */ |
332 | 334 |
333 old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx, | 335 old_ccf = (ngx_core_conf_t *) ngx_get_conf(old_cycle->conf_ctx, |
334 ngx_core_module); | 336 ngx_core_module); |
335 if (ccf->pid.len != old_ccf->pid.len | 337 |
336 || ngx_strcmp(ccf->pid.data, old_ccf->pid.data) != 0) | 338 if (ngx_pidfile_changed(&ccf->pid, &old_ccf->pid, log)) { |
337 { | 339 |
338 /* new pid file name */ | 340 /* new pid file name */ |
339 | 341 |
340 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) { | 342 if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) { |
341 goto failed; | 343 goto failed; |
342 } | 344 } |
1085 ngx_delete_file_n " \"%s\" failed", name); | 1087 ngx_delete_file_n " \"%s\" failed", name); |
1086 } | 1088 } |
1087 } | 1089 } |
1088 | 1090 |
1089 | 1091 |
1092 static ngx_int_t | |
1093 ngx_pidfile_changed(ngx_str_t *name1, ngx_str_t *name2, ngx_log_t *log) | |
1094 { | |
1095 u_char *real1, *real2; | |
1096 ngx_int_t rc; | |
1097 | |
1098 if (name1->len == name2->len | |
1099 && ngx_strcmp(name1->data, name2->data) == 0) | |
1100 { | |
1101 return 0; | |
1102 } | |
1103 | |
1104 rc = 1; | |
1105 real1 = NULL; | |
1106 real2 = NULL; | |
1107 | |
1108 real1 = ngx_realpath(name1->data, NULL); | |
1109 | |
1110 if (real1 == NULL) { | |
1111 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, ngx_errno, | |
1112 ngx_realpath_n " \"%s\" failed", name1->data); | |
1113 goto done; | |
1114 } | |
1115 | |
1116 real2 = ngx_realpath(name2->data, NULL); | |
1117 | |
1118 if (real2 == NULL) { | |
1119 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, ngx_errno, | |
1120 ngx_realpath_n " \"%s\" failed", name2->data); | |
1121 goto done; | |
1122 } | |
1123 | |
1124 rc = ngx_strcmp(real1, real2); | |
1125 | |
1126 done: | |
1127 | |
1128 if (real1 && real1 != name1->data) { | |
1129 ngx_free(real1); | |
1130 } | |
1131 | |
1132 if (real2 && real2 != name2->data) { | |
1133 ngx_free(real2); | |
1134 } | |
1135 | |
1136 return rc; | |
1137 } | |
1138 | |
1139 | |
1090 ngx_int_t | 1140 ngx_int_t |
1091 ngx_signal_process(ngx_cycle_t *cycle, char *sig) | 1141 ngx_signal_process(ngx_cycle_t *cycle, char *sig) |
1092 { | 1142 { |
1093 ssize_t n; | 1143 ssize_t n; |
1094 ngx_pid_t pid; | 1144 ngx_pid_t pid; |