From 64a1d1afdcfce7b401f02eb19e268cd3562ef1ac Mon Sep 17 00:00:00 2001 From: jbj Date: Mon, 27 Aug 2001 18:39:17 +0000 Subject: [PATCH] - fix: error message on failed package installs resurrected. - python: memory leaks in headerLoad/headerunload bindings. - python: retrofit sha1 digest using RPMTAG_SHA1RHN. - python: change rhnUnload bindings. CVS patchset: 5032 CVS date: 2001/08/27 18:39:17 --- CHANGES | 4 ++ build/pack.c | 6 +-- lib/fsm.c | 24 +++++++---- lib/psm.c | 19 ++++----- lib/rpmlib.h | 1 + lib/verify.c | 4 +- python/poptmodule.c | 6 +-- python/rpmmodule.c | 114 ++++++++++++++++++++++++++++------------------------ rpmio/rpmerr.h | 6 +-- 9 files changed, 105 insertions(+), 79 deletions(-) diff --git a/CHANGES b/CHANGES index 8e4c698..1ae2fec 100644 --- a/CHANGES +++ b/CHANGES @@ -222,6 +222,10 @@ - verify perms (but not mode) on %ghost files. - headers without RPMTAG_NAME are skipped when retrieved. - within a region, entries sort by address; added drips sort by tag. + - fix: error message on failed package installs resurrected. + - python: memory leaks in headerLoad/headerunload bindings. + - python: retrofit sha1 digest using RPMTAG_SHA1RHN. + - python: change rhnUnload bindings. 4.0 -> 4.0.[12] - add doxygen and lclint annotations most everywhere. diff --git a/build/pack.c b/build/pack.c index 7705532..eeafff4 100644 --- a/build/pack.c +++ b/build/pack.c @@ -450,7 +450,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, if (headerWrite(fd, h, HEADER_MAGIC_YES)) { rc = RPMERR_NOSPACE; - rpmError(RPMERR_NOSPACE, _("Unable to write %s header\n"), "temp"); + rpmError(RPMERR_NOSPACE, _("Unable to write temp header\n")); } else { /* Write the archive and get the size */ if (csa->cpioList != NULL) { rc = cpio_doio(fd, h, csa, rpmio_flags); @@ -493,7 +493,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, fdInitSHA1(fd, 0); if (headerWrite(fd, h, HEADER_MAGIC_NO)) { rc = RPMERR_NOSPACE; - rpmError(RPMERR_NOSPACE, _("Unable to write %s header\n"), "final"); + rpmError(RPMERR_NOSPACE, _("Unable to write final header\n")); } (void) Fflush(fd); fdFiniSHA1(fd, (void **)&sha1, NULL, 1); @@ -524,7 +524,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, sig = headerReload(sig, RPMTAG_HEADERSIGNATURES); if (sig == NULL) { /* XXX can't happen */ rc = RPMERR_RELOAD; - rpmError(RPMERR_RELOAD, _("Unable to reload %s header.\n"), "signature"); + rpmError(RPMERR_RELOAD, _("Unable to reload signature header.\n")); goto exit; } diff --git a/lib/fsm.c b/lib/fsm.c index ae43481..1c6b092 100644 --- a/lib/fsm.c +++ b/lib/fsm.c @@ -456,7 +456,7 @@ int fsmSetup(FSM_t fsm, fileStage goal, unsigned int * archiveSize, const char ** failedFile) { size_t pos = 0; - int rc; + int rc, ec = 0; fsm->goal = goal; if (cfd) { @@ -488,15 +488,17 @@ int fsmSetup(FSM_t fsm, fileStage goal, sprintf(fsm->sufbuf, ";%08x", (unsigned)ts->id); } - rc = fsm->rc = 0; + ec = fsm->rc = 0; rc = fsmStage(fsm, FSM_CREATE); + if (rc && !ec) ec = rc; rc = fsmStage(fsm, fsm->goal); + if (rc && !ec) ec = rc; - if (fsm->archiveSize && rc == 0) + if (fsm->archiveSize && ec == 0) *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos); - return rc; + return ec; } int fsmTeardown(FSM_t fsm) { @@ -1255,8 +1257,10 @@ int fsmStage(FSM_t fsm, fileStage stage) /* Notify on success. */ (void) fsmStage(fsm, FSM_NOTIFY); - if (fsmStage(fsm, FSM_FINI)) + rc = fsmStage(fsm, FSM_FINI); + if (rc) { /*@loopbreak@*/ break; + } } break; case FSM_PKGERASE: @@ -1669,13 +1673,13 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break; /* XXX common error message. */ rpmError( - (strict_erasures ? RPMERR_RMDIR : RPMWARN_RMDIR), + (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR), _("%s rmdir of %s failed: Directory not empty\n"), fiTypeString(fi), fsm->path); break; default: rpmError( - (strict_erasures ? RPMERR_RMDIR : RPMWARN_RMDIR), + (strict_erasures ? RPMERR_RMDIR : RPMDEBUG_RMDIR), _("%s rmdir of %s failed: %s\n"), fiTypeString(fi), fsm->path, strerror(errno)); break; @@ -1685,7 +1689,7 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break; if (!rc) break; if (!(errno == ENOENT && (fsm->fflags & RPMFILE_MISSINGOK))) rpmError( - (strict_erasures ? RPMERR_UNLINK : RPMWARN_UNLINK), + (strict_erasures ? RPMERR_UNLINK : RPMDEBUG_UNLINK), _("%s unlink of %s failed: %s\n"), fiTypeString(fi), fsm->path, strerror(errno)); } @@ -1732,6 +1736,10 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break; /* Notify on success. */ if (!rc) rc = fsmStage(fsm, FSM_NOTIFY); + else if (fsm->failedFile && *fsm->failedFile == NULL) { + *fsm->failedFile = fsm->path; + fsm->path = NULL; + } break; case FSM_DESTROY: fsm->path = _free(fsm->path); diff --git a/lib/psm.c b/lib/psm.c index 9b42d90..51dd6d5 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -1779,17 +1779,19 @@ assert(psm->mi == NULL); if (!rc) { rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), (psm->pkgURL ? psm->pkgURL : "???")); - } else { - if (psm->failedFile) - rpmError(RPMERR_CPIO, - _("create archive failed on file %s: %s\n"), - psm->failedFile, cpioStrerror(rc)); - else - rpmError(RPMERR_CPIO, _("create archive failed: %s\n"), - cpioStrerror(rc)); } } + if (rc) { + if (psm->failedFile) + rpmError(RPMERR_CPIO, + _("%s failed on file %s: %s\n"), + psm->stepName, psm->failedFile, cpioStrerror(rc)); + else + rpmError(RPMERR_CPIO, _("%s failed: %s\n"), + psm->stepName, cpioStrerror(rc)); + } + if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) fi->h = headerFree(fi->h); psm->oh = headerFree(psm->oh); @@ -1803,7 +1805,6 @@ assert(psm->mi == NULL); fi->fuser = hfd(fi->fuser, -1); fi->apath = _free(fi->apath); fi->fstates = _free(fi->fstates); - break; case PSM_PKGINSTALL: diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 2defdc5..8fde12a 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -355,6 +355,7 @@ typedef enum rpmTag_e { RPMTAG_MULTILIBS = 1127, RPMTAG_INSTALLTID = 1128, RPMTAG_REMOVETID = 1129, + RPMTAG_SHA1RHN = 1130, /*!< internal */ /*@-enummemuse@*/ RPMTAG_FIRSTFREE_TAG /*!< internal */ /*@=enummemuse@*/ diff --git a/lib/verify.c b/lib/verify.c index cb0e82f..c180a7b 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -347,7 +347,9 @@ int rpmVerifyDigest(Header h) int ec = 0; /* assume no problems */ /* Retrieve header digest. */ - if (!hge(h, RPMTAG_SHA1HEADER, &hdt, (void **) &hdigest, NULL)) { + if (!hge(h, RPMTAG_SHA1HEADER, &hdt, (void **) &hdigest, NULL) + && !hge(h, RPMTAG_SHA1RHN, &hdt, (void **) &hdigest, NULL)) + { if (hge(h, RPMTAG_BADSHA1HEADER, &hdt, (void **) &hdigest, NULL)) flags |= (RPMDIGEST_REVERSE|RPMDIGEST_BCSWAP); else diff --git a/python/poptmodule.c b/python/poptmodule.c index 158743a..c382688 100644 --- a/python/poptmodule.c +++ b/python/poptmodule.c @@ -6,7 +6,7 @@ #define PY_POPT_VERSION "0.2" -static const char *rcs_id = "$Id: poptmodule.c,v 1.4 2001/07/21 19:44:22 jbj Exp $"; +static const char *rcs_id = "$Id: poptmodule.c,v 1.5 2001/08/27 18:39:17 jbj Exp $"; static char *module_doc = "Python bindings for the popt library\n\ \n\ @@ -622,8 +622,8 @@ static PyObject * _strerror(PyObject *self, PyObject *args) /* Methods for the popt module */ static struct PyMethodDef poptModuleMethods[] = { - {"getContext", (PyCFunction)getContext}, - {"strerror", (PyCFunction)_strerror}, + {"getContext", (PyCFunction)getContext, METH_VARARGS, NULL}, + {"strerror", (PyCFunction)_strerror, METH_VARARGS, NULL}, {NULL, NULL} }; diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 753591e..3a98e83 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -18,10 +18,16 @@ #include "rpmcli.h" /* XXX for rpmCheckSig */ #include "misc.h" #include "rpmio_internal.h" +#include "header_internal.h" #include "upgrade.h" extern int _rpmio_debug; +/*@unused@*/ static inline Header headerAllocated(Header h) { + h->flags |= HEADERFLAG_ALLOCATED; + return 0; +} + #ifdef __LCLINT__ #undef PyObject_HEAD #define PyObject_HEAD int _PyObjectHead @@ -439,6 +445,59 @@ static void mungeFilelist(Header h) free((void *)fileNames); } +/** + */ +static PyObject * rhnUnload(PyObject * self, PyObject * args) { + int len; + char * uh; + PyObject * rc; + hdrObject *s; + Header h; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + h = headerLink(s->h); + + /* Legacy headers are forced into immutable region. */ + if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) { + Header nh = headerReload(h, RPMTAG_HEADERIMMUTABLE); + /* XXX Another unload/load cycle to "seal" the immutable region. */ + uh = headerUnload(nh); + headerFree(nh); + h = headerLoad(uh); + headerAllocated(h); + } + + /* All headers have SHA1 digest, compute and add if necessary. */ + if (!headerIsEntry(h, RPMTAG_SHA1HEADER)) { + int_32 uht, uhc; + const char * digest; + size_t digestlen; + DIGEST_CTX ctx; + + headerGetEntry(h, RPMTAG_HEADERIMMUTABLE, &uht, (void **)&uh, &uhc); + + ctx = rpmDigestInit(RPMDIGEST_SHA1); + rpmDigestUpdate(ctx, uh, uhc); + rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1); + + headerAddEntry(h, RPMTAG_SHA1RHN, RPM_STRING_TYPE, digest, 1); + + uh = headerFreeData(uh, uht); + digest = _free(digest); + } + + len = headerSizeof(h, 0); + uh = headerUnload(h); + headerFree(h); + + rc = PyString_FromStringAndSize(uh, len); + free(uh); + + return rc; +} + /** \ingroup python */ static PyObject * hdrFullFilelist(hdrObject * s, PyObject * args) { @@ -457,6 +516,7 @@ static struct PyMethodDef hdrMethods[] = { {"expandFilelist", (PyCFunction) hdrExpandFilelist, 1 }, {"compressFilelist", (PyCFunction) hdrCompressFilelist, 1 }, {"fullFilelist", (PyCFunction) hdrFullFilelist, 1 }, + {"rhnUnload", (PyCFunction) rhnUnload, 1 }, {NULL, NULL} /* sentinel */ }; @@ -1804,6 +1864,7 @@ static PyObject * hdrLoad(PyObject * self, PyObject * args) { PyErr_SetString(pyrpmError, "bad header"); return NULL; } + headerAllocated(hdr); compressFilelist (hdr); providePackageNVR (hdr); @@ -1840,6 +1901,7 @@ static PyObject * rhnLoad(PyObject * self, PyObject * args) { PyErr_SetString(pyrpmError, "bad header"); return NULL; } + headerAllocated(hdr); if (!headerIsEntry(hdr, RPMTAG_HEADERIMMUTABLE)) { PyErr_SetString(pyrpmError, "bad header, not immutable"); @@ -1869,57 +1931,6 @@ static PyObject * rhnLoad(PyObject * self, PyObject * args) { return (PyObject *) h; } -/** - */ -static PyObject * rhnUnload(PyObject * self, PyObject * args) { - int len; - char * uh; - PyObject * rc; - hdrObject *s; - Header h; - if (!PyArg_ParseTuple(args, "O!", &hdrType, &s)) - return NULL; - - h = headerLink(s->h); - - /* Legacy headers are forced into immutable region. */ - if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) { - Header nh = headerReload(h, RPMTAG_HEADERIMMUTABLE); - /* XXX Another unload/load cycle to "seal" the immutable region. */ - uh = headerUnload(nh); - headerFree(nh); - h = headerLoad(uh); - } - - /* All headers have SHA1 digest, compute and add if necessary. */ - if (!headerIsEntry(h, RPMTAG_SHA1HEADER)) { - int_32 uht, uhc; - const char * digest; - size_t digestlen; - DIGEST_CTX ctx; - - headerGetEntry(h, RPMTAG_HEADERIMMUTABLE, &uht, (void **)&uh, &uhc); - - ctx = rpmDigestInit(RPMDIGEST_SHA1); - rpmDigestUpdate(ctx, uh, uhc); - rpmDigestFinal(ctx, (void **)&digest, &digestlen, 1); - - headerAddEntry(h, RPMTAG_SHA1HEADER, RPM_STRING_TYPE, digest, 1); - - uh = headerFreeData(uh, uht); - digest = _free(digest); - } - - len = headerSizeof(h, 0); - uh = headerUnload(h); - headerFree(h); - - rc = PyString_FromStringAndSize(uh, len); - free(uh); - - return rc; -} - /** */ static PyObject * rpmInitDB(PyObject * self, PyObject * args) { @@ -2415,7 +2426,6 @@ static PyMethodDef rpmModuleMethods[] = { { "findUpgradeSet", (PyCFunction) findUpgradeSet, METH_VARARGS, NULL }, { "headerFromPackage", (PyCFunction) rpmHeaderFromPackage, METH_VARARGS, NULL }, { "headerLoad", (PyCFunction) hdrLoad, METH_VARARGS, NULL }, - { "rhnUnload", (PyCFunction) rhnUnload, METH_VARARGS, NULL }, { "rhnLoad", (PyCFunction) rhnLoad, METH_VARARGS, NULL }, { "initdb", (PyCFunction) rpmInitDB, METH_VARARGS, NULL }, { "opendb", (PyCFunction) rpmOpenDB, METH_VARARGS, NULL }, diff --git a/rpmio/rpmerr.h b/rpmio/rpmerr.h index 7932386..93f9034 100644 --- a/rpmio/rpmerr.h +++ b/rpmio/rpmerr.h @@ -128,9 +128,9 @@ typedef enum rpmerrCode_e { RPMERR_SIGGEN = _em(201), /*!< Error generating signature */ RPMERR_SIGVFY = _nm(202), /*!< */ - RPMWARN_UNLINK = _wm(512u+16), /*!< unlink(2) failed */ - RPMWARN_RMDIR = _wm(512u+17), /*!< rmdir(2) failed */ - RPMWARN_FLOCK = _wm(512u+27) /*!< locking the database failed */ + RPMDEBUG_UNLINK = _dm(512u+16), /*!< unlink(2) failed */ + RPMDEBUG_RMDIR = _dm(512u+17), /*!< rmdir(2) failed */ + RPMWARN_FLOCK = _wm(512u+27) /*!< locking the database failed */ } rpmerrCode; /*@=typeuse @*/ -- 2.7.4