[nginx] Core: close PID file when writing fails.

Ruslan Ermilov ru at nginx.com
Tue Jul 21 17:36:47 UTC 2020


details:   https://hg.nginx.org/nginx/rev/4f30f75dbdf3
branches:  
changeset: 7685:4f30f75dbdf3
user:      Ruslan Ermilov <ru at nginx.com>
date:      Tue Jul 21 20:34:29 2020 +0300
description:
Core: close PID file when writing fails.

Reported by Jinhua Tan.

diffstat:

 src/core/ngx_cycle.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (35 lines):

diff -r 32a343635b50 -r 4f30f75dbdf3 src/core/ngx_cycle.c
--- a/src/core/ngx_cycle.c	Thu Jul 09 16:21:37 2020 +0300
+++ b/src/core/ngx_cycle.c	Tue Jul 21 20:34:29 2020 +0300
@@ -1009,6 +1009,7 @@ ngx_int_t
 ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log)
 {
     size_t      len;
+    ngx_int_t   rc;
     ngx_uint_t  create;
     ngx_file_t  file;
     u_char      pid[NGX_INT64_LEN + 2];
@@ -1033,11 +1034,13 @@ ngx_create_pidfile(ngx_str_t *name, ngx_
         return NGX_ERROR;
     }
 
+    rc = NGX_OK;
+
     if (!ngx_test_config) {
         len = ngx_snprintf(pid, NGX_INT64_LEN + 2, "%P%N", ngx_pid) - pid;
 
         if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
-            return NGX_ERROR;
+            rc = NGX_ERROR;
         }
     }
 
@@ -1046,7 +1049,7 @@ ngx_create_pidfile(ngx_str_t *name, ngx_
                       ngx_close_file_n " \"%s\" failed", file.name.data);
     }
 
-    return NGX_OK;
+    return rc;
 }
 
 


More information about the nginx-devel mailing list