diff options
author | jbj <devnull@localhost> | 1999-11-10 22:09:49 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 1999-11-10 22:09:49 +0000 |
commit | e0b1d0be3607ef673555ca17078bfff6f854267e (patch) | |
tree | 828541f8c102a7b9adddc19b0cf623cdedc0fb44 /lib | |
parent | aeab1e959d1fb383a0ff21924bff0edd01404fab (diff) | |
download | librpm-tizen-e0b1d0be3607ef673555ca17078bfff6f854267e.tar.gz librpm-tizen-e0b1d0be3607ef673555ca17078bfff6f854267e.tar.bz2 librpm-tizen-e0b1d0be3607ef673555ca17078bfff6f854267e.zip |
Swap 2nd and 3rd arg to Fread/Fwrite to preserve read/write type return.
Use Fstrerror to retrieve fd->syserrno.
Make ftpFileDoneNeeded per-fd rather than per-url.
Make data fd unique rather than per-url.
Use appropriate protocol commands for ufdio writing.
CVS patchset: 3421
CVS date: 1999/11/10 22:09:49
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cpio.c | 12 | ||||
-rw-r--r-- | lib/falloc.c | 2 | ||||
-rw-r--r-- | lib/ftp.c | 44 | ||||
-rw-r--r-- | lib/header.c | 22 | ||||
-rw-r--r-- | lib/macro.c | 2 | ||||
-rw-r--r-- | lib/misc.c | 77 | ||||
-rw-r--r-- | lib/oldheader.c | 12 | ||||
-rw-r--r-- | lib/query.c | 8 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 22 | ||||
-rw-r--r-- | lib/rpmdb.c | 4 | ||||
-rw-r--r-- | lib/rpminstall.c | 44 | ||||
-rw-r--r-- | lib/rpmio.h | 8 | ||||
-rw-r--r-- | lib/rpmlead.c | 4 | ||||
-rw-r--r-- | lib/rpmrc.c | 14 | ||||
-rw-r--r-- | lib/rpmurl.h | 5 | ||||
-rw-r--r-- | lib/signature.c | 8 | ||||
-rw-r--r-- | lib/tufdio.c | 4 | ||||
-rw-r--r-- | lib/uninstall.c | 4 | ||||
-rw-r--r-- | lib/url.c | 37 |
19 files changed, 182 insertions, 151 deletions
diff --git a/lib/cpio.c b/lib/cpio.c index f45ce5f4e..7d0a3a914 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -62,7 +62,7 @@ static inline off_t saferead(FD_t cfd, /*@out@*/void * vbuf, size_t amount) while (amount > 0) { size_t nb; - nb = Fread(buf, amount, 1, cfd); + nb = Fread(buf, sizeof(buf[0]), amount, cfd); if (nb <= 0) return nb; rc += nb; @@ -99,7 +99,7 @@ static inline off_t safewrite(FD_t cfd, const void * vbuf, size_t amount) while (amount > 0) { size_t nb; - nb = Fwrite(buf, amount, 1, cfd); + nb = Fwrite(buf, sizeof(buf[0]), amount, cfd); if (nb <= 0) return nb; rc += nb; @@ -315,7 +315,7 @@ static int expandRegular(FD_t cfd, struct cpioHeader * hdr, cpioCallback cb, void * cbData) { FD_t ofd; - char buf[8192]; + char buf[BUFSIZ]; int bytesRead; int left = hdr->size; int rc = 0; @@ -355,7 +355,7 @@ static int expandRegular(FD_t cfd, struct cpioHeader * hdr, break; } - if (Fwrite(buf, bytesRead, 1, ofd) != bytesRead) { + if (Fwrite(buf, sizeof(buf[0]), bytesRead, ofd) != bytesRead) { rc = CPIOERR_COPY_FAILED; break; } @@ -772,9 +772,9 @@ static int writeFile(FD_t cfd, struct stat sb, struct cpioFileMapping * map, } else #endif { - amount = Fread(b, + amount = Fread(b, sizeof(buf[0]), (sb.st_size > sizeof(buf) ? sizeof(buf) : sb.st_size), - 1, datafd); + datafd); if (amount <= 0) { olderrno = errno; Fclose(datafd); diff --git a/lib/falloc.c b/lib/falloc.c index 334edb0d9..d10bfc98b 100644 --- a/lib/falloc.c +++ b/lib/falloc.c @@ -56,7 +56,7 @@ FD_t fadOpen(const char * path, int flags, int perms) if (fadGetFileSize(fd) == 0) { newHdr.magic = FA_MAGIC; newHdr.firstFree = 0; - if (Fwrite(&newHdr, sizeof(newHdr), 1, fd) != sizeof(newHdr)) { + if (Fwrite(&newHdr, sizeof(char), sizeof(newHdr), fd) != sizeof(newHdr)) { Fclose(fd); return NULL; } @@ -81,6 +81,7 @@ static int checkResponse(urlinfo u, /*@out@*/ int *ecp, /*@out@*/ char ** str) URLSANE(u); buf = u->buf; bufAlloced = u->bufAlloced; + *buf = '\0'; errorCode[0] = '\0'; @@ -91,6 +92,7 @@ static int checkResponse(urlinfo u, /*@out@*/ int *ecp, /*@out@*/ char ** str) * Read next line from server. */ se = buf + bufLength; + *se = '\0'; rc = fdRdline(u->ctrl, se, (bufAlloced - bufLength)); if (rc < 0) { ec = FTPERR_BAD_SERVER_RESPONSE; @@ -371,13 +373,6 @@ reopen: if (rc < 0) goto errxit; -#ifdef DYING - /* checkResponse() assumes the socket is nonblocking */ - if (fcntl(fdio->fileno(u->ctrl), F_SETFL, O_NONBLOCK)) { - rc = FTPERR_FAILED_CONNECT; - goto errxit; - } -#endif u->ctrl = fdLink(u->ctrl, "open ctrl (httpOpen)"); } @@ -478,14 +473,6 @@ int ftpOpen(urlinfo u) goto errxit; } -#ifdef DYING - /* checkResponse() assumes the socket is nonblocking */ - if (fcntl(fdio->fileno(u->ctrl), F_SETFL, O_NONBLOCK)) { - rc = FTPERR_FAILED_CONNECT; - goto errxit; - } -#endif - if ((rc = ftpCheckResponse(u, NULL))) goto errxit; @@ -507,15 +494,17 @@ errxit: return rc; } -int ftpFileDone(urlinfo u) +int ftpFileDone(urlinfo u, FD_t fd) { int rc = 0; + int ftpFileDoneNeeded; URLSANE(u); - assert(u->ftpFileDoneNeeded); + ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(fd); + assert(ftpFileDoneNeeded); - if (u->ftpFileDoneNeeded) { - u->ftpFileDoneNeeded = 0; + if (ftpFileDoneNeeded) { + fdSetFtpFileDoneNeeded(fd, 0); u->ctrl = fdFree(u->ctrl, "open data (ftpFileDone)"); u->ctrl = fdFree(u->ctrl, "grab data (ftpFileDone)"); rc = ftpCheckResponse(u, NULL); @@ -523,33 +512,28 @@ int ftpFileDone(urlinfo u) return rc; } -int ftpFileDesc(urlinfo u, const char *cmd) +int ftpFileDesc(urlinfo u, const char *cmd, FD_t fd) { struct sockaddr_in dataAddress; int cmdlen; char * passReply; char * chptr; int rc; - FD_t fd; + int ftpFileDoneNeeded; URLSANE(u); if (cmd == NULL) return FTPERR_UNKNOWN; /* XXX W2DO? */ cmdlen = strlen(cmd); - fd = u->data; -#ifdef DYING /* * XXX When ftpFileDesc() is called, there may be a lurking * XXX transfer complete message (if ftpFileDone() was not - * XXX called to clear that message). Clear that message now. + * XXX called to clear that message). Detect that condition now. */ - if (u->ftpFileDoneNeeded) - rc = ftpFileDone(u); /* XXX return code ignored */ -#else - assert(u->ftpFileDoneNeeded == 0); -#endif + ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(fd); + assert(ftpFileDoneNeeded == 0); /* * Get the ftp version of the Content-Length. @@ -656,7 +640,7 @@ int ftpFileDesc(urlinfo u, const char *cmd) goto errxit; } - u->ftpFileDoneNeeded = 1; + fdSetFtpFileDoneNeeded(fd, 1); u->ctrl = fdLink(u->ctrl, "grab data (ftpFileDesc)"); u->ctrl = fdLink(u->ctrl, "open data (ftpFileDesc)"); return 0; diff --git a/lib/header.c b/lib/header.c index 27893745e..7b0558004 100644 --- a/lib/header.c +++ b/lib/header.c @@ -483,20 +483,20 @@ int headerWrite(FD_t fd, Header h, int magicp) p = doHeaderUnload(h, &length); if (magicp) { - nb = Fwrite(header_magic, sizeof(header_magic), 1, fd); + nb = Fwrite(header_magic, sizeof(char), sizeof(header_magic), fd); if (nb != sizeof(header_magic)) { free(p); return 1; } l = htonl(0); - nb = Fwrite(&l, sizeof(l), 1, fd); + nb = Fwrite(&l, sizeof(char), sizeof(l), fd); if (nb != sizeof(l)) { free(p); return 1; } } - nb = Fwrite(p, length, 1, fd); + nb = Fwrite(p, sizeof(char), length, fd); if (nb != length) { free(p); return 1; @@ -572,20 +572,20 @@ int headerGzWrite(FD_t fd, Header h, int magicp) p = doHeaderUnload(h, &length); if (magicp) { - nb = Fwrite(header_magic, sizeof(header_magic), 1, fd); + nb = Fwrite(header_magic, sizeof(char), sizeof(header_magic), fd); if (nb != sizeof(header_magic)) { free(p); return 1; } l = htonl(0); - nb = Fwrite(&l, sizeof(l), 1, fd); + nb = Fwrite(&l, sizeof(char), sizeof(l), fd); if (nb != sizeof(l)) { free(p); return 1; } } - nb = Fwrite(p, length, 1, fd); + nb = Fwrite(p, sizeof(char), length, fd); if (nb != length) { free(p); return 1; @@ -606,24 +606,24 @@ Header headerGzRead(FD_t fd, int magicp) int totalSize; if (magicp == HEADER_MAGIC_YES) { - if (Fread(&magic, sizeof(magic), 1, fd) != sizeof(magic)) + if (Fread(&magic, sizeof(char), sizeof(magic), fd) != sizeof(magic)) return NULL; if (memcmp(&magic, header_magic, sizeof(magic))) { return NULL; } - if (Fread(&reserved, sizeof(reserved), 1, fd) != sizeof(reserved)) + if (Fread(&reserved, sizeof(char), sizeof(reserved), fd) != sizeof(reserved)) return NULL; } /* First read the index length (count of index entries) */ - if (Fread(&il, sizeof(il), 1, fd) != sizeof(il)) + if (Fread(&il, sizeof(char), sizeof(il), fd) != sizeof(il)) return NULL; il = ntohl(il); /* Then read the data length (number of bytes) */ - if (Fread(&dl, sizeof(dl), 1, fd) != sizeof(dl)) + if (Fread(&dl, sizeof(char), sizeof(dl), fd) != sizeof(dl)) return NULL; dl = ntohl(dl); @@ -636,7 +636,7 @@ Header headerGzRead(FD_t fd, int magicp) *p++ = htonl(dl); totalSize -= sizeof(int_32) + sizeof(int_32); - if (Fread(p, totalSize, 1, fd) != totalSize) + if (Fread(p, sizeof(char), totalSize, fd) != totalSize) return NULL; h = headerLoad(block); diff --git a/lib/macro.c b/lib/macro.c index 5b9320ff2..72129603d 100644 --- a/lib/macro.c +++ b/lib/macro.c @@ -1349,7 +1349,7 @@ int isCompressed(const char *file, int *compressed) rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno)); return 1; } - nb = Fread(magic, sizeof(magic), 1, fd); + nb = Fread(magic, sizeof(char), sizeof(magic), fd); rderrno = errno; Fclose(fd); diff --git a/lib/misc.c b/lib/misc.c index 39a7a4482..03f411afe 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -57,7 +57,7 @@ int rpmfileexists(const char * filespec) { filespec = strchr(filespec, '/'); /*@fallthrough@*/ case URL_IS_UNKNOWN: - if (stat(filespec, &buf)) { + if (Stat(filespec, &buf)) { switch(errno) { case ENOENT: case EINVAL: @@ -65,8 +65,8 @@ int rpmfileexists(const char * filespec) { } } break; - case URL_IS_DASH: case URL_IS_FTP: + case URL_IS_DASH: case URL_IS_HTTP: default: return 0; @@ -356,63 +356,88 @@ char * gidToGname(gid_t gid) { } int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) { - const char * fnpath, * fn; + const char * tfn; FD_t fd; int ran; struct stat sb, sb2; if (!prefix) prefix = ""; - fnpath = NULL; + tfn = NULL; + /* XXX should probably use mktemp here */ srand(time(NULL)); ran = rand() % 100000; /* maybe this should use link/stat? */ do { - char tfn[32]; - sprintf(tfn, "rpm-tmp.%d", ran++); - if (fnpath) xfree(fnpath); - fnpath = rpmGetPath(prefix, "%{_tmppath}/", tfn, NULL); - - switch (urlIsURL(fnpath)) { + char tfnbuf[64]; + const char * tempfn; +#ifndef NOTYET + sprintf(tfnbuf, "rpm-tmp.%d", ran++); + if (tfn) xfree(tfn); + tfn = tempfn = rpmGetPath("%{_tmppath}/", tfnbuf, NULL); +#else + strcpy(tfnbuf, "rpm-tmp.XXXXXX"); + if (tfn) xfree(tfn); + tfn = tempfn = rpmGetPath("%{_tmppath}/", mktemp(tfnbuf), NULL); +#endif + + switch (urlIsURL(tempfn)) { case URL_IS_PATH: - fn = fnpath + sizeof("file://") - 1; - fn = strchr(fn, '/'); - break; + tfn += sizeof("file://") - 1; + tfn = strchr(tfn, '/'); + /*@fallthrough@*/ case URL_IS_UNKNOWN: - fn = fnpath; + if (prefix && prefix[strlen(prefix) - 1] == '/') + while (*tfn == '/') tfn++; + tfn = rpmGetPath( (prefix ? prefix : ""), tfn, NULL); + xfree(tempfn); break; + case URL_IS_FTP: + case URL_IS_HTTP: + case URL_IS_DASH: default: + xfree(tempfn); return 1; + /*@notreached@*/ } - fd = fdio->open(fn, O_CREAT | O_RDWR | O_EXCL, 0700); - } while (Ferror(fd) && errno == EEXIST); - - if (!stat(fn, &sb) && S_ISLNK(sb.st_mode)) { - rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fnpath); - xfree(fnpath); +#ifdef DYING + fd = fdio->open(tfn, O_CREAT | O_RDWR | O_EXCL, 0700); +#else + fd = Fopen(tfn, "w+x.ufdio"); +fprintf(stderr, "*** mktemp %s fd %p: %s\n", tfnbuf, fd, strerror(errno)); +#endif + } while ((fd == NULL || Ferror(fd)) && errno == EEXIST); + + if (!Stat(tfn, &sb) && S_ISLNK(sb.st_mode)) { + rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); + xfree(tfn); return 1; } if (sb.st_nlink != 1) { - rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fnpath); - xfree(fnpath); + rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); + xfree(tfn); return 1; } +#ifndef NOTYET fstat(Fileno(fd), &sb2); +#else + Stat(tfn, &sb2); +#endif if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) { - rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fnpath); - xfree(fnpath); + rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); + xfree(tfn); return 1; } if (fnptr) - *fnptr = fnpath; + *fnptr = tfn; else - xfree(fnpath); + xfree(tfn); *fdptr = fd; return 0; diff --git a/lib/oldheader.c b/lib/oldheader.c index 92f41fb4c..42e6bbd80 100644 --- a/lib/oldheader.c +++ b/lib/oldheader.c @@ -45,7 +45,7 @@ char * oldhdrReadFromStream(FD_t fd, struct oldrpmHeader * header) { unsigned int groupLength; if (timedRead(fd, (char *)&lit, sizeof(lit)) != sizeof(lit)) { - return strerror(errno); + return Fstrerror(fd); } bytesRead = sizeof(lit); @@ -90,7 +90,7 @@ char * oldhdrReadFromStream(FD_t fd, struct oldrpmHeader * header) { if (timedRead(fd, header->group, groupLength) != groupLength) { oldhdrFree(header); - return strerror(errno); + return Fstrerror(fd); } header->group[groupLength] = '\0'; bytesRead += groupLength; @@ -109,7 +109,7 @@ char * oldhdrReadFromStream(FD_t fd, struct oldrpmHeader * header) { if (timedRead(fd, header->icon, header->iconLength) != header->iconLength) { oldhdrFree(header); - return strerror(errno); + return Fstrerror(fd); } bytesRead += header->iconLength; } else { @@ -119,21 +119,21 @@ char * oldhdrReadFromStream(FD_t fd, struct oldrpmHeader * header) { while (bytesRead < specOffset) { if (timedRead(fd, &ch, 1) != 1) { oldhdrFree(header); - return strerror(errno); + return Fstrerror(fd); } bytesRead++; } if (timedRead(fd, header->spec, header->specLength) != header->specLength) { oldhdrFree(header); - return strerror(errno); + return Fstrerror(fd); } bytesRead += header->specLength; while (bytesRead < archiveOffset) { if (timedRead(fd, &ch, 1) != 1) { oldhdrFree(header); - return strerror(errno); + return Fstrerror(fd); } bytesRead++; } diff --git a/lib/query.c b/lib/query.c index 79d42cc6f..17cad7bf9 100644 --- a/lib/query.c +++ b/lib/query.c @@ -458,13 +458,19 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, case RPMQV_RPM: { const char *myargv[2], **argv = myargv;; + /* XXX prepare for remglob */ argv[0] = arg; argv[1] = NULL; while ((arg = *argv++) != NULL) { FD_t fd = Fopen(arg, "r.ufdio"); if (Ferror(fd)) { /* XXX Fstrerror */ - fprintf(stderr, _("open of %s failed: %s\n"), arg,urlStrerror(arg)); + fprintf(stderr, _("open of %s failed: %s\n"), arg, +#ifndef NOTYET + urlStrerror(arg)); +#else + Fstrerror(fd)); +#endif Fclose(fd); retcode = 1; break; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index c4e39c9b3..36515b3c5 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -26,12 +26,15 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc) /* open a file and set *fdp */ if (*fdp == NULL && fnp && *fnp) { +#ifdef DYING mode_t mode = (flags & O_CREAT) ? 0644 : 0; fd = fdio->open(*fnp, flags, mode); +#else + fd = Fopen(*fnp, ((flags & O_RDONLY) ? "r.fdio" : "w.fdio")); +#endif if (Ferror(fd)) { - /* XXX Fstrerror */ fprintf(stderr, _("%s: open failed: %s\n"), *fnp, - strerror(errno)); + Fstrerror(fd)); return 1; } *fdp = fd; @@ -62,7 +65,7 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc) static int copyFile(FD_t *sfdp, const char **sfnp, FD_t *tfdp, const char **tfnp) { - unsigned char buffer[8192]; + unsigned char buffer[BUFSIZ]; ssize_t count; int rc = 1; @@ -71,15 +74,15 @@ static int copyFile(FD_t *sfdp, const char **sfnp, if (manageFile(tfdp, tfnp, O_WRONLY|O_CREAT|O_TRUNC, 0)) goto exit; - while ((count = Fread(buffer, sizeof(buffer), 1, *sfdp)) > 0) { - if (Fwrite(buffer, count, 1, *tfdp) < 0) { + 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, - strerror(errno)); + Fstrerror(*tfdp)); goto exit; } } if (count < 0) { - fprintf(stderr, _("%s: Fread failed: %s\n"), *sfnp, strerror(errno)); + fprintf(stderr, _("%s: Fread failed: %s\n"), *sfnp, Fstrerror(*sfdp)); goto exit; } @@ -167,12 +170,13 @@ int rpmReSign(int add, char *passPhrase, const char **argv) lead.signature_type = RPMSIG_HEADERSIG; if (writeLead(ofd, &lead)) { fprintf(stderr, _("%s: writeLead failed: %s\n"), trpm, - strerror(errno)); + Fstrerror(ofd)); goto exit; } if (rpmWriteSignature(ofd, sig)) { - fprintf(stderr, _("%s: rpmWriteSignature failed\n"), trpm); + fprintf(stderr, _("%s: rpmWriteSignature failed: %s\n"), trpm, + Fstrerror(ofd)); goto exit; } diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 090a2e74f..08436b750 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -152,8 +152,8 @@ int openDatabase(const char * prefix, const char * dbpath, rpmdb *rpmdbp, int mo if (!justcheck || !rpmfileexists(filename)) { db->pkgs = fadOpen(filename, mode, perms); if (Ferror(db->pkgs)) { - /* XXX Fstrerror */ - rpmError(RPMERR_DBOPEN, _("failed to open %s\n"), filename); + rpmError(RPMERR_DBOPEN, _("failed to open %s: %s\n"), filename, + Fstrerror(db->pkgs)); return 1; } diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 567847e4b..4dba461f6 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -4,16 +4,6 @@ #include <rpmmacro.h> #include <rpmurl.h> -#ifdef DYING -#include "build/rpmbuild.h" - -static void printHash(const unsigned long amount, const unsigned long total); -static void * showProgress(const Header h, const rpmCallbackType what, - const unsigned long amount, - const unsigned long total, - const void * pkgKey, void * data); -#endif - static int hashesPrinted = 0; static void printHash(const unsigned long amount, const unsigned long total) { @@ -152,10 +142,26 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, fprintf(stdout, _("Retrieving %s\n"), *filename); { char tfnbuf[64]; + const char * tempfn; strcpy(tfnbuf, "rpm-xfer.XXXXXX"); /* XXX watchout for rootdir = NULL */ - tfn = rpmGetPath( (rootdir ? rootdir : ""), - "%{_tmppath}/", mktemp(tfnbuf), NULL); + tfn = tempfn = rpmGetPath("%{_tmppath}/", mktemp(tfnbuf), NULL); + switch(urlIsURL(tempfn)) { + case URL_IS_FTP: + case URL_IS_HTTP: + case URL_IS_DASH: + break; + case URL_IS_PATH: + tfn += sizeof("file://") - 1; + tfn = strchr(tfn, '/'); + /*@fallthrough@*/ + case URL_IS_UNKNOWN: + if (rootdir && rootdir[strlen(rootdir) - 1] == '/') + while (*tfn == '/') tfn++; + tfn = rpmGetPath( (rootdir ? rootdir : ""), tfn, NULL); + xfree(tempfn); + break; + } } rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn); @@ -188,8 +194,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, for (filename = packages; *filename; filename++) { fd = Fopen(*filename, "r.ufdio"); if (Ferror(fd)) { - /* XXX Fstrerror */ - rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), *filename); + rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), *filename, + Fstrerror(fd)); numFailed++; packages[i] = NULL; continue; @@ -328,11 +334,10 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, if (numSourcePackages && !stopInstall) { for (i = 0; i < numSourcePackages; i++) { - fd = Fopen(sourcePackages[i], "r.fdio"); + fd = Fopen(sourcePackages[i], "r.ufdio"); if (Ferror(fd)) { - /* XXX Fstrerror */ - rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), - sourcePackages[i]); + rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), + sourcePackages[i], Fstrerror(fd)); continue; } @@ -458,8 +463,7 @@ int rpmInstallSource(const char * rootdir, const char * arg, const char ** specF fd = Fopen(arg, "r.ufdio"); if (Ferror(fd)) { - /* XXX Fstrerror */ - rpmMessage(RPMMESS_ERROR, _("cannot open %s\n"), arg); + rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd)); Fclose(fd); return 1; } diff --git a/lib/rpmio.h b/lib/rpmio.h index 5f1b3c306..de836be88 100644 --- a/lib/rpmio.h +++ b/lib/rpmio.h @@ -84,9 +84,13 @@ void fdSetIoCookie(FD_t fd, FDIO_t iop); int fdGetRdTimeoutSecs(FD_t fd); +int fdGetFtpFileDoneNeeded(FD_t fd); +void fdSetFtpFileDoneNeeded(FD_t fd, int ftpFileDoneNeeded); + long int fdGetCpioPos(FD_t fd); -extern /*@null@*/ FD_t fdDup(int fdno); void fdSetCpioPos(FD_t fd, long int cpioPos); + +extern /*@null@*/ FD_t fdDup(int fdno); #ifdef UNUSED extern /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode); #endif @@ -117,7 +121,7 @@ extern /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode); /*@observer@*/ const char * urlStrerror(const char * url); int httpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd); -int ftpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd); +int ftpGetFile( /*@killref@*/ FD_t sfd, FD_t tfd, const char * ftpcmd); const char *const ftpStrerror(int errorNumber); #if 0 diff --git a/lib/rpmlead.c b/lib/rpmlead.c index e1a970679..9ec3f6d75 100644 --- a/lib/rpmlead.c +++ b/lib/rpmlead.c @@ -35,7 +35,7 @@ int writeLead(FD_t fd, struct rpmlead *lead) l.osnum = htons(l.osnum); l.signature_type = htons(l.signature_type); - if (Fwrite(&l, sizeof(l), 1, fd) < 0) { + if (Fwrite(&l, sizeof(char), sizeof(l), fd) < 0) { return 1; } @@ -45,7 +45,7 @@ int writeLead(FD_t fd, struct rpmlead *lead) int readLead(FD_t fd, struct rpmlead *lead) { if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) { - rpmError(RPMERR_READERROR, _("read failed: %s (%d)"), strerror(errno), + rpmError(RPMERR_READERROR, _("read failed: %s (%d)"), Fstrerror(fd), errno); return 1; } diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 1c485a538..d8d4fbb9d 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -553,9 +553,8 @@ int rpmReadRC(const char * rcfiles) /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */ if (rcfiles == defrcfiles && myrcfiles != r) continue; - /* XXX Fstrerror */ rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."), - fn, strerror(errno)); + fn, Fstrerror(fd)); rc = 1; break; } else { @@ -596,10 +595,10 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * filename) nb = (sb.st_size > 0 ? sb.st_size : 8*BUFSIZ); next = alloca(nb + 2); next[0] = '\0'; - rc = Fread(next, nb, 1, fd); + rc = Fread(next, sizeof(*next), nb, fd); if (Ferror(fd) || (sb.st_size > 0 && rc != nb)) { /* XXX Feof(fd) */ rpmError(RPMERR_RPMRC, _("Failed to read %s: %s."), filename, - strerror(errno)); + Fstrerror(fd)); rc = 1; } else rc = 0; @@ -674,9 +673,8 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * filename) fdinc = Fopen(fn, "r.ufdio"); if (fdinc == NULL || Ferror(fdinc)) { - /* XXX Fstrerror */ - rpmError(RPMERR_RPMRC, _("cannot open %s at %s:%d"), - fn, filename, linenum); + rpmError(RPMERR_RPMRC, _("cannot open %s at %s:%d: %s"), + fn, filename, linenum, Fstrerror(fdinc)); rc = 1; } else { rc = doReadRC(fdinc, fn); @@ -853,7 +851,7 @@ static void defaultMachine(const char ** arch, const char ** os) { if (!Ferror(fd)) { chptr = (char *) xcalloc(1, 256); if (chptr != NULL) { - int irelid = Fread(chptr, 256, 1, fd); + int irelid = Fread(chptr, sizeof(*chptr), 256, fd); Fclose(fd); /* example: "112393 RELEASE 020200 Version 01 OS" */ if (irelid > 0) { diff --git a/lib/rpmurl.h b/lib/rpmurl.h index ff09868cb..c021205c7 100644 --- a/lib/rpmurl.h +++ b/lib/rpmurl.h @@ -51,7 +51,6 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct urlinfo { FD_t data; /* per-xfer data channel */ int bufAlloced; /* sizeof I/O buffer */ char *buf; /* I/O buffer */ - int ftpFileDoneNeeded; int openError; /* Type of open failure */ int httpVersion; int httpHasRange; @@ -69,8 +68,8 @@ int ftpCommand(urlinfo u, ...); int httpOpen(urlinfo u, const char * httpcmd); int ftpOpen(urlinfo u); -int ftpFileDone(urlinfo u); -int ftpFileDesc(urlinfo u, const char * cmd); +int ftpFileDone(urlinfo u, FD_t fd); +int ftpFileDesc(urlinfo u, const char * cmd, FD_t fd); urlinfo urlLink(urlinfo u, const char * msg); urlinfo XurlLink(urlinfo u, const char * msg, const char * file, unsigned line); diff --git a/lib/signature.c b/lib/signature.c index ca6b2e8fb..8005e400a 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -203,7 +203,7 @@ int rpmWriteSignature(FD_t fd, Header header) rpmMessage(RPMMESS_DEBUG, _("Signature size: %d\n"), sigSize); rpmMessage(RPMMESS_DEBUG, _("Signature pad : %d\n"), pad); memset(buf, 0, pad); - if (Fwrite(buf, pad, 1, fd) != pad) + if (Fwrite(buf, sizeof(buf[0]), pad, fd) != pad) rc = 1; } return rc; @@ -480,7 +480,7 @@ static int verifyPGPSignature(const char *datafile, void *sig, int pid, status, outpipe[2]; FD_t sfd; char *sigfile; - unsigned char buf[8192]; + unsigned char buf[BUFSIZ]; FILE *file; int res = RPMSIG_OK; const char *path; @@ -507,7 +507,7 @@ static int verifyPGPSignature(const char *datafile, void *sig, xfree(tmppath); } sfd = Fopen(sigfile, "w.fdio"); - (void)Fwrite(sig, count, 1, sfd); + (void)Fwrite(sig, sizeof(char), count, sfd); Fclose(sfd); /* Now run PGP */ @@ -602,7 +602,7 @@ static int verifyGPGSignature(const char *datafile, void *sig, xfree(tmppath); } sfd = Fopen(sigfile, "w.fdio"); - (void)Fwrite(sig, count, 1, sfd); + (void)Fwrite(sig, sizeof(char), count, sfd); Fclose(sfd); /* Now run GPG */ diff --git a/lib/tufdio.c b/lib/tufdio.c index ab2363afe..8562513ca 100644 --- a/lib/tufdio.c +++ b/lib/tufdio.c @@ -50,13 +50,13 @@ static int doFIO(const char *ofn, const char *rfmode, const char *wfmode) if ((fd = Fopen(ofn, wfmode)) == NULL) warn("Fopen: write %s (%s) %s\n", wfmode, rfmode, ofn); - else if ((rc = Fwrite(ofn, 1, strlen(ofn), fd)) != strlen(ofn)) + else if ((rc = Fwrite(ofn, sizeof(ofn[0]), strlen(ofn), fd)) != strlen(ofn)) warn("Fwrite: write %s (%s) %s\n", wfmode, rfmode, ofn); else if ((rc = Fclose(fd)) != 0) warn("Fclose: write %s (%s) %s\n", wfmode, rfmode, ofn); else if ((fd = Fopen(ofn, rfmode)) == NULL) warn("Fopen: read %s (%s) %s\n", rfmode, wfmode, ofn); - else if ((rc = Fread(buf, 1, sizeof(buf), fd)) != strlen(ofn)) + else if ((rc = Fread(buf, sizeof(buf[0]), sizeof(buf), fd)) != strlen(ofn)) warn("Fread: read %s (%s) %s\n", rfmode, wfmode, ofn); else if ((rc = Fclose(fd)) != 0) warn("Fclose: read %s (%s) %s\n", rfmode, wfmode, ofn); diff --git a/lib/uninstall.c b/lib/uninstall.c index c0ca95fce..18e8af119 100644 --- a/lib/uninstall.c +++ b/lib/uninstall.c @@ -289,9 +289,9 @@ static int runScript(Header h, const char * root, int progArgc, const char ** pr if (rpmIsDebug() && (!strcmp(argv[0], "/bin/sh") || !strcmp(argv[0], "/bin/bash"))) - (void)Fwrite("set -x\n", 7, 1, fd); + (void)Fwrite("set -x\n", sizeof(char), 7, fd); - (void)Fwrite(script, strlen(script), 1, fd); + (void)Fwrite(script, sizeof(script[0]), strlen(script), fd); Fclose(fd); argv[argc++] = fn + strlen(root); @@ -49,7 +49,6 @@ urlinfo XurlNew(const char *msg, const char *file, unsigned line) u->data = NULL; u->bufAlloced = 0; u->buf = NULL; - u->ftpFileDoneNeeded = 0; u->httpHasRange = 1; u->httpContentLength = 0; u->httpPersist = u->httpVersion = 0; @@ -69,16 +68,16 @@ DBGREFS(0, (stderr, "--> url %p -- %d %s at %s:%u\n", u, u->nrefs, msg, file, li fdio->close(u->ctrl); u->ctrl = fdio->deref(u->ctrl, "persist ctrl (urlFree)", file, line); if (u->ctrl) - fprintf(stderr, "warning: ctrl nrefs != 0 (%s %s)\n", - u->host, u->service); + fprintf(stderr, _("warning: u %p ctrl nrefs != 0 (%s %s)\n"), + u, u->host, u->service); } if (u->data) { if (fdio->fileno(u->data) >= 0) fdio->close(u->data); u->data = fdio->deref(u->data, "persist data (urlFree)", file, line); if (u->data) - fprintf(stderr, "warning: data nrefs != 0 (%s %s)\n", - u->host, u->service); + fprintf(stderr, _("warning: data nrefs != 0 (%s %s)\n"), + u, u->host, u->service); } if (u->buf) { free(u->buf); @@ -105,8 +104,9 @@ void urlFreeCache(void) if (uCache[i] == NULL) continue; uCache[i] = urlFree(uCache[i], "uCache"); if (uCache[i]) - fprintf(stderr, "warning: nrefs(%d) != 1 (%s %s)\n", uCache[i]->nrefs, - uCache[i]->host, uCache[i]->service); + fprintf(stderr, _("warning: uCache[%d] %p nrefs(%d) != 1 (%s %s)\n"), + i, uCache[i], uCache[i]->nrefs, + uCache[i]->host, uCache[i]->service); } if (uCache) free(uCache); @@ -400,8 +400,7 @@ int urlGetFile(const char * url, const char * dest) { sfd = Fopen(url, "r.ufdio"); if (sfd == NULL || Ferror(sfd)) { - /* XXX Fstrerror */ - rpmMessage(RPMMESS_DEBUG, _("failed to open %s\n"), url); + rpmMessage(RPMMESS_DEBUG, _("failed to open %s: %s\n"), url, Fstrerror(sfd)); Fclose(sfd); return FTPERR_UNKNOWN; } @@ -419,33 +418,41 @@ int urlGetFile(const char * url, const char * dest) { sfu = NULL; } - tfd = Fopen(dest, "w.fdio"); + tfd = Fopen(dest, "w.ufdio"); +if (_url_debug) +fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, tfd, dest); if (Ferror(tfd)) { /* XXX Fstrerror */ - rpmMessage(RPMMESS_DEBUG, _("failed to create %s\n"), dest); - Fclose(tfd); - Fclose(sfd); + rpmMessage(RPMMESS_DEBUG, _("failed to create %s: %s\n"), dest, Fstrerror(tfd)); + if (tfd) + Fclose(tfd); + if (sfd) + Fclose(sfd); return FTPERR_UNKNOWN; } switch (urlIsURL(url)) { case URL_IS_FTP: - if ((rc = ftpGetFile(sfd, tfd))) { +#ifdef DYING + if ((rc = ftpGetFile(sfd, tfd, "RETR"))) { unlink(dest); + /* XXX FIXME: sfd possibly closed by copyData */ /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ; } /* XXX Fclose(sfd) done by copyData */ break; +#endif case URL_IS_HTTP: case URL_IS_PATH: case URL_IS_DASH: + case URL_IS_UNKNOWN: if ((rc = httpGetFile(sfd, tfd))) { unlink(dest); + /* XXX FIXME: sfd possibly closed by copyData */ /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ; } /* XXX Fclose(sfd) done by copyData */ break; - case URL_IS_UNKNOWN: default: rc = FTPERR_UNKNOWN; break; |