summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4670892)
raw | patch | inline | side by side (parent: 4670892)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 13 Oct 2011 14:08:23 +0000 (16:08 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 13 Oct 2011 14:08:23 +0000 (16:08 +0200) |
This is an upstream patch adding option -Z to enable non-zero exit codes in
case a certain amount of replies were lost.
case a certain amount of replies were lost.
debian/changelog | patch | blob | history | |
debian/patches/series | patch | blob | history | |
debian/patches/z-option | [new file with mode: 0644] | patch | blob |
diff --git a/debian/changelog b/debian/changelog
index 2d62a9106ca7df0cea69d2847eaa50ae77489e53..72346e39b8b713d4f5aa6defa29ffdbf697e0d61 100644 (file)
--- a/debian/changelog
+++ b/debian/changelog
* debian/patches:
- Added recvtos -- patch for #618729 (missing IP_RECVTOS on FreeBSD) as
separate patch.
+ - Added z-option -- upstream patch adding option -Z to enable non-zero
+ exit codes in case a certain amount of replies were lost.
- -- Sebastian Harl <tokkee@debian.org> Thu, 13 Oct 2011 15:38:23 +0200
+ -- Sebastian Harl <tokkee@debian.org> Thu, 13 Oct 2011 16:06:10 +0200
liboping (1.6.1+2.g207d51d-1.1) unstable; urgency=low
diff --git a/debian/patches/series b/debian/patches/series
index 2f78422075a103b878068d8c453e0c0fd1366d9f..3449737b0bc8f6d29092e89b68d03da9875aa5ec 100644 (file)
--- a/debian/patches/series
+++ b/debian/patches/series
recvtos
+z-option
diff --git a/debian/patches/z-option b/debian/patches/z-option
--- /dev/null
+++ b/debian/patches/z-option
@@ -0,0 +1,144 @@
+diff a/src/mans/oping.pod b/src/mans/oping.pod
+--- a/src/mans/oping.pod
++++ b/src/mans/oping.pod
+@@ -166,6 +166,18 @@ I<Explicit Congestion Notification> (ECN), even if the deprecated
+ I<Type of Service> (ToS) aliases were used to specify the bits of outgoing
+ packets.
+
++=item B<-Z> I<percent>
++
++If any hosts have a drop rate higher than I<percent>, where I<percent> is a
++number between zero and 100 inclusively, exit with a non-zero exit status.
++Since it is not possible to have a higher drop rate than 100%, passing this
++limit will effectively disable the feature (the default). Setting the option to
++zero means that the exit status will only be zero if I<all> replies for I<all>
++hosts have been received.
++
++The exit status will indicate the number of hosts with more than I<percent>
++packets lost, up to a number of 255 failing hosts.
++
+ =back
+
+ =head1 COLORS
+diff a/src/oping.c b/src/oping.c
+--- a/src/oping.c
++++ b/src/oping.c
+@@ -121,6 +121,7 @@ static char *opt_filename = NULL;
+ static int opt_count = -1;
+ static int opt_send_ttl = 64;
+ static uint8_t opt_send_qos = 0;
++static double opt_exit_status_threshold = 1.0;
+
+ static int host_num = 0;
+
+@@ -265,6 +266,8 @@ static void usage_exit (const char *name, int status) /* {{{ */
+ " -I srcaddr source address\n"
+ " -D device outgoing interface name\n"
+ " -f filename filename to read hosts from\n"
++ " -Z percent Exit with non-zero exit status if more than this percentage of\n"
++ " probes timed out. (default: never)\n"
+
+ "\noping "PACKAGE_VERSION", http://verplant.org/liboping/\n"
+ "by Florian octo Forster <octo@verplant.org>\n"
+@@ -467,7 +470,7 @@ static int read_options (int argc, char **argv) /* {{{ */
+
+ while (1)
+ {
+- optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:");
++ optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:");
+
+ if (optchar == -1)
+ break;
+@@ -538,6 +541,24 @@ static int read_options (int argc, char **argv) /* {{{ */
+ set_opt_send_qos (optarg);
+ break;
+
++ case 'Z':
++ {
++ char *endptr = NULL;
++ double tmp;
++
++ errno = 0;
++ tmp = strtod (optarg, &endptr);
++ if ((errno != 0) || (endptr == NULL) || (*endptr != 0) || (tmp < 0.0) || (tmp > 100.0))
++ {
++ fprintf (stderr, "Ignoring invalid -Z argument: %s\n", optarg);
++ fprintf (stderr, "The \"-Z\" option requires a numeric argument between 0 and 100.\n");
++ }
++ else
++ opt_exit_status_threshold = tmp / 100.0;
++
++ break;
++ }
++
+ case 'h':
+ usage_exit (argv[0], 0);
+ break;
+@@ -623,7 +644,7 @@ static int update_stats_from_context (ping_context_t *ctx) /* {{{ */
+
+ average = context_get_average (ctx);
+ deviation = context_get_stddev (ctx);
+-
++
+ mvwprintw (ctx->window, /* y = */ 2, /* x = */ 2,
+ "rtt min/avg/max/sdev = %.3f/%.3f/%.3f/%.3f ms",
+ ctx->latency_min,
+@@ -951,9 +972,13 @@ static void update_host_hook (pingobj_iter_t *iter, /* {{{ */
+ #endif
+ } /* }}} void update_host_hook */
+
++/* Prints statistics for each host, cleans up the contexts and returns the
++ * number of hosts which failed to return more than the fraction
++ * opt_exit_status_threshold of pings. */
+ static int post_loop_hook (pingobj_t *ping) /* {{{ */
+ {
+ pingobj_iter_t *iter;
++ int failure_count = 0;
+
+ #if USE_NCURSES
+ endwin ();
+@@ -973,6 +998,13 @@ static int post_loop_hook (pingobj_t *ping) /* {{{ */
+ context_get_packet_loss (context),
+ context->latency_total);
+
++ {
++ double pct_failed = 1.0 - (((double) context->req_rcvd)
++ / ((double) context->req_sent));
++ if (pct_failed > opt_exit_status_threshold)
++ failure_count++;
++ }
++
+ if (context->req_rcvd != 0)
+ {
+ double average;
+@@ -992,7 +1024,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 +1313,19 @@ int main (int argc, char **argv) /* {{{ */
+ opt_count--;
+ } /* while (opt_count != 0) */
+
+- post_loop_hook (ping);
++ /* Returns the number of failed hosts according to -Z. */
++ status = post_loop_hook (ping);
+
+ ping_destroy (ping);
+
+- return (0);
++ if (status == 0)
++ exit (EXIT_SUCCESS);
++ else
++ {
++ if (status > 255)
++ status = 255;
++ exit (status);
++ }
+ } /* }}} int main */
+
+ /* vim: set fdm=marker : */