diff src/core/ngx_cycle.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 f18db38a9826
children 4eb02e5ddb48
line wrap: on
line diff
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -1027,6 +1027,10 @@ ngx_create_pidfile(ngx_str_t *name, ngx_
         return NGX_OK;
     }
 
+    if (name->len == 0) {
+        return NGX_OK;
+    }
+
     ngx_memzero(&file, sizeof(ngx_file_t));
 
     file.name = *name;
@@ -1070,6 +1074,10 @@ ngx_delete_pidfile(ngx_cycle_t *cycle)
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
 
+    if (ccf->pid.len == 0) {
+        return;
+    }
+
     name = ngx_new_binary ? ccf->oldpid.data : ccf->pid.data;
 
     if (ngx_delete_file(name) == NGX_FILE_ERROR) {
@@ -1092,6 +1100,12 @@ ngx_signal_process(ngx_cycle_t *cycle, c
 
     ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
 
+    if (ccf->pid.len == 0) {
+        ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
+                      "no PID file configured");
+        return 1;
+    }
+
     ngx_memzero(&file, sizeof(ngx_file_t));
 
     file.name = ccf->pid;