Commit 18221a2d authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(main): Implement --write-only.

parent 66818e08
......@@ -425,6 +425,7 @@ static struct option longopts[] = {
{"silent", 0, 0, 's'},
{"time-abort", 0, 0, 'a'},
{"time-limit", 0, 0, 'l'},
{"write-only", 0, 0, 'w'},
{ 0, 0, 0, 0 }
};
......@@ -446,9 +447,13 @@ 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;
while ((optc = getopt_long(argc, argv, "valp",
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
fail("signal");
while ((optc = getopt_long(argc, argv, "wvalp",
longopts, (int *) 0)) != EOF)
{
switch (optc)
......@@ -469,11 +474,18 @@ main(int argc,
do_limit_time = 1;
break;
case 'w':
do_write_only = 1;
break;
case '?':
fail("usage");
}
}
if (do_write_only && !do_abort_time)
fail("usage");
if (optind + 2 != argc)
fail("usage");
......@@ -509,7 +521,8 @@ main(int argc,
oop = oop_sys_source(sys);
oop->on_fd(oop, 0, OOP_READ, read_stdin, NULL);
oop->on_fd(oop, server, OOP_READ, read_server, NULL);
if (!do_write_only)
oop->on_fd(oop, server, OOP_READ, read_server, NULL);
oop->on_fd(oop, server, OOP_WRITE, write_server, NULL);
writing_to_server = 1;
......@@ -521,10 +534,34 @@ main(int argc,
if (do_limit_time)
arm_timer(oop, 5, 0, limit_it, &end_timer);
else if (do_abort_time)
arm_timer(oop, 5, 0, end_it, &end_timer);
arm_timer(oop, do_write_only ? 15 : 5, 0, end_it, &end_timer);
oop_sys_run(sys);
if (do_write_only)
{
switch (write(server, "\n", 1))
{
case -1:
/* We expect EPIPE. */
if (errno != EPIPE)
fail("final write");
break;
case 0:
fprintf(stderr, "final write returned 0\n");
break;
case 1:
fprintf(stderr, "ERROR: final write succeeded\n");
break;
default:
fprintf(stderr, "insane return value from final write\n");
break;
}
}
if (verbose)
oop->cancel_time(oop, report_timer, report_stats, &report_timer);
......@@ -534,7 +571,8 @@ main(int argc,
do_report_stats();
oop->cancel_fd(oop, 0, OOP_READ);
oop->cancel_fd(oop, server, OOP_READ);
if (!do_write_only)
oop->cancel_fd(oop, server, OOP_READ);
stop_writing(oop);
oop_sys_delete(sys);
......
Supports Markdown
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