bin: diagnose failures to print --help

Fixes #349.

* bin/common_setup.cc (OPT_HELP, OPT_VERSION): Call close_stdout().
This commit is contained in:
Alexandre Duret-Lutz 2018-05-17 16:59:17 +02:00
parent a80cd361c0
commit 2f8ae55f6b

View file

@ -21,6 +21,7 @@
#include "common_aoutput.hh" #include "common_aoutput.hh"
#include "argp.h" #include "argp.h"
#include "closeout.h"
#include <cstdlib> #include <cstdlib>
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
@ -147,10 +148,17 @@ parse_opt_misc(int key, char*, struct argp_state* state)
switch (key) switch (key)
{ {
case OPT_HELP: case OPT_HELP:
argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP); argp_state_help(state, state->out_stream,
// Do not let argp exit: we want to diagnose a
// failure to print --help by closing stdout
// properly.
ARGP_HELP_STD_HELP & ~ARGP_HELP_EXIT_OK);
close_stdout();
exit(0);
break; break;
case OPT_VERSION: case OPT_VERSION:
display_version(state->out_stream, state); display_version(state->out_stream, state);
close_stdout();
exit(0); exit(0);
break; break;
default: default: