Commit fa7155a6 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(abort_pending): New static variable.

(do_write_only): Now global static, not a local variable in main.
(setup_timer): Removed.  Use the one from libmisc instead.
(write_server): Handle ECONNRESET, EPIPE and end-of-file when only
	writing.
(arm_timer): Check return value of setup_timer.
(end_it): Clear abort_pending.
(main): Set abort_pending if we are about to abort.  Cancel the
	timer if the top loop returns before the abort timer fires.
	Treat ECONNRESET the same way as EPIPE.
parent 441ca8a9
......@@ -57,6 +57,7 @@
#include "s-string.h"
#include "isc.h"
#include "timeval-util.h"
#include "getopt.h"
#include "linkansi.h"
#include "unused.h"
......@@ -75,6 +76,9 @@ static int server;
static int writing_to_server;
static long last_progress_status = 0;
static int abort_pending = 0;
static int do_write_only = 0;
static oop_call_fd read_stdin;
static oop_call_fd read_server;
......@@ -91,27 +95,6 @@ fail(const char *reason)
exit(1);
}
static void
setup_timer(struct timeval *tv,
struct timeval interval)
{
if (gettimeofday(tv, NULL) < 0)
{
fprintf(stderr, "setup_timer(): gettimeofday failed: %s\n",
strerror(errno));
*tv = OOP_TIME_NOW;
}
else
{
tv->tv_sec += interval.tv_sec;
tv->tv_usec += interval.tv_usec;
if (tv->tv_usec > 1000000)
{
tv->tv_usec -= 1000000;
tv->tv_sec++;
}
}
}
static int
tcp_connect(const char *host,
......@@ -311,6 +294,8 @@ write_server(oop_source *UNUSED(source),
rv = write(fd, pos, end - pos);
if (rv < 0)
{
if ((errno == ECONNRESET || errno == EPIPE) && do_write_only)
return OOP_HALT;
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
fail("write(server)");
else
......@@ -318,6 +303,8 @@ write_server(oop_source *UNUSED(source),
}
else if (rv == 0)
{
if (do_write_only)
return OOP_HALT;
fprintf(stderr, "eof on server");
exit(1);
}
......@@ -348,7 +335,8 @@ arm_timer(oop_source *source,
struct timeval ival;
ival.tv_sec = sec;
ival.tv_usec = usec;
setup_timer(tv, ival);
if (setup_timer(tv, ival) < 0)
fprintf(stderr, "gettimeofday failed: %s\n", strerror(errno));
source->on_time(source, *tv, call, tv);
}
......@@ -397,6 +385,7 @@ end_it(oop_source *UNUSED(source),
struct timeval UNUSED(tv),
void *UNUSED(user))
{
abort_pending = 0;
return OOP_HALT;
}
......@@ -447,7 +436,6 @@ main(int argc,
/* What should we do? */
int do_limit_time = 0;
int do_abort_time = 0;
int do_write_only = 0;
int verbose = 0;
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
......@@ -534,7 +522,10 @@ main(int argc,
if (do_limit_time)
arm_timer(oop, 5, 0, limit_it, &end_timer);
else if (do_abort_time)
{
abort_pending = 1;
arm_timer(oop, do_write_only ? 15 : 5, 0, end_it, &end_timer);
}
oop_sys_run(sys);
......@@ -543,8 +534,8 @@ main(int argc,
switch (write(server, "\n", 1))
{
case -1:
/* We expect EPIPE. */
if (errno != EPIPE)
/* We expect EPIPE or ECONNRESET. */
if (errno != EPIPE && errno != ECONNRESET)
fail("final write");
break;
......@@ -565,6 +556,9 @@ main(int argc,
if (verbose)
oop->cancel_time(oop, report_timer, report_stats, &report_timer);
if (abort_pending)
oop->cancel_time(oop, end_timer, end_it, &end_timer);
printf("End of progress reports\n");
oop->cancel_time(oop, progress_timer, report_progress, &progress_timer);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment