summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a2f032e)
raw | patch | inline | side by side (parent: a2f032e)
author | octo <octo> | |
Sun, 30 Apr 2006 16:18:49 +0000 (16:18 +0000) | ||
committer | octo <octo> | |
Sun, 30 Apr 2006 16:18:49 +0000 (16:18 +0000) |
ToDo | patch | blob | history | |
configure.ac | patch | blob | history | |
src/oping.c | patch | blob | history |
index a624cbf5b82c4eb6cb152485f6fe0f43cfd4422e..6ebf1066a275e13f1a7ba33d42e3c88e97ad9d6f 100644 (file)
--- a/ToDo
+++ b/ToDo
- Write manpage
+- Catch SIGINT in `oping'
diff --git a/configure.ac b/configure.ac
index 6f74c816f6bd2e6421481d11fe8b9d37127f9d1c..5e9fc72799e2de9eaa720c4901367a3892c7008b 100644 (file)
--- a/configure.ac
+++ b/configure.ac
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(netdb.h)
+AC_CHECK_HEADERS(signal.h)
# This sucks, but what can I do..?
AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
diff --git a/src/oping.c b/src/oping.c
index 457a09d226fbe9ceff83d07647ca7edcfdebcec0..0c799863f198a3b206249038620edc8d0a5b75c3 100644 (file)
--- a/src/oping.c
+++ b/src/oping.c
# include <netdb.h> /* NI_MAXHOST */
#endif
+#if HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
#include <liboping.h>
typedef struct ping_context
static int opt_addrfamily = PING_DEF_AF;
static int opt_count = -1;
+void sigint_handler (int signal)
+{
+ /* Exit the loop */
+ opt_count = 0;
+}
+
ping_context_t *context_create (void)
{
ping_context_t *ret;
pingobj_t *ping;
pingobj_iter_t *iter;
+ struct sigaction sigint_action;
+
struct timeval tv_begin;
struct timeval tv_end;
struct timespec ts_wait;
int optind;
int i;
-
optind = read_options (argc, argv);
if (optind >= argc)
ping_iterator_set_context (iter, (void *) context);
}
- while (1)
+ memset (&sigint_action, '\0', sizeof (sigint_action));
+ sigint_action.sa_handler = sigint_handler;
+ if (sigaction (SIGINT, &sigint_action, NULL) < 0)
{
- int status;
+ perror ("sigaction");
+ return (1);
+ }
- if (opt_count > 0)
- opt_count--;
+ while (opt_count != 0)
+ {
+ int status;
if (gettimeofday (&tv_begin, NULL) < 0)
{
}
fflush (stdout);
- if (opt_count == 0)
+ /* Don't sleep in the last iteration */
+ if (opt_count == 1)
break;
if (gettimeofday (&tv_end, NULL) < 0)
perror ("nanosleep");
break;
}
+ else if (opt_count == 0)
+ {
+ /* sigint */
+ break;
+ }
}
+
+ if (opt_count > 0)
+ opt_count--;
} /* while (opt_count != 0) */
for (iter = ping_iterator_get (ping);