Patch available,
https://github.com/barak/liboping/commit/e48d79399dee92b8b3ea340d8b7be48b7fbf8a5b

                                        --Barak.
-- 
Barak A. Pearlmutter
 Hamilton Institute & Dept Comp Sci, NUI Maynooth, Co. Kildare, Ireland
 http://www.bcl.hamilton.ie/~barak/
>From e48d79399dee92b8b3ea340d8b7be48b7fbf8a5b Mon Sep 17 00:00:00 2001
From: "Barak A. Pearlmutter" <barak+...@cs.nuim.ie>
Date: Thu, 1 Sep 2011 13:22:05 +0100
Subject: [PATCH] non-zero process exit status when too many packets are
 unreturned

The number of unreturned packets in excess of 50% is summed over all
hosts.  If this is nonzero, this count plus 1 is the process exit
status.
---
 src/oping.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/oping.c b/src/oping.c
index 79d7569..5b75dae 100644
--- a/src/oping.c
+++ b/src/oping.c
@@ -951,9 +951,14 @@ static void update_host_hook (pingobj_iter_t *iter, /* {{{ */
 #endif
 } /* }}} void update_host_hook */
 
+/* returns the number of significant failures: sum over hosts of
+   unreturned packets exceeding 50% of the number sent, rounding up. */
 static int post_loop_hook (pingobj_t *ping) /* {{{ */
 {
 	pingobj_iter_t *iter;
+	/* failures to report: sum over hosts of number of failed
+	   returns above 50% */
+	int failure_count = 0;
 
 #if USE_NCURSES
 	endwin ();
@@ -973,6 +978,13 @@ static int post_loop_hook (pingobj_t *ping) /* {{{ */
 				context_get_packet_loss (context),
 				context->latency_total);
 
+		{
+		  /* threshold for counting failed returns is 50%, rounding up */
+		  int threshold = (context->req_sent + 1) / 2;
+		  if (context->req_rcvd < threshold)
+		    failure_count += threshold - context->req_rcvd;
+		}
+
 		if (context->req_rcvd != 0)
 		{
 			double average;
@@ -992,7 +1004,7 @@ static int post_loop_hook (pingobj_t *ping) /* {{{ */
 		context_destroy (context);
 	}
 
-	return (0);
+	return (failure_count);
 } /* }}} int post_loop_hook */
 
 int main (int argc, char **argv) /* {{{ */
@@ -1281,11 +1293,14 @@ int main (int argc, char **argv) /* {{{ */
 			opt_count--;
 	} /* while (opt_count != 0) */
 
-	post_loop_hook (ping);
+	status = post_loop_hook (ping);
 
 	ping_destroy (ping);
 
-	return (0);
+	if (status)
+	  return (EXIT_FAILURE + status);
+	else
+	  return (EXIT_SUCCESS);
 } /* }}} int main */
 
 /* vim: set fdm=marker : */
-- 
1.7.5.4

Reply via email to