Mercurial > hg > nginx
comparison src/core/nginx.c @ 9268:6a3ee145d0b5
Core: made it possible to disable PID files with "pid off".
While it is not generally recommended, this might be beneficial in some
configurations, such as with immutable images and direct control by
a service manager.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 13 May 2024 06:13:03 +0300 |
parents | c209dc4eed17 |
children | 3d455e37abf8 |
comparison
equal
deleted
inserted
replaced
9267:9a5e2296c1be | 9268:6a3ee145d0b5 |
---|---|
764 | 764 |
765 ctx.envp = (char *const *) env; | 765 ctx.envp = (char *const *) env; |
766 | 766 |
767 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 767 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
768 | 768 |
769 if (ngx_rename_file(ccf->pid.data, ccf->oldpid.data) == NGX_FILE_ERROR) { | 769 if (ccf->pid.len |
770 && ngx_rename_file(ccf->pid.data, ccf->oldpid.data) == NGX_FILE_ERROR) | |
771 { | |
770 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 772 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
771 ngx_rename_file_n " %s to %s failed " | 773 ngx_rename_file_n " %s to %s failed " |
772 "before executing new binary process \"%s\"", | 774 "before executing new binary process \"%s\"", |
773 ccf->pid.data, ccf->oldpid.data, argv[0]); | 775 ccf->pid.data, ccf->oldpid.data, argv[0]); |
774 | 776 |
779 } | 781 } |
780 | 782 |
781 pid = ngx_execute(cycle, &ctx); | 783 pid = ngx_execute(cycle, &ctx); |
782 | 784 |
783 if (pid == NGX_INVALID_PID) { | 785 if (pid == NGX_INVALID_PID) { |
784 if (ngx_rename_file(ccf->oldpid.data, ccf->pid.data) | 786 if (ccf->pid.len |
785 == NGX_FILE_ERROR) | 787 && ngx_rename_file(ccf->oldpid.data, ccf->pid.data) |
788 == NGX_FILE_ERROR) | |
786 { | 789 { |
787 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 790 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
788 ngx_rename_file_n " %s back to %s failed after " | 791 ngx_rename_file_n " %s back to %s failed after " |
789 "an attempt to execute new binary process \"%s\"", | 792 "an attempt to execute new binary process \"%s\"", |
790 ccf->oldpid.data, ccf->pid.data, argv[0]); | 793 ccf->oldpid.data, ccf->pid.data, argv[0]); |
1166 | 1169 |
1167 if (ccf->pid.len == 0) { | 1170 if (ccf->pid.len == 0) { |
1168 ngx_str_set(&ccf->pid, NGX_PID_PATH); | 1171 ngx_str_set(&ccf->pid, NGX_PID_PATH); |
1169 } | 1172 } |
1170 | 1173 |
1171 if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { | 1174 if (ngx_strcmp(ccf->pid.data, "off") == 0) { |
1172 return NGX_CONF_ERROR; | 1175 ngx_str_set(&ccf->pid, ""); |
1173 } | 1176 ngx_str_set(&ccf->oldpid, ""); |
1174 | 1177 |
1175 ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); | 1178 } else { |
1176 | 1179 if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { |
1177 ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); | 1180 return NGX_CONF_ERROR; |
1178 if (ccf->oldpid.data == NULL) { | 1181 } |
1179 return NGX_CONF_ERROR; | 1182 |
1180 } | 1183 ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); |
1181 | 1184 |
1182 ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), | 1185 ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); |
1183 NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); | 1186 if (ccf->oldpid.data == NULL) { |
1187 return NGX_CONF_ERROR; | |
1188 } | |
1189 | |
1190 ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), | |
1191 NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); | |
1192 } | |
1184 | 1193 |
1185 | 1194 |
1186 #if !(NGX_WIN32) | 1195 #if !(NGX_WIN32) |
1187 | 1196 |
1188 if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { | 1197 if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { |