Procházet zdrojové kódy

when using ssh (or check-by-ssh) with ControlMaster/ControlPersist, nagios
times out the first time and one gets zombie processes

Fix for issue http://tracker.nagios.org/view.php?id=321

Patch from Gordon Messmer applied.

John C. Frickson před 9 roky
rodič
revize
e2ea947263
2 změnil soubory, kde provedl 9 přidání a 2 odebrání
  1. 2 0
      NEWS
  2. 7 2
      lib/utils_cmd.c

+ 2 - 0
NEWS

@@ -20,6 +20,8 @@ This file documents the major additions and syntax changes between releases.
 	sslutils.c: output has first line of "SSL Version: xxxxxx"
 	sslutils.c: output has first line of "SSL Version: xxxxxx"
 	  effects anything using sslutils including check_http, check_dhcp
 	  effects anything using sslutils including check_http, check_dhcp
 	  and others
 	  and others
+	utils_cmd.c: when using ssh (or check-by-ssh) with ControlMaster/ControlPersist,
+	  nagios times out the first time and one gets zombie processes (Gordon Messmer)
 
 
 
 
 2.1.2 2016-08-01
 2.1.2 2016-08-01

+ 7 - 2
lib/utils_cmd.c

@@ -140,7 +140,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
 	struct rlimit limit;
 	struct rlimit limit;
 #endif
 #endif
 
 
-	int i = 0;
+	int flags, i = 0;
 
 
 	/* if no command was passed, return with no error */
 	/* if no command was passed, return with no error */
 	if (argv == NULL)
 	if (argv == NULL)
@@ -188,6 +188,11 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
 	/* close childs descriptors in our address space */
 	/* close childs descriptors in our address space */
 	close (pfd[1]);
 	close (pfd[1]);
 	close (pfderr[1]);
 	close (pfderr[1]);
+	/* don't block on reading stderr from child, to work around
+ 	 * hang when the child has forked.  A blocking read may not
+ 	 * get EOF. */
+	flags = fcntl (pfderr[0], F_GETFL, 0);
+	fcntl (pfderr[0], F_SETFL, flags | O_NONBLOCK);
 
 
 	/* tag our file's entry in the pid-list and return it */
 	/* tag our file's entry in the pid-list and return it */
 	_cmd_pids[pfd[0]] = pid;
 	_cmd_pids[pfd[0]] = pid;
@@ -238,7 +243,7 @@ _cmd_fetch_output (int fd, output * op, int flags)
 		i++;
 		i++;
 	}
 	}
 
 
-	if (ret < 0) {
+	if (ret < 0 && (errno != EAGAIN && errno != EWOULDBLOCK)) {
 		printf ("read() returned %d: %s\n", ret, strerror (errno));
 		printf ("read() returned %d: %s\n", ret, strerror (errno));
 		return ret;
 		return ret;
 	}
 	}