Blame SOURCES/popt-1.16-execfail.patch

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