Return malloced memory from rpmcpioStrerror()
- This is unlikely to ever run into threads, but returning a const pointer to a static buffer is sooooo last century...
This commit is contained in:
parent
8002b3f985
commit
0e0ec5bd98
|
@ -46,12 +46,13 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro)
|
|||
&csa->cpioArchiveSize, &failedFile);
|
||||
|
||||
if (fsmrc) {
|
||||
char *emsg = rpmcpioStrerror(fsmrc);
|
||||
if (failedFile)
|
||||
rpmlog(RPMLOG_ERR, _("create archive failed on file %s: %s\n"),
|
||||
failedFile, rpmcpioStrerror(fsmrc));
|
||||
failedFile, emsg);
|
||||
else
|
||||
rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"),
|
||||
rpmcpioStrerror(fsmrc));
|
||||
rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"), emsg);
|
||||
free(emsg);
|
||||
}
|
||||
|
||||
free(failedFile);
|
||||
|
|
|
@ -350,9 +350,9 @@ rpmcpio_t rpmcpioFree(rpmcpio_t cpio)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char * rpmcpioStrerror(int rc)
|
||||
char * rpmcpioStrerror(int rc)
|
||||
{
|
||||
static char msg[256];
|
||||
char msg[256];
|
||||
const char *s;
|
||||
int myerrno = errno;
|
||||
size_t l;
|
||||
|
@ -411,5 +411,5 @@ const char * rpmcpioStrerror(int rc)
|
|||
l -= strlen(s);
|
||||
if (l > 0) strncat(msg, strerror(myerrno), l);
|
||||
}
|
||||
return msg;
|
||||
return xstrdup(msg);
|
||||
}
|
||||
|
|
|
@ -132,10 +132,10 @@ ssize_t rpmcpioRead(rpmcpio_t cpio, void * buf, size_t size);
|
|||
/** \ingroup payload
|
||||
* Return formatted error message on payload handling failure.
|
||||
* @param rc error code
|
||||
* @return formatted error string
|
||||
* @return formatted error string (malloced)
|
||||
*/
|
||||
/* XXX should be RPM_GNUC_INTERNAL too but build/pack.c uses */
|
||||
const char * rpmcpioStrerror(int rc);
|
||||
char * rpmcpioStrerror(int rc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
10
lib/psm.c
10
lib/psm.c
|
@ -835,11 +835,13 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
|
|||
rpmpsmNotify(psm, RPMCALLBACK_INST_STOP, psm->total);
|
||||
|
||||
if (fsmrc) {
|
||||
char *emsg = rpmcpioStrerror(fsmrc);
|
||||
rpmlog(RPMLOG_ERR,
|
||||
_("unpacking of archive failed%s%s: %s\n"),
|
||||
(psm->failedFile != NULL ? _(" on file ") : ""),
|
||||
(psm->failedFile != NULL ? psm->failedFile : ""),
|
||||
rpmcpioStrerror(fsmrc));
|
||||
emsg);
|
||||
free(emsg);
|
||||
rc = RPMRC_FAIL;
|
||||
|
||||
/* XXX notify callback on error. */
|
||||
|
@ -939,13 +941,15 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
|
|||
break;
|
||||
case PSM_FINI:
|
||||
if (rc) {
|
||||
char *emsg = rpmcpioStrerror(rc);
|
||||
if (psm->failedFile)
|
||||
rpmlog(RPMLOG_ERR,
|
||||
_("%s failed on file %s: %s\n"),
|
||||
psm->goalName, psm->failedFile, rpmcpioStrerror(rc));
|
||||
psm->goalName, psm->failedFile, emsg);
|
||||
else
|
||||
rpmlog(RPMLOG_ERR, _("%s failed: %s\n"),
|
||||
psm->goalName, rpmcpioStrerror(rc));
|
||||
psm->goalName, emsg);
|
||||
free(emsg);
|
||||
|
||||
/* XXX notify callback on error. */
|
||||
rpmtsNotify(ts, psm->te, RPMCALLBACK_CPIO_ERROR, 0, 0);
|
||||
|
|
Loading…
Reference in New Issue