diff options
author | jbj <devnull@localhost> | 2001-01-03 20:19:27 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-01-03 20:19:27 +0000 |
commit | 23fcf67cb51b54c4c1f23188ee355dbcbfba0a28 (patch) | |
tree | f8d1a8a5a523fd6f60760b2930f99f1f18349091 /lib | |
parent | fd2c1d927f4a13e0507ab929a009decdbb90c01e (diff) | |
download | rpm-23fcf67cb51b54c4c1f23188ee355dbcbfba0a28.tar.gz rpm-23fcf67cb51b54c4c1f23188ee355dbcbfba0a28.tar.bz2 rpm-23fcf67cb51b54c4c1f23188ee355dbcbfba0a28.zip |
- fix: avoid locale issues with strcasecmp/strncasecmp (#23199).
- remove almost all explicit uses of stderr in rpmlib using rpmError().
CVS patchset: 4406
CVS date: 2001/01/03 20:19:27
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cpio.c | 8 | ||||
-rw-r--r-- | lib/db1.c | 11 | ||||
-rw-r--r-- | lib/db2.c | 8 | ||||
-rw-r--r-- | lib/db3.c | 24 | ||||
-rw-r--r-- | lib/falloc.c | 3 | ||||
-rw-r--r-- | lib/header.c | 50 | ||||
-rw-r--r-- | lib/install.c | 14 | ||||
-rw-r--r-- | lib/poptBT.c | 5 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 38 | ||||
-rw-r--r-- | lib/rpminstall.c | 6 | ||||
-rw-r--r-- | lib/rpmrc.c | 14 | ||||
-rw-r--r-- | lib/signature.c | 10 |
12 files changed, 75 insertions, 116 deletions
diff --git a/lib/cpio.c b/lib/cpio.c index e5bc39245..7537a405d 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -9,6 +9,7 @@ #include "system.h" #include "cpio.h" +#include "rpmerr.h" #include "debug.h" /*@access FD_t@*/ @@ -441,13 +442,13 @@ static int expandRegular(FD_t cfd, const struct cpioHeader * hdr, strcpy(buf, hdr->path); strcat(buf, "-RPMDELETE"); if (rename(hdr->path, buf)) { - fprintf(stderr, _("can't rename %s to %s: %s\n"), + rpmError(RPMERR_RENAME, _("can't rename %s to %s: %s\n"), hdr->path, buf, strerror(errno)); return CPIOERR_UNLINK_FAILED; } if (unlink(buf)) { - fprintf(stderr, _("can't unlink %s: %s\n"), + rpmError(RPMERR_UNLINK, _("can't unlink %s: %s\n"), buf, strerror(errno)); #if 0 return CPIOERR_UNLINK_FAILED; @@ -754,7 +755,8 @@ int cpioInstallArchive(FD_t cfd, const struct cpioFileMapping * mappings, } if ((rc = getNextHeader(cfd, hdr))) { #if 0 /* XXX this is the failure point for an unreadable rpm */ - fprintf(stderr, _("getNextHeader: %s\n"), cpioStrerror(rc)); + rpmError(RPMERR_BADPACKAGE, _("getNextHeader: %s\n"), + cpioStrerror(rc)); #endif return rc; } @@ -88,10 +88,12 @@ static int cvtdberr(dbiIndex dbi, const char * msg, int error, int printit) { rc = -1; if (printit && rc) { - fprintf(stderr, _("db%d error(%d)"), dbi->dbi_api, rc); if (msg) - fprintf(stderr, _(" performing %s"), msg); - fprintf(stderr, ": %s\n", db_strerror(error)); + rpmError(RPMERR_DBERR, _("db%d error(%d) from %s: %s\n"), + dbi->dbi_api, rc, msg, db_strerror(error)); + else + rpmError(RPMERR_DBERR, _("db%d error(%d): %s\n"), + dbi->dbi_api, rc, db_strerror(error)); } return rc; @@ -382,9 +384,6 @@ static int db1close(/*@only@*/ dbiIndex dbi, /*@unused@*/ unsigned int flags) dbi->dbi_db = NULL; } - if (dbi->dbi_debug) - fprintf(stderr, "db1close: rc %d db %p\n", rc, dbi->dbi_db); - rpmMessage(RPMMESS_DEBUG, _("closed db file %s\n"), urlfn); /* Remove temporary databases */ if (dbi->dbi_temporary) { @@ -108,8 +108,12 @@ static int cvtdberr(dbiIndex dbi, const char * msg, int error, int printit) { rc = -1; if (printit && rc) { - fprintf(stderr, "*** db%d %s rc %d %s\n", dbi->dbi_api, msg, - rc, db_strerror(error)); + if (msg) + rpmError(RPMERR_DBERR, _("db%d error(%d) from %s: %s\n"), + dbi->dbi_api, rc, msg, db_strerror(error)); + else + rpmError(RPMERR_DBERR, _("db%d error(%d): %s\n"), + dbi->dbi_api, rc, db_strerror(error)); } return rc; @@ -264,7 +264,8 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) break; } if (opt->longName == NULL) { - fprintf(stderr, _("dbiSetConfig: unrecognized db option: \"%s\" ignored\n"), o); + rpmError(RPMERR_DBCONFIG, + _("unrecognized db option: \"%s\" ignored\n"), o); continue; } @@ -287,12 +288,13 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) case POPT_ARG_LONG: aLong = strtol(p, &pe, 0); if (pe) { - if (!strncasecmp(pe, "Mb", 2)) + if (!xstrncasecmp(pe, "Mb", 2)) aLong *= 1024 * 1024; - else if (!strncasecmp(pe, "Kb", 2)) + else if (!xstrncasecmp(pe, "Kb", 2)) aLong *= 1024; else if (*pe != '\0') { - fprintf(stderr,_("%s has invalid numeric value, skipped\n"), + rpmError(RPMERR_DBCONFIG, + _("%s has invalid numeric value, skipped\n"), opt->longName); continue; } @@ -300,7 +302,8 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { if (aLong == LONG_MIN || aLong == LONG_MAX) { - fprintf(stderr, _("%s has too large or too small long value, skipped\n"), + rpmError(RPMERR_DBCONFIG, + _("%s has too large or too small long value, skipped\n"), opt->longName); continue; } @@ -308,7 +311,8 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) break; } else { if (aLong > INT_MAX || aLong < INT_MIN) { - fprintf(stderr, _("%s has too large or too small integer value, skipped\n"), + rpmError(RPMERR_DBCONFIG, + _("%s has too large or too small integer value, skipped\n"), opt->longName); continue; } @@ -448,10 +452,12 @@ static int cvtdberr(dbiIndex dbi, const char * msg, int error, int printit) { rc = error; if (printit && rc) { - fprintf(stderr, _("db%d error(%d)"), dbi->dbi_api, rc); if (msg) - fprintf(stderr, _(" performing %s"), msg); - fprintf(stderr, ": %s\n", db_strerror(error)); + rpmError(RPMERR_DBERR, _("db%d error(%d) from %s: %s\n"), + dbi->dbi_api, rc, msg, db_strerror(error)); + else + rpmError(RPMERR_DBERR, _("db%d error(%d): %s\n"), + dbi->dbi_api, rc, db_strerror(error)); } return rc; diff --git a/lib/falloc.c b/lib/falloc.c index 55faf471a..3a5936fdd 100644 --- a/lib/falloc.c +++ b/lib/falloc.c @@ -13,6 +13,7 @@ #include "system.h" #include <rpmio_internal.h> +#include <rpmerr.h> #include "falloc.h" #include "debug.h" @@ -137,7 +138,7 @@ unsigned int fadAlloc(FD_t fd, unsigned int size) /* XXX W2DO? exit(EXIT_FAILURE) forces the user to discover rpm --rebuilddb */ if (!header.isFree) { - fprintf(stderr, _("free list corrupt (%u)- please run\n" + rpmError(RPMERR_FREELIST, _("free list corrupt (%u)- please run\n" "\t\"rpm --rebuilddb\"\n" "More information is available from http://www.rpm.org " "or the rpm-list@redhat.com mailing list\n" diff --git a/lib/header.c b/lib/header.c index 8fa756982..80eb31e98 100644 --- a/lib/header.c +++ b/lib/header.c @@ -149,54 +149,6 @@ struct sprintfToken { } u; }; -#if HAVE_MCHECK_H -static int probe_headers = 0; -#define HEADERPROBE(_h, _msg) if (probe_headers) headerProbe((_h), (_msg)) - -static void headerProbeAddr(Header h, const char * msg, - void * p, const char * imsg) -{ - const char * mchkstr = NULL; - switch (mprobe(p)) { - case MCHECK_DISABLED: - case MCHECK_OK: - return; - /*@notreached@*/ break; - case MCHECK_HEAD: - mchkstr = "HEAD"; - break; - case MCHECK_TAIL: - mchkstr = "TAIL"; - break; - case MCHECK_FREE: - mchkstr = "FREE"; - break; - } - fprintf(stderr, "*** MCHECK_%s h %p", mchkstr, h); - if (imsg && p) - fprintf(stderr, " %s %p", imsg, p); - if (msg) - fprintf(stderr, " %s", msg); - fprintf(stderr, "\n"); -} - -static void headerProbe(Header h, const char *msg) -{ - char imsg[256]; - int i; - - headerProbeAddr(h, msg, h, "header"); - sprintf(imsg, "index (used %d)", h->indexUsed); - headerProbeAddr(h, msg, h->index, imsg); - for (i = 0; i < h->indexUsed; i++) { - sprintf(imsg, "index[%d:%d].data", i, h->indexUsed); - headerProbeAddr(h, msg, h->index[i].data, imsg); - } -} -#else /* HAVE_MCHECK_H */ -#define HEADERPROBE(_h, _msg) -#endif /* HAVE_MCHECK_H */ - /** * Return length of entry data. * @param type entry data type @@ -1273,7 +1225,6 @@ static int intGetEntry(Header h, int_32 tag, /*@out@*/ int_32 *type, { struct indexEntry * entry; - HEADERPROBE(h, "intGetEntry"); /* First find the tag */ entry = findEntry(h, tag, RPM_NULL_TYPE); if (entry == NULL) { @@ -1357,7 +1308,6 @@ void headerFree(Header h) Header headerLink(Header h) { - HEADERPROBE(h, "headerLink"); h->nrefs++; /*@-refcounttrans@*/ return h; /*@=refcounttrans@*/ } diff --git a/lib/install.c b/lib/install.c index cbb9d18f6..98e8e4ae5 100644 --- a/lib/install.c +++ b/lib/install.c @@ -278,7 +278,7 @@ static void trimChangelog(Header h) * @param h header from * @param newH header to * @param actions array of file dispositions - * @return 0 always + * @return 0 on success, 1 on failure */ static int mergeFiles(Header h, Header newH, enum fileActions * actions) { @@ -362,9 +362,10 @@ static int mergeFiles(Header h, Header newH, enum fileActions * actions) free (data); break; default: - fprintf(stderr, _("Data type %d not supported\n"), (int) type); - exit(EXIT_FAILURE); - /*@notreached@*/ + rpmError(RPMERR_DATATYPE, _("Data type %d not supported\n"), + (int) type); + return 1; + /*@notreached@*/ break; } } headerGetEntry(newH, RPMTAG_DIRINDEXES, NULL, (void **) &newDirIndexes, @@ -1178,7 +1179,10 @@ int installBinaryPackage(const rpmTransactionSet ts, FD_t fd, Header h, headerModifyEntry(oldH, RPMTAG_MULTILIBS, RPM_INT32_TYPE, &multiLib, 1); } - mergeFiles(oldH, h, actions); + if (mergeFiles(oldH, h, actions)) { + rc = 2; + goto exit; + } } if (rpmdbAdd(ts->rpmdb, h)) { diff --git a/lib/poptBT.c b/lib/poptBT.c index 3de85cf1e..b2f2e96f5 100644 --- a/lib/poptBT.c +++ b/lib/poptBT.c @@ -91,9 +91,8 @@ static void buildArgCallback( /*@unused@*/ poptContext con, case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break; case POPT_BUILDROOT: if (rba->buildRootOverride) { - fprintf(stderr, _("buildroot already specified")); - exit(EXIT_FAILURE); - /*@notreached@*/ + rpmError(RPMERR_BUILDROOT, _("buildroot already specified, ignoring %s\n"), arg); + break; } rba->buildRootOverride = xstrdup(arg); break; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 818eb3766..6f409e12d 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -35,7 +35,7 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc) if (*fdp == NULL && fnp && *fnp) { fd = Fopen(*fnp, ((flags & O_WRONLY) ? "w.ufdio" : "r.ufdio")); if (fd == NULL || Ferror(fd)) { - fprintf(stderr, _("%s: open failed: %s\n"), *fnp, + rpmError(RPMERR_OPEN, _("%s: open failed: %s\n"), *fnp, Fstrerror(fd)); return 1; } @@ -46,7 +46,7 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc) /* open a temp file */ if (*fdp == NULL && (fnp == NULL || *fnp == NULL)) { if (makeTempFile(NULL, (fnp ? &fn : NULL), &fd)) { - fprintf(stderr, _("makeTempFile failed\n")); + rpmError(RPMERR_MAKETEMP, _("makeTempFile failed\n")); return 1; } if (fnp) @@ -78,13 +78,13 @@ static int copyFile(FD_t *sfdp, const char **sfnp, while ((count = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), *sfdp)) > 0) { if (Fwrite(buffer, sizeof(buffer[0]), count, *tfdp) < 0) { - fprintf(stderr, _("%s: Fwrite failed: %s\n"), *tfnp, + rpmError(RPMERR_FWRITE, _("%s: Fwrite failed: %s\n"), *tfnp, Fstrerror(*tfdp)); goto exit; } } if (count < 0) { - fprintf(stderr, _("%s: Fread failed: %s\n"), *sfnp, Fstrerror(*sfdp)); + rpmError(RPMERR_FREAD, _("%s: Fread failed: %s\n"), *sfnp, Fstrerror(*sfdp)); goto exit; } @@ -133,16 +133,16 @@ l = malloc(sizeof(*l)); goto exit; if (readLead(fd, l)) { - fprintf(stderr, _("%s: readLead failed\n"), rpm); + rpmError(RPMERR_READLEAD, _("%s: readLead failed\n"), rpm); goto exit; } switch (l->major) { case 1: - fprintf(stderr, _("%s: Can't sign v1.0 RPM\n"), rpm); + rpmError(RPMERR_BADSIGTYPE, _("%s: Can't sign v1.0 RPM\n"), rpm); goto exit; /*@notreached@*/ break; case 2: - fprintf(stderr, _("%s: Can't re-sign v2.0 RPM\n"), rpm); + rpmError(RPMERR_BADSIGTYPE, _("%s: Can't re-sign v2.0 RPM\n"), rpm); goto exit; /*@notreached@*/ break; default: @@ -150,11 +150,11 @@ l = malloc(sizeof(*l)); } if (rpmReadSignature(fd, &sig, l->signature_type)) { - fprintf(stderr, _("%s: rpmReadSignature failed\n"), rpm); + rpmError(RPMERR_SIGGEN, _("%s: rpmReadSignature failed\n"), rpm); goto exit; } if (sig == NULL) { - fprintf(stderr, _("%s: No signature available\n"), rpm); + rpmError(RPMERR_SIGGEN, _("%s: No signature available\n"), rpm); goto exit; } @@ -187,13 +187,13 @@ l = malloc(sizeof(*l)); l->signature_type = RPMSIG_HEADERSIG; if (writeLead(ofd, l)) { - fprintf(stderr, _("%s: writeLead failed: %s\n"), trpm, + rpmError(RPMERR_WRITELEAD, _("%s: writeLead failed: %s\n"), trpm, Fstrerror(ofd)); goto exit; } if (rpmWriteSignature(ofd, sig)) { - fprintf(stderr, _("%s: rpmWriteSignature failed: %s\n"), trpm, + rpmError(RPMERR_SIGGEN, _("%s: rpmWriteSignature failed: %s\n"), trpm, Fstrerror(ofd)); goto exit; } @@ -267,13 +267,13 @@ l = malloc(sizeof(*l)); } if (readLead(fd, &lead)) { - fprintf(stderr, _("%s: readLead failed\n"), rpm); + rpmError(RPMERR_READLEAD, _("%s: readLead failed\n"), rpm); res++; goto bottom; } switch (l->major) { case 1: - fprintf(stderr, _("%s: No signature available (v1.0 RPM)\n"), rpm); + rpmError(RPMERR_BADSIGTYPE, _("%s: No signature available (v1.0 RPM)\n"), rpm); res++; goto bottom; /*@notreached@*/ break; @@ -281,12 +281,12 @@ l = malloc(sizeof(*l)); break; } if (rpmReadSignature(fd, &sig, l->signature_type)) { - fprintf(stderr, _("%s: rpmReadSignature failed\n"), rpm); + rpmError(RPMERR_SIGGEN, _("%s: rpmReadSignature failed\n"), rpm); res++; goto bottom; } if (sig == NULL) { - fprintf(stderr, _("%s: No signature available\n"), rpm); + rpmError(RPMERR_SIGGEN, _("%s: No signature available\n"), rpm); res++; goto bottom; } @@ -432,9 +432,9 @@ l = malloc(sizeof(*l)); if (res2) { if (rpmIsVerbose()) { - fprintf(stderr, "%s", (char *)buffer); + rpmError(RPMERR_SIGVFY, "%s", (char *)buffer); } else { - fprintf(stderr, "%s%s%s%s%s%s%s%s\n", (char *)buffer, + rpmError(RPMERR_SIGVFY, "%s%s%s%s%s%s%s%s\n", (char *)buffer, _("NOT OK"), (missingKeys[0] != '\0') ? _(" (MISSING KEYS:") : "", (char *)missingKeys, @@ -446,9 +446,9 @@ l = malloc(sizeof(*l)); } } else { if (rpmIsVerbose()) { - fprintf(stdout, "%s", (char *)buffer); + rpmError(RPMERR_SIGVFY, "%s", (char *)buffer); } else { - fprintf(stdout, "%s%s%s%s%s%s%s%s\n", (char *)buffer, + rpmError(RPMERR_SIGVFY, "%s%s%s%s%s%s%s%s\n", (char *)buffer, _("OK"), (missingKeys[0] != '\0') ? _(" (MISSING KEYS:") : "", (char *)missingKeys, diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 6e9e6f2da..1cac761e0 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -330,7 +330,9 @@ int rpmInstall(const char * rootdir, const char ** fileArgv, rpmMessage(RPMMESS_ERROR, _("cannot open Packages database in %s\n"), dn); free((void *)dn); - exit(EXIT_FAILURE); + numFailed++; + pkgURL[i] = NULL; + break; } rpmdep = rpmtransCreateSet(db, rootdir); dbIsOpen = 1; @@ -532,7 +534,7 @@ int rpmErase(const char * rootdir, const char ** argv, dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL); rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn); free((void *)dn); - exit(EXIT_FAILURE); + return -1; } rpmdep = rpmtransCreateSet(db, rootdir); diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 187721402..292aaf0e2 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -117,7 +117,7 @@ static void rpmSetVarArch(int var, const char * val, const char * arch); static void rebuildCompatTables(int type, const char *name); static int optionCompare(const void * a, const void * b) { - return strcasecmp(((struct rpmOption *) a)->name, + return xstrcasecmp(((struct rpmOption *) a)->name, ((struct rpmOption *) b)->name); } @@ -207,16 +207,8 @@ static /*@observer@*/ struct machEquivInfo * { int i; -/* - * XXX The strcasecmp below is necessary so the old (rpm < 2.90) style - * XXX os-from-uname (e.g. "Linux") is compatible with the new - * XXX os-from-platform (e.g "linux" from "sparc-*-linux"). - * XXX A copy of this string is embedded in headers and is - * XXX used by rpmInstallPackage->{os,arch}Okay->rpmMachineScore->. - * XXX to verify correct arch/os from headers. - */ for (i = 0; i < table->count; i++) - if (!strcasecmp(table->list[i].name, name)) + if (!xstrcasecmp(table->list[i].name, name)) return table->list + i; return NULL; @@ -1238,7 +1230,7 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget) if ((co = strrchr(c, '-')) == NULL) { co = c; } else { - if (!strcasecmp(co, "-gnu")) + if (!xstrcasecmp(co, "-gnu")) *co = '\0'; if ((co = strrchr(c, '-')) == NULL) co = c; diff --git a/lib/signature.c b/lib/signature.c index 75f3dea2f..d57b6e800 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -51,13 +51,13 @@ int rpmLookupSignatureType(int action) { const char *name = rpmExpand("%{_signature}", NULL); if (!(name && *name != '%')) rc = 0; - else if (!strcasecmp(name, "none")) + else if (!xstrcasecmp(name, "none")) rc = 0; - else if (!strcasecmp(name, "pgp")) + else if (!xstrcasecmp(name, "pgp")) rc = RPMSIGTAG_PGP; - else if (!strcasecmp(name, "pgp5")) /* XXX legacy */ + else if (!xstrcasecmp(name, "pgp5")) /* XXX legacy */ rc = RPMSIGTAG_PGP; - else if (!strcasecmp(name, "gpg")) + else if (!xstrcasecmp(name, "gpg")) rc = RPMSIGTAG_GPG; else rc = -1; /* Invalid %_signature spec in macro file */ @@ -641,7 +641,7 @@ verifyGPGSignature(const char *datafile, const void * sig, int count, char *resu result[0] = '\0'; while (fgets(buf, 1024, file)) { strcat(result, buf); - if (!strncasecmp("gpg: Can't check signature: Public key not found", buf, 48)) { + if (!xstrncasecmp("gpg: Can't check signature: Public key not found", buf, 48)) { res = RPMSIG_NOKEY; } } |