From: Matthew Weber <matthew.weber@collins.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] package/nginx: fix NGINX pidfile handling systemd
Date: Fri, 21 May 2021 09:41:49 -0500 [thread overview]
Message-ID: <20210521144149.35725-1-matthew.weber@collins.com> (raw)
Based on https://git.launchpad.net/ubuntu/+source/nginx/plain/debian/patches/nginx-fix-pidfile.patch
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=876365
Upstream bug: (deferred fix)
https://trac.nginx.org/nginx/ticket/1897?cversion=0&cnum_hist=2
Signed-off-by: Matthew Weber <matthew.weber@collins.com>
---
.../0010-Fix-NGINX-pidfile-handling.patch | 105 ++++++++++++++++++
1 file changed, 105 insertions(+)
create mode 100644 package/nginx/0010-Fix-NGINX-pidfile-handling.patch
diff --git a/package/nginx/0010-Fix-NGINX-pidfile-handling.patch b/package/nginx/0010-Fix-NGINX-pidfile-handling.patch
new file mode 100644
index 0000000000..9a50118434
--- /dev/null
+++ b/package/nginx/0010-Fix-NGINX-pidfile-handling.patch
@@ -0,0 +1,105 @@
+From 2491379370059c7b9a2b956a49c90a9de55f5dcb Mon Sep 17 00:00:00 2001
+From: Tj <ubuntu@iam.tj>
+Date: Fri, 21 May 2021 09:35:53 -0500
+Subject: [PATCH] Fix NGINX pidfile handling
+
+Based on https://git.launchpad.net/ubuntu/+source/nginx/plain/debian/patches/nginx-fix-pidfile.patch
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=876365
+Last-Update: 2020-06-24
+
+Upstream bug: (deferred fix)
+https://trac.nginx.org/nginx/ticket/1897?cversion=0&cnum_hist=2
+
+Signed-off-by: Tj <ubuntu@iam.tj>
+Signed-off-by: Matthew Weber <matthew.weber@collins.com>
+---
+ src/core/nginx.c | 24 +++++++++++++++++++++---
+ src/os/unix/ngx_daemon.c | 8 ++++++--
+ 2 files changed, 27 insertions(+), 5 deletions(-)
+
+diff --git a/src/core/nginx.c b/src/core/nginx.c
+index 9fcb0eb..083eba1 100644
+--- a/src/core/nginx.c
++++ b/src/core/nginx.c
+@@ -338,14 +338,21 @@ main(int argc, char *const *argv)
+ ngx_process = NGX_PROCESS_MASTER;
+ }
+
++ /* tell-tale to detect if this is parent or child process */
++ ngx_int_t child_pid = NGX_BUSY;
++
+ #if !(NGX_WIN32)
+
+ if (ngx_init_signals(cycle->log) != NGX_OK) {
+ return 1;
+ }
+
++ /* tell-tale that this code has been executed */
++ child_pid--;
++
+ if (!ngx_inherited && ccf->daemon) {
+- if (ngx_daemon(cycle->log) != NGX_OK) {
++ child_pid = ngx_daemon(cycle->log);
++ if (child_pid == NGX_ERROR) {
+ return 1;
+ }
+
+@@ -358,8 +365,19 @@ main(int argc, char *const *argv)
+
+ #endif
+
+- if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
+- return 1;
++ /* If ngx_daemon() returned the child's PID in the parent process
++ * after the fork() set ngx_pid to the child_pid, which gets
++ * written to the PID file, then exit.
++ * For NGX_WIN32 always write the PID file
++ * For others, only write it from the parent process */
++ if (child_pid < NGX_OK || child_pid > NGX_OK) {
++ ngx_pid = child_pid > NGX_OK ? child_pid : ngx_pid;
++ if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) {
++ return 1;
++ }
++ }
++ if (child_pid > NGX_OK) {
++ exit(0);
+ }
+
+ if (ngx_log_redirect_stderr(cycle) != NGX_OK) {
+diff --git a/src/os/unix/ngx_daemon.c b/src/os/unix/ngx_daemon.c
+index 385c49b..3719854 100644
+--- a/src/os/unix/ngx_daemon.c
++++ b/src/os/unix/ngx_daemon.c
+@@ -7,14 +7,17 @@
+
+ #include <ngx_config.h>
+ #include <ngx_core.h>
++#include <unistd.h>
+
+
+ ngx_int_t
+ ngx_daemon(ngx_log_t *log)
+ {
+ int fd;
++ /* retain the return value for passing back to caller */
++ pid_t pid_child = fork();
+
+- switch (fork()) {
++ switch (pid_child) {
+ case -1:
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed");
+ return NGX_ERROR;
+@@ -23,7 +26,8 @@ ngx_daemon(ngx_log_t *log)
+ break;
+
+ default:
+- exit(0);
++ /* let caller do the exit() */
++ return pid_child;
+ }
+
+ ngx_parent = ngx_pid;
+--
+2.17.1
+
--
2.17.1
next reply other threads:[~2021-05-21 14:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-21 14:41 Matthew Weber [this message]
2021-05-26 20:48 ` [Buildroot] [PATCH] package/nginx: fix NGINX pidfile handling systemd Yann E. MORIN
2021-05-27 20:49 ` Arnout Vandecappelle
2021-05-28 11:39 ` Yann E. MORIN
2021-05-28 11:51 ` Arnout Vandecappelle
2021-05-28 13:12 ` Yann E. MORIN
2021-05-28 13:24 ` Arnout Vandecappelle
2021-05-28 15:48 ` Peter Korsgaard
2021-05-28 16:10 ` Arnout Vandecappelle
2021-05-28 16:42 ` Peter Korsgaard
2021-05-28 15:46 ` Peter Korsgaard
2021-05-28 16:05 ` Arnout Vandecappelle
2021-05-28 19:41 ` Yann E. MORIN
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210521144149.35725-1-matthew.weber@collins.com \
--to=matthew.weber@collins.com \
--cc=buildroot@busybox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.