Code

ping_receive_all(): Return immediately when select(2) is interrupted.
[liboping.git] / src / oping.c
index 776dc0b6becd95aa7bc5b5e8ada9b99b3050f9c1..caf655fd441197c46f2f39f544e711235e85fa6c 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * Object oriented C module to send ICMP and ICMPv6 `echo's.
- * Copyright (C) 2006-2010  Florian octo Forster <octo at verplant.org>
+ * Copyright (C) 2006-2011  Florian octo Forster <ff at octo.it>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 # define _POSIX_SAVED_IDS 0
 #endif
 
+#ifndef IPTOS_MINCOST
+# define IPTOS_MINCOST 0x02
+#endif
+
+/* Remove GNU specific __attribute__ settings when using another compiler */
+#if !__GNUC__
+# define __attribute__(x) /**/
+#endif
+
 typedef struct ping_context
 {
        char host[NI_MAXHOST];
@@ -268,6 +277,7 @@ static void usage_exit (const char *name, int status) /* {{{ */
        exit (status);
 } /* }}} void usage_exit */
 
+__attribute__((noreturn))
 static void usage_qos_exit (const char *arg, int status) /* {{{ */
 {
        if (arg != 0)
@@ -329,8 +339,8 @@ static int set_opt_send_qos (const char *opt) /* {{{ */
                        && (strlen (opt) == 4))
        {
                uint8_t dscp;
-               uint8_t class;
-               uint8_t prec;
+               uint8_t class = 0;
+               uint8_t prec = 0;
 
                /* There are four classes, AF1x, AF2x, AF3x, and AF4x. */
                if (opt[2] == '1')
@@ -667,7 +677,7 @@ static int on_resize (pingobj_t *ping) /* {{{ */
                        context->window = NULL;
                }
                context->window = newwin (/* height = */ 4,
-                               /* width = */ 0,
+                               /* width = */ width,
                                /* y = */ main_win_height + (4 * context->index),
                                /* x = */ 0);
        }
@@ -720,7 +730,7 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
 
        main_win_height = height - (4 * host_num);
        main_win = newwin (/* height = */ main_win_height,
-                       /* width = */ 0,
+                       /* width = */ width,
                        /* y = */ 0, /* x = */ 0);
        /* Allow scrolling */
        scrollok (main_win, TRUE);
@@ -746,7 +756,7 @@ static int pre_loop_hook (pingobj_t *ping) /* {{{ */
                        context->window = NULL;
                }
                context->window = newwin (/* height = */ 4,
-                               /* width = */ 0,
+                               /* width = */ width,
                                /* y = */ main_win_height + (4 * context->index),
                                /* x = */ 0);
        }
@@ -814,7 +824,7 @@ static int post_sleep_hook (__attribute__((unused)) pingobj_t *ping) /* {{{ */
 #endif
 
 static void update_host_hook (pingobj_iter_t *iter, /* {{{ */
-               int index)
+               __attribute__((unused)) int index)
 {
        double          latency;
        unsigned int    sequence;
@@ -1224,7 +1234,12 @@ int main (int argc, char **argv) /* {{{ */
                        return (1);
                }
 
-               if (ping_send (ping) < 0)
+               status = ping_send (ping);
+               if (status == -EINTR)
+               {
+                       continue;
+               }
+               else if (status < 0)
                {
                        fprintf (stderr, "ping_send failed: %s\n",
                                        ping_get_error (ping));
@@ -1257,14 +1272,13 @@ int main (int argc, char **argv) /* {{{ */
                /* printf ("Sleeping for %i.%09li seconds\n", (int) ts_wait.tv_sec, ts_wait.tv_nsec); */
                while ((status = nanosleep (&ts_wait, &ts_wait)) != 0)
                {
-                       if (errno != EINTR)
+                       if (errno == EINTR)
                        {
-                               perror ("nanosleep");
-                               break;
+                               continue;
                        }
-                       else if (opt_count == 0)
+                       else
                        {
-                               /* sigint */
+                               perror ("nanosleep");
                                break;
                        }
                }