Patch by Panu Matilainen for popt <= 1.16 which kludges poptBadOption() to return something semi-meaningful on exec alias fail: - poptBadOption() is totally unaware of exec alias failures, and will return either the first argument or last option, giving wonderfully misleading error messages (#697435, #710267). - Remember execvp() first argument on failure and return that from poptBadOption() if present to give the user a reasonable clue what exactly went wrong. This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.html --- popt-1.16/popt.c 2010-01-19 01:39:10.000000000 +0100 +++ popt-1.16/popt.c.execfail 2013-11-24 15:50:06.000000000 +0100 @@ -192,6 +192,7 @@ con->flags = flags; con->execs = NULL; con->numExecs = 0; + con->execFail = NULL; con->finalArgvAlloced = argc * 2; con->finalArgv = calloc( (size_t)con->finalArgvAlloced, sizeof(*con->finalArgv) ); con->execAbsolute = 1; @@ -236,6 +237,7 @@ con->nextLeftover = 0; con->restLeftover = 0; con->doExec = NULL; + con->execFail = _free(con->execFail); if (con->finalArgv != NULL) for (i = 0; i < con->finalArgvCount; i++) { @@ -564,6 +566,7 @@ /*@-nullstate@*/ rc = execvp(argv[0], (char *const *)argv); /*@=nullstate@*/ + con->execFail = xstrdup(argv[0]); exit: if (argv) { @@ -1697,11 +1700,19 @@ const char * poptBadOption(poptContext con, unsigned int flags) { struct optionStackEntry * os = NULL; + const char *badOpt = NULL; - if (con != NULL) - os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os; + if (con != NULL) { + /* Stupid hack to return something semi-meaningful from exec failure */ + if (con->execFail) { + badOpt = con->execFail; + } else { + os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os; + badOpt = os->argv[os->next - 1]; + } + } - return (os != NULL && os->argv != NULL ? os->argv[os->next - 1] : NULL); + return badOpt; } const char * poptStrerror(const int error) --- popt-1.16/poptint.h 2010-01-19 01:39:10.000000000 +0100 +++ popt-1.16/poptint.h.execfail 2013-11-24 15:50:38.000000000 +0100 @@ -132,6 +132,7 @@ /*@owned@*/ /*@null@*/ poptItem execs; int numExecs; + char * execFail; /*@only@*/ /*@null@*/ poptArgv finalArgv; int finalArgvCount;