net-analyzer/nagios-core: new revision fixing zombie process bug.
authorMichael Orlitzky <mjo@gentoo.org>
Mon, 19 Aug 2019 23:30:32 +0000 (19:30 -0400)
committerMichael Orlitzky <mjo@gentoo.org>
Mon, 19 Aug 2019 23:30:56 +0000 (19:30 -0400)
Bug: https://bugs.gentoo.org/692092
Reported-by: Tomáš Mózes <hydrapolic@gmail.com>
Package-Manager: Portage-2.3.69, Repoman-2.3.16
Signed-off-by: Michael Orlitzky <mjo@gentoo.org>
net-analyzer/nagios-core/files/nagios-core-4.4.4-no-zombie-processes.patch [new file with mode: 0644]
net-analyzer/nagios-core/nagios-core-4.4.4-r1.ebuild [moved from net-analyzer/nagios-core/nagios-core-4.4.4.ebuild with 99% similarity]

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 (file)
index 0000000..4592b1d
--- /dev/null
@@ -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;
+ }
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 74ddb853c43eb791bf0e70e4fd495bdace5cf058..520b2503a8c53028b8a0b9a3d1ec80b4381955c9 100644 (file)
@@ -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