|
|
30b197 |
Kludge poptBadOption() to return something semi-meaningful on exec alias fail
|
|
|
30b197 |
|
|
|
30b197 |
- poptBadOption() is totally unaware of exec alias failures, and
|
|
|
30b197 |
will return either the first argument or last option, giving
|
|
|
30b197 |
wonderfully misleading error messages (#697435, #710267).
|
|
|
30b197 |
- Remember execvp() first argument on failure and return that
|
|
|
30b197 |
from poptBadOption() if present to give the user a reasonable
|
|
|
30b197 |
clue what exactly went wrong.
|
|
|
30b197 |
|
|
|
30b197 |
diff -up popt-1.13/popt.c.execfail popt-1.13/popt.c
|
|
|
30b197 |
--- popt-1.13/popt.c.execfail 2012-08-02 16:08:34.762315304 +0300
|
|
|
30b197 |
+++ popt-1.13/popt.c 2012-08-02 16:11:41.352683721 +0300
|
|
|
30b197 |
@@ -186,6 +186,7 @@ poptContext poptGetContext(const char *
|
|
|
30b197 |
con->flags = flags;
|
|
|
30b197 |
con->execs = NULL;
|
|
|
30b197 |
con->numExecs = 0;
|
|
|
30b197 |
+ con->execFail = NULL;
|
|
|
30b197 |
con->finalArgvAlloced = argc * 2;
|
|
|
30b197 |
con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) );
|
|
|
30b197 |
con->execAbsolute = 1;
|
|
|
30b197 |
@@ -234,6 +235,7 @@ void poptResetContext(poptContext con)
|
|
|
30b197 |
con->nextLeftover = 0;
|
|
|
30b197 |
con->restLeftover = 0;
|
|
|
30b197 |
con->doExec = NULL;
|
|
|
30b197 |
+ con->execFail = _free(con->execFail);
|
|
|
30b197 |
|
|
|
30b197 |
if (con->finalArgv != NULL)
|
|
|
30b197 |
for (i = 0; i < con->finalArgvCount; i++) {
|
|
|
30b197 |
@@ -468,6 +470,7 @@ if (_popt_debug)
|
|
|
30b197 |
/*@-nullstate@*/
|
|
|
30b197 |
rc = execvp(argv[0], (char *const *)argv);
|
|
|
30b197 |
/*@=nullstate@*/
|
|
|
30b197 |
+ con->execFail = xstrdup(argv[0]);
|
|
|
30b197 |
|
|
|
30b197 |
exit:
|
|
|
30b197 |
if (argv) {
|
|
|
30b197 |
@@ -1194,11 +1197,19 @@ int poptAddItem(poptContext con, poptIte
|
|
|
30b197 |
const char * poptBadOption(poptContext con, unsigned int flags)
|
|
|
30b197 |
{
|
|
|
30b197 |
struct optionStackEntry * os = NULL;
|
|
|
30b197 |
+ const char *badOpt = NULL;
|
|
|
30b197 |
|
|
|
30b197 |
- if (con != NULL)
|
|
|
30b197 |
- os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
|
|
|
30b197 |
+ if (con != NULL) {
|
|
|
30b197 |
+ /* Stupid hack to return something semi-meaningful from exec failure */
|
|
|
30b197 |
+ if (con->execFail) {
|
|
|
30b197 |
+ badOpt = con->execFail;
|
|
|
30b197 |
+ } else {
|
|
|
30b197 |
+ os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
|
|
|
30b197 |
+ badOpt = os->argv[os->next - 1];
|
|
|
30b197 |
+ }
|
|
|
30b197 |
+ }
|
|
|
30b197 |
|
|
|
30b197 |
- return (os != NULL && os->argv != NULL ? os->argv[os->next - 1] : NULL);
|
|
|
30b197 |
+ return badOpt;
|
|
|
30b197 |
}
|
|
|
30b197 |
|
|
|
30b197 |
const char * poptStrerror(const int error)
|
|
|
30b197 |
diff -up popt-1.13/poptint.h.execfail popt-1.13/poptint.h
|
|
|
30b197 |
--- popt-1.13/poptint.h.execfail 2012-08-02 16:08:34.000000000 +0300
|
|
|
30b197 |
+++ popt-1.13/poptint.h 2012-08-02 16:12:35.796500122 +0300
|
|
|
30b197 |
@@ -78,6 +78,7 @@ struct poptContext_s {
|
|
|
30b197 |
/*@owned@*/ /*@null@*/
|
|
|
30b197 |
poptItem execs;
|
|
|
30b197 |
int numExecs;
|
|
|
30b197 |
+ char * execFail;
|
|
|
30b197 |
/*@only@*/ /*@null@*/
|
|
|
30b197 |
const char ** finalArgv;
|
|
|
30b197 |
int finalArgvCount;
|