[Rpm-maint] [PATCH] Don't lose errno from rpmPackageFilesInstall

Andreas Schwab schwab at linux-m68k.org
Thu Jun 27 17:39:28 UTC 2013


There are a lot of ways to lose the value of errno after a failed
rpmPackageFilesInstall.  Typically, stdio will call isatty which then
overwrites errno with ENOTTY.  Save and restore errno between the return
from rpmPackageFilesInstall and the logging of the error.  There may be
more opportunities inside rpmPackageFilesInstall to clobber the real
errno which I haven't investigated yet.
---
 lib/psm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/psm.c b/lib/psm.c
index df09bd3..e327bba 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -806,6 +806,7 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
     case PSM_PROCESS:
 	if (psm->goal == PKG_INSTALL) {
 	    int fsmrc = 0;
+	    int saved_errno = 0;
 
 	    rpmpsmNotify(psm, RPMCALLBACK_INST_START, 0);
 	    /* make sure first progress call gets made */
@@ -820,6 +821,7 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
 
 		fsmrc = rpmPackageFilesInstall(psm->ts, psm->te, psm->fi,
 				  payload, psm, &psm->failedFile);
+		saved_errno = errno;
 
 		rpmswAdd(rpmtsOp(psm->ts, RPMTS_OP_UNCOMPRESS),
 			 fdOp(payload, FDSTAT_READ));
@@ -834,7 +836,9 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
 	    rpmpsmNotify(psm, RPMCALLBACK_INST_STOP, psm->total);
 
 	    if (fsmrc) {
-		char *emsg = rpmcpioStrerror(fsmrc);
+		char *emsg;
+		errno = saved_errno;
+		emsg = rpmcpioStrerror(fsmrc);
 		rpmlog(RPMLOG_ERR,
 			_("unpacking of archive failed%s%s: %s\n"),
 			(psm->failedFile != NULL ? _(" on file ") : ""),
-- 
1.8.3.1

-- 
Andreas Schwab, schwab at linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


More information about the Rpm-maint mailing list