Blame SOURCES/popt-1.16-execfail.patch

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