From 2f8ae55f6b003da8b4615438aabb83ceaefaefc0 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 17 May 2018 16:59:17 +0200 Subject: [PATCH] bin: diagnose failures to print --help Fixes #349. * bin/common_setup.cc (OPT_HELP, OPT_VERSION): Call close_stdout(). --- bin/common_setup.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/common_setup.cc b/bin/common_setup.cc index f9c4d63e4..39337669a 100644 --- a/bin/common_setup.cc +++ b/bin/common_setup.cc @@ -21,6 +21,7 @@ #include "common_aoutput.hh" #include "argp.h" +#include "closeout.h" #include #include #include @@ -147,10 +148,17 @@ parse_opt_misc(int key, char*, struct argp_state* state) switch (key) { 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; case OPT_VERSION: display_version(state->out_stream, state); + close_stdout(); exit(0); break; default: