commit:     c4f4d3abf675460b53e5ebb9a0550a4c9a539771
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 19 23:30:32 2019 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Mon Aug 19 23:30:56 2019 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c4f4d3ab

net-analyzer/nagios-core: new revision fixing zombie process bug.

Bug: https://bugs.gentoo.org/692092
Reported-by: Tomáš Mózes <hydrapolic <AT> gmail.com>
Package-Manager: Portage-2.3.69, Repoman-2.3.16
Signed-off-by: Michael Orlitzky <mjo <AT> gentoo.org>

 .../nagios-core-4.4.4-no-zombie-processes.patch    | 158 +++++++++++++++++++++
 ...re-4.4.4.ebuild => nagios-core-4.4.4-r1.ebuild} |   2 +
 2 files changed, 160 insertions(+)

diff --git 
a/net-analyzer/nagios-core/files/nagios-core-4.4.4-no-zombie-processes.patch 
b/net-analyzer/nagios-core/files/nagios-core-4.4.4-no-zombie-processes.patch
new file mode 100644
index 00000000000..4592b1d27f4
--- /dev/null
+++ b/net-analyzer/nagios-core/files/nagios-core-4.4.4-no-zombie-processes.patch
@@ -0,0 +1,158 @@
+This was an upstream bug that has been reverted for nagios-core-4.4.5:
+
+  https://github.com/NagiosEnterprises/nagioscore/issues/683
+
+Thanks to Tomáš Mózes (hydrapolic) for noticing and reporting the fix.
+
+diff --git a/base/events.c b/base/events.c
+index d601e970f..bb27b3240 100644
+--- a/base/events.c
++++ b/base/events.c
+@@ -351,13 +351,12 @@ void init_timing_loop(void) {
+                        */
+                       check_delay =
+                                       mult_factor * 
scheduling_info.service_inter_check_delay;
+-                      time_t check_window = 
reschedule_within_timeperiod(next_valid_time, temp_service->check_period_ptr, 
check_window(temp_service)) - current_time;
+-                      if(check_delay > check_window) {
++                      if(check_delay > check_window(temp_service)) {
+                               log_debug_info(DEBUGL_EVENTS, 0,
+                                               "  Fixing check time %lu secs 
too far away\n",
+-                                              check_delay - check_window);
++                                              check_delay - 
check_window(temp_service));
+                               fixed_services++;
+-                              check_delay = check_window;
++                              check_delay = check_window(temp_service);
+                               log_debug_info(DEBUGL_EVENTS, 0, "  New check 
offset: %d\n",
+                                               check_delay);
+                       }
+@@ -370,7 +369,8 @@ void init_timing_loop(void) {
+                       if(is_valid_time == ERROR) {
+                               log_debug_info(DEBUGL_EVENTS, 2, "Preferred 
Time is Invalid In Timeperiod '%s': %lu --> %s\n", 
temp_service->check_period_ptr->name, (unsigned long)temp_service->next_check, 
ctime(&temp_service->next_check));
+                               get_next_valid_time(temp_service->next_check, 
&next_valid_time, temp_service->check_period_ptr);
+-                              temp_service->next_check = 
reschedule_within_timeperiod(next_valid_time, temp_service->check_period_ptr, 
check_window(temp_service));
++                              temp_service->next_check = 
++                                      (time_t)(next_valid_time + check_delay);
+                               }
+ 
+                       log_debug_info(DEBUGL_EVENTS, 2, "Actual Check Time: 
%lu --> %s\n", (unsigned long)temp_service->next_check, 
ctime(&temp_service->next_check));
+@@ -508,7 +508,7 @@ void init_timing_loop(void) {
+                       log_debug_info(DEBUGL_EVENTS, 1, "Fixing check time 
(off by %lu)\n",
+                                       check_delay - check_window(temp_host));
+                       fixed_hosts++;
+-                      check_delay = 
reschedule_within_timeperiod(next_valid_time, temp_host->check_period_ptr, 
check_window(temp_host));
++                      check_delay = ranged_urand(0, check_window(temp_host));
+                       }
+               temp_host->next_check = (time_t)(current_time + check_delay);
+ 
+diff --git a/cgi/status.c b/cgi/status.c
+index ae723c683..2f6a60fde 100644
+--- a/cgi/status.c
++++ b/cgi/status.c
+@@ -221,8 +221,26 @@ int main(void) {
+       document_header(TRUE);
+ 
+       /* if a navbar search was performed, find the host by name, address or 
partial name */
+-      if(navbar_search == TRUE) {
+-              if(host_name != NULL && NULL != strstr(host_name, "*")) {
++      if(navbar_search == TRUE && host_name != NULL) {
++
++              /* Remove trailing spaces from host_name */
++              len = strlen(host_name);
++              for (i = len - 1; i >= 0; i--) {
++                      if (!isspace(host_name[i])) {
++                              host_name[i+1] = '\0';
++                              break;
++                      }
++              }
++
++              /* Remove leading spaces from host_name */
++              for (i = 0; i < len; i++) {
++                      if (!isspace(host_name[i])) {
++                              break;
++                      }
++              }
++              strcpy(host_name, host_name + i);
++
++              if(NULL != strstr(host_name, "*")) {
+                       /* allocate for 3 extra chars, ^, $ and \0 */
+                       host_filter = malloc(sizeof(char) * (strlen(host_name) 
* 2 + 3));
+                       len = strlen(host_name);
+@@ -238,7 +256,7 @@ int main(void) {
+                       host_filter[regex_i++] = '$';
+                       host_filter[regex_i] = '\0';
+                       }
+-              else if (host_name != NULL) {
++              else {
+                       if((temp_host = find_host(host_name)) == NULL) {
+                               for(temp_host = host_list; temp_host != NULL; 
temp_host = temp_host->next) {
+                                       if(is_authorized_for_host(temp_host, 
&current_authdata) == FALSE)
+diff --git a/lib/worker.c b/lib/worker.c
+index 4f7cbc384..a94719cc4 100644
+--- a/lib/worker.c
++++ b/lib/worker.c
+@@ -215,7 +215,7 @@ int worker_buf2kvvec_prealloc(struct kvvec *kvv, char 
*buf, unsigned long len, i
+       } while (0)
+ 
+ /* forward declaration */
+-static int gather_output(child_process *cp, iobuf *io, int final);
++static void gather_output(child_process *cp, iobuf *io, int final);
+ 
+ static void destroy_job(child_process *cp)
+ {
+@@ -258,23 +258,15 @@ static void destroy_job(child_process *cp)
+ int finish_job(child_process *cp, int reason)
+ {
+       static struct kvvec resp = KVVEC_INITIALIZER;
+-      int i, ret, rd;
++      int i, ret;
+ 
+       /* get rid of still open filedescriptors */
+       if (cp->outstd.fd != -1) {
+-
+-              rd = 1;
+-              while(rd > 0) {
+-                      rd = gather_output(cp, &cp->outstd, 0);
+-              }
++              gather_output(cp, &cp->outstd, 1);
+               iobroker_close(iobs, cp->outstd.fd);
+       }
+       if (cp->outerr.fd != -1) {
+-
+-              rd = 1;
+-              while(rd > 0) {
+-                      rd = gather_output(cp, &cp->outerr, 0);
+-              }
++              gather_output(cp, &cp->outerr, 1);
+               iobroker_close(iobs, cp->outerr.fd);
+       }
+ 
+@@ -450,13 +442,13 @@ static void kill_job(child_process *cp, int reason)
+       destroy_job(cp);
+ }
+ 
+-static int gather_output(child_process *cp, iobuf *io, int final)
++static void gather_output(child_process *cp, iobuf *io, int final)
+ {
+       int retry = 5;
+-      int rd;
+ 
+       for (;;) {
+               char buf[4096];
++              int rd;
+ 
+               rd = read(io->fd, buf, sizeof(buf));
+               if (rd < 0) {
+@@ -492,13 +484,13 @@ static int gather_output(child_process *cp, iobuf *io, 
int final)
+               if (rd <= 0 || final) {
+                       iobroker_close(iobs, io->fd);
+                       io->fd = -1;
++                      if (!final)
++                              check_completion(cp, WNOHANG);
+                       break;
+               }
+ 
+               break;
+       }
+-
+-      return rd;
+ }

diff --git a/net-analyzer/nagios-core/nagios-core-4.4.4.ebuild 
b/net-analyzer/nagios-core/nagios-core-4.4.4-r1.ebuild
similarity index 99%
rename from net-analyzer/nagios-core/nagios-core-4.4.4.ebuild
rename to net-analyzer/nagios-core/nagios-core-4.4.4-r1.ebuild
index 74ddb853c43..520b2503a8c 100644
--- a/net-analyzer/nagios-core/nagios-core-4.4.4.ebuild
+++ b/net-analyzer/nagios-core/nagios-core-4.4.4-r1.ebuild
@@ -70,6 +70,8 @@ RDEPEND="${DEPEND}
 
 S="${WORKDIR}/${MY_P}"
 
+PATCHES=( "${FILESDIR}/${P}-no-zombie-processes.patch" )
+
 pkg_setup() {
        enewgroup nagios
        enewuser nagios -1 /bin/bash /var/nagios/home nagios

Reply via email to