Make fdFileno() static, use Fileno()/Ferror() analogues throughout.

Make ufdClose() static, use Fclose() with ufdio cookie throughout.
rpm.c: Clean urlinfoCache and rpmBuildArgs leaks.
url.c: urlIsURL() should be here, not in rpmio.c.
url.c: Preserve FD_t abstraction by creating ufdGetUrlinfo().
url.c: Create freeUrlinfoCache().
rpmio.c: Create ufdio cookie.

CVS patchset: 3407
CVS date: 1999/10/30 16:43:29
This commit is contained in:
jbj 1999-10-30 16:43:29 +00:00
parent 533991efdb
commit 2b84d36c2e
34 changed files with 619 additions and 536 deletions

View File

@ -59,7 +59,8 @@ static int isSpecFile(const char *specfile)
int count; int count;
int checking; int checking;
if (fdFileno((fd = ufdOpen(specfile, O_RDONLY, 0))) < 0) { fd = ufdOpen(specfile, O_RDONLY, 0);
if (Ferror(fd)) {
/* XXX Fstrerror */ /* XXX Fstrerror */
fprintf(stderr, _("Unable to open spec file: %s\n"), specfile); fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
return 0; return 0;

View File

@ -84,7 +84,7 @@ int doScript(Spec spec, int what, const char *name, StringBuf sb, int test)
return RPMERR_SCRIPT; return RPMERR_SCRIPT;
} }
#ifdef HAVE_FCHMOD #ifdef HAVE_FCHMOD
(void)fchmod(fdFileno(fd), 0600); (void)fchmod(Fileno(fd), 0600);
#endif #endif
f = fdFdopen(fd, "w"); f = fdFdopen(fd, "w");

View File

@ -183,7 +183,9 @@ int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead, Header *sig
int rc; int rc;
if (fileName != NULL) { if (fileName != NULL) {
if (fdFileno(fdi = fdOpen(fileName, O_RDONLY, 0644)) < 0) { fdi = fdOpen(fileName, O_RDONLY, 0644);
if (Ferror(fdi)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"), fileName, rpmError(RPMERR_BADMAGIC, _("readRPM: open %s: %s\n"), fileName,
strerror(errno)); strerror(errno));
return RPMERR_BADMAGIC; return RPMERR_BADMAGIC;
@ -249,7 +251,7 @@ int writeRPM(Header h, const char *fileName, int type,
Header sig; Header sig;
struct rpmlead lead; struct rpmlead lead;
if (fdFileno(csa->cpioFdIn) < 0) { if (Fileno(csa->cpioFdIn) < 0) {
csa->cpioArchiveSize = 0; csa->cpioArchiveSize = 0;
/* Add a bogus archive size to the Header */ /* Add a bogus archive size to the Header */
headerAddEntry(h, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE, headerAddEntry(h, RPMTAG_ARCHIVESIZE, RPM_INT32_TYPE,
@ -275,7 +277,7 @@ int writeRPM(Header h, const char *fileName, int type,
} else { /* Write the archive and get the size */ } else { /* Write the archive and get the size */
if (csa->cpioList != NULL) { if (csa->cpioList != NULL) {
rc = cpio_gzip(fd, csa); rc = cpio_gzip(fd, csa);
} else if (fdFileno(csa->cpioFdIn) >= 0) { } else if (Fileno(csa->cpioFdIn) >= 0) {
rc = cpio_copy(fd, csa); rc = cpio_copy(fd, csa);
} else { } else {
rpmError(RPMERR_CREATE, _("Bad CSA data")); rpmError(RPMERR_CREATE, _("Bad CSA data"));
@ -290,7 +292,7 @@ int writeRPM(Header h, const char *fileName, int type,
} }
/* Now set the real archive size in the Header */ /* Now set the real archive size in the Header */
if (fdFileno(csa->cpioFdIn) < 0) { if (Fileno(csa->cpioFdIn) < 0) {
headerModifyEntry(h, RPMTAG_ARCHIVESIZE, headerModifyEntry(h, RPMTAG_ARCHIVESIZE,
RPM_INT32_TYPE, &csa->cpioArchiveSize, 1); RPM_INT32_TYPE, &csa->cpioArchiveSize, 1);
} }
@ -310,7 +312,9 @@ int writeRPM(Header h, const char *fileName, int type,
} }
/* Open the output file */ /* Open the output file */
if (fdFileno(fd = fdOpen(fileName, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) { fd = fdOpen(fileName, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_CREATE, _("Could not open %s\n"), fileName); rpmError(RPMERR_CREATE, _("Could not open %s\n"), fileName);
unlink(sigtarget); unlink(sigtarget);
xfree(sigtarget); xfree(sigtarget);
@ -323,7 +327,7 @@ int writeRPM(Header h, const char *fileName, int type,
sprintf(buf, "%s-%s-%s", name, version, release); sprintf(buf, "%s-%s-%s", name, version, release);
} }
if (fdFileno(csa->cpioFdIn) < 0) { if (Fileno(csa->cpioFdIn) < 0) {
rpmGetArchInfo(NULL, &archnum); rpmGetArchInfo(NULL, &archnum);
rpmGetOsInfo(NULL, &osnum); rpmGetOsInfo(NULL, &osnum);
} else if (csa->lead != NULL) { /* XXX FIXME: exorcize lead/arch/os */ } else if (csa->lead != NULL) { /* XXX FIXME: exorcize lead/arch/os */
@ -412,7 +416,7 @@ static int cpio_bzip2(FD_t fdo, CSA_t *csa)
int rc; int rc;
const char *failedFile = NULL; const char *failedFile = NULL;
cfd = bzdFdopen(fdDup(fdFileno(fdo)), "w9"); cfd = bzdFdopen(fdDup(Fileno(fdo)), "w9");
rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL, rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL,
&csa->cpioArchiveSize, &failedFile); &csa->cpioArchiveSize, &failedFile);
if (rc) { if (rc) {
@ -435,7 +439,7 @@ static int cpio_gzip(FD_t fdo, CSA_t *csa)
int rc; int rc;
const char *failedFile = NULL; const char *failedFile = NULL;
cfd = gzdFdopen(fdDup(fdFileno(fdo)), "w9"); cfd = gzdFdopen(fdDup(Fileno(fdo)), "w9");
rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL, rc = cpioBuildArchive(cfd, csa->cpioList, csa->cpioCount, NULL, NULL,
&csa->cpioArchiveSize, &failedFile); &csa->cpioArchiveSize, &failedFile);
if (rc) { if (rc) {

View File

@ -246,7 +246,7 @@ static int readIcon(Header h, const char *file)
*icon = '\0'; *icon = '\0';
fd = fdOpen(fn, O_RDONLY, 0); fd = fdOpen(fn, O_RDONLY, 0);
/* XXX Fstrerror */ /* XXX Fstrerror */
/* XXX fdFileno check */ /* XXX Ferror check */
nb = Fread(icon, statbuf.st_size, 1, fd); nb = Fread(icon, statbuf.st_size, 1, fd);
Fclose(fd); Fclose(fd);
if (nb != statbuf.st_size) { if (nb != statbuf.st_size) {

View File

@ -343,7 +343,7 @@ static int expandRegular(FD_t cfd, struct cpioHeader * hdr,
} }
ofd = fdOpen(hdr->path, O_CREAT | O_WRONLY, 0); ofd = fdOpen(hdr->path, O_CREAT | O_WRONLY, 0);
if (fdFileno(ofd) < 0) if (Ferror(ofd))
return CPIOERR_OPEN_FAILED; return CPIOERR_OPEN_FAILED;
cbInfo.file = hdr->path; cbInfo.file = hdr->path;
@ -747,12 +747,13 @@ static int writeFile(FD_t cfd, struct stat sb, struct cpioFileMapping * map,
size_t nmapped; size_t nmapped;
#endif #endif
if (fdFileno(datafd = fdOpen(map->fsPath, O_RDONLY, 0)) < 0) datafd = fdOpen(map->fsPath, O_RDONLY, 0);
if (Ferror(datafd))
return CPIOERR_OPEN_FAILED; return CPIOERR_OPEN_FAILED;
#if HAVE_MMAP #if HAVE_MMAP
nmapped = 0; nmapped = 0;
mapped = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fdFileno(datafd), 0); mapped = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, Fileno(datafd), 0);
if (mapped != (void *)-1) { if (mapped != (void *)-1) {
b = (char *)mapped; b = (char *)mapped;
nmapped = sb.st_size; nmapped = sb.st_size;

View File

@ -55,7 +55,7 @@ int faClose(faFile fa) {
} }
int faFcntl(faFile fa, int op, void *lip) { int faFcntl(faFile fa, int op, void *lip) {
return fcntl(fdFileno(faFileno(fa)), op, lip); return fcntl(Fileno(faFileno(fa)), op, lip);
} }
static inline ssize_t faPRead(faFile fa, /*@out@*/void *buf, size_t count, off_t offset) { static inline ssize_t faPRead(faFile fa, /*@out@*/void *buf, size_t count, off_t offset) {
@ -80,7 +80,7 @@ faFile faOpen(const char * path, int flags, int perms)
return NULL; return NULL;
fa = ufdOpen(path, flags, perms); fa = ufdOpen(path, flags, perms);
if (fdFileno(faFileno(fa)) < 0) if (Ferror(faFileno(fa)))
/* XXX Fstrerror */ /* XXX Fstrerror */
return NULL; return NULL;

View File

@ -208,7 +208,7 @@ static int fssizesTag(Header h, int_32 * type, void ** data, int_32 * count,
numFiles = 0; numFiles = 0;
filenames = NULL; filenames = NULL;
} else { } else {
buildFileList(h, (char ***) &filenames, &numFiles); buildFileList(h, &filenames, &numFiles);
} }
if (rpmGetFilesystemList(NULL, count)) { if (rpmGetFilesystemList(NULL, count)) {
@ -339,10 +339,10 @@ static int filenamesTag(Header h, int_32 * type, /*@out@*/void ** data,
int_32 * count, int * freeData) { int_32 * count, int * freeData) {
*type = RPM_STRING_ARRAY_TYPE; *type = RPM_STRING_ARRAY_TYPE;
buildFileList(h, (char ***) data, count); buildFileList(h, (const char ***) data, count);
*freeData = 1; *freeData = 1;
*freeData = 0; *freeData = 0; /* XXX WTFO? */
return 0; return 0;
} }

View File

@ -442,12 +442,12 @@ static int copyData( /*@only@*/ FD_t sfd, FD_t tfd) {
while (1) { while (1) {
FD_ZERO(&emptySet); FD_ZERO(&emptySet);
FD_ZERO(&readSet); FD_ZERO(&readSet);
FD_SET(fdFileno(sfd), &readSet); FD_SET(Fileno(sfd), &readSet);
timeout.tv_sec = ftpTimeoutSecs; timeout.tv_sec = ftpTimeoutSecs;
timeout.tv_usec = 0; timeout.tv_usec = 0;
rc = select(fdFileno(sfd) + 1, &readSet, &emptySet, &emptySet, &timeout); rc = select(Fileno(sfd) + 1, &readSet, &emptySet, &emptySet, &timeout);
if (rc == 0) { if (rc == 0) {
rc = FTPERR_SERVER_TIMEOUT; rc = FTPERR_SERVER_TIMEOUT;
break; break;
@ -506,8 +506,8 @@ fprintf(stderr, "-> ABOR\n");
u->ftpControl = -1; u->ftpControl = -1;
return FTPERR_SERVER_IO_ERROR; return FTPERR_SERVER_IO_ERROR;
} }
if (fdFileno(fd) >= 0) { if (Fileno(fd) >= 0) {
while(read(fdFileno(fd), buf, sizeof(buf)) > 0) while(read(Fileno(fd), buf, sizeof(buf)) > 0)
; ;
} }
@ -518,7 +518,7 @@ fprintf(stderr, "-> ABOR\n");
rc = ftpCheckResponse(u, NULL); rc = ftpCheckResponse(u, NULL);
ftpTimeoutSecs = tosecs; ftpTimeoutSecs = tosecs;
if (fdFileno(fd) >= 0) if (Fileno(fd) >= 0)
Fclose(fd); Fclose(fd);
return 0; return 0;
} }
@ -597,15 +597,14 @@ fprintf(stderr, "-> PASV\n");
return FTPERR_PASSIVE_ERROR; return FTPERR_PASSIVE_ERROR;
fd->fd_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); fd->fd_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (fdFileno(fd) < 0) { if (Fileno(fd) < 0)
return FTPERR_FAILED_CONNECT; return FTPERR_FAILED_CONNECT;
}
retrCommand = alloca(strlen(remotename) + 20); retrCommand = alloca(strlen(remotename) + 20);
sprintf(retrCommand, "RETR %s\r\n", remotename); sprintf(retrCommand, "RETR %s\r\n", remotename);
i = strlen(retrCommand); i = strlen(retrCommand);
while (connect(fdFileno(fd), (struct sockaddr *) &dataAddress, while (connect(Fileno(fd), (struct sockaddr *) &dataAddress,
sizeof(dataAddress)) < 0) { sizeof(dataAddress)) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
@ -641,7 +640,7 @@ int ftpGetFile(FD_t sfd, FD_t tfd)
u = (urlinfo *)sfd->fd_url; u = (urlinfo *)sfd->fd_url;
/* XXX normally sfd = ufdOpen(...) and this code does not execute */ /* XXX normally sfd = ufdOpen(...) and this code does not execute */
if (fdFileno(sfd) < 0 && (rc = ftpGetFileDesc(sfd)) < 0) { if (Fileno(sfd) < 0 && (rc = ftpGetFileDesc(sfd)) < 0) {
Fclose(sfd); Fclose(sfd);
return rc; return rc;
} }

View File

@ -108,12 +108,12 @@ static int assembleFileList(Header h, /*@out@*/ struct fileMemory ** memPtr,
if (!headerIsEntry(h, RPMTAG_COMPFILELIST)) return 0; if (!headerIsEntry(h, RPMTAG_COMPFILELIST)) return 0;
buildFileList(h, (char ***) &mem->names, fileCountPtr); buildFileList(h, &mem->names, fileCountPtr);
if (headerIsEntry(h, RPMTAG_ORIGCOMPFILELIST)) { if (headerIsEntry(h, RPMTAG_ORIGCOMPFILELIST)) {
buildOrigFileList(h, (char ***) &mem->cpioNames, fileCountPtr); buildOrigFileList(h, &mem->cpioNames, fileCountPtr);
} else { } else {
buildFileList(h, (char ***) &mem->cpioNames, fileCountPtr); buildFileList(h, &mem->cpioNames, fileCountPtr);
} }
fileCount = *fileCountPtr; fileCount = *fileCountPtr;
@ -342,7 +342,7 @@ static int installArchive(FD_t fd, struct fileInfo * files,
(void)notify(h, RPMCALLBACK_INST_PROGRESS, 0, archiveSize, pkgKey, (void)notify(h, RPMCALLBACK_INST_PROGRESS, 0, archiveSize, pkgKey,
notifyData); notifyData);
cfd = gzdFdopen(fdDup(fdFileno(fd)), "r"); cfd = gzdFdopen(fdDup(Fileno(fd)), "r");
rc = cpioInstallArchive(cfd, map, mappedFiles, rc = cpioInstallArchive(cfd, map, mappedFiles,
((notify && archiveSize) || specFile) ? callback : NULL, ((notify && archiveSize) || specFile) ? callback : NULL,
&info, &failedFile); &info, &failedFile);

View File

@ -25,7 +25,7 @@
#define _(x) x #define _(x) x
#define xfree(_p) free((void *)_p) #define xfree(_p) free((void *)_p)
typedef int FD_t; typedef int FD_t;
#define fdFileno(_x) (_x) #define Ferror(_x) (_x)
#define fdOpen open #define fdOpen open
#define Fread(_b, _s, _n, _fd) read(_fd, _b, _s) #define Fread(_b, _s, _n, _fd) read(_fd, _b, _s)
#define Fclose(_fd) close(_fd) #define Fclose(_fd) close(_fd)
@ -1341,7 +1341,9 @@ int isCompressed(const char *file, int *compressed)
*compressed = COMPRESSED_NOT; *compressed = COMPRESSED_NOT;
if (fdFileno(fd = fdOpen(file, O_RDONLY, 0)) < 0) { fd = fdOpen(file, O_RDONLY, 0);
if (Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno)); rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno));
return 1; return 1;
} }

View File

@ -361,7 +361,7 @@ int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) {
if (fn) xfree(fn); if (fn) xfree(fn);
fn = rpmGetPath(prefix, "%{_tmppath}/", tfn, NULL); fn = rpmGetPath(prefix, "%{_tmppath}/", tfn, NULL);
fd = fdOpen(fn, O_CREAT | O_RDWR | O_EXCL, 0700); fd = fdOpen(fn, O_CREAT | O_RDWR | O_EXCL, 0700);
} while (fdFileno(fd) < 0 && errno == EEXIST); } while (Ferror(fd) && errno == EEXIST);
if (!stat(fn, &sb) && S_ISLNK(sb.st_mode)) { if (!stat(fn, &sb) && S_ISLNK(sb.st_mode)) {
rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fn); rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fn);
@ -375,7 +375,7 @@ int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) {
return 1; return 1;
} }
fstat(fdFileno(fd), &sb2); fstat(Fileno(fd), &sb2);
if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) { if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) {
rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fn); rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), fn);
xfree(fn); xfree(fn);
@ -412,7 +412,6 @@ void compressFilelist(Header h) {
const char ** baseNames; const char ** baseNames;
int fileCount; int fileCount;
int i; int i;
char * tail;
int lastDir = -1; int lastDir = -1;
int lastLen = -1; int lastLen = -1;
@ -465,7 +464,7 @@ void compressFilelist(Header h) {
/* this is pretty straight-forward. The only thing that even resembles a trick /* this is pretty straight-forward. The only thing that even resembles a trick
is getting all of this into a single xmalloc'd block */ is getting all of this into a single xmalloc'd block */
static void doBuildFileList(Header h, /*@out@*/ char *** fileListPtr, static void doBuildFileList(Header h, /*@out@*/ const char *** fileListPtr,
/*@out@*/ int * fileCountPtr, int baseNameTag, /*@out@*/ int * fileCountPtr, int baseNameTag,
int dirListTag, int dirIndexesTag) { int dirListTag, int dirIndexesTag) {
int * dirList; int * dirList;
@ -508,12 +507,14 @@ static void doBuildFileList(Header h, /*@out@*/ char *** fileListPtr,
free(dirs); free(dirs);
} }
void buildFileList(Header h, char *** fileListPtr, int * fileCountPtr) { void buildFileList(Header h, const char *** fileListPtr, int * fileCountPtr)
{
doBuildFileList(h, fileListPtr, fileCountPtr, RPMTAG_COMPFILELIST, doBuildFileList(h, fileListPtr, fileCountPtr, RPMTAG_COMPFILELIST,
RPMTAG_COMPDIRLIST, RPMTAG_COMPFILEDIRS); RPMTAG_COMPDIRLIST, RPMTAG_COMPFILEDIRS);
} }
void buildOrigFileList(Header h, char *** fileListPtr, int * fileCountPtr) { void buildOrigFileList(Header h, const char *** fileListPtr, int * fileCountPtr)
{
doBuildFileList(h, fileListPtr, fileCountPtr, RPMTAG_ORIGCOMPFILELIST, doBuildFileList(h, fileListPtr, fileCountPtr, RPMTAG_ORIGCOMPFILELIST,
RPMTAG_ORIGCOMPDIRLIST, RPMTAG_ORIGCOMPFILEDIRS); RPMTAG_ORIGCOMPDIRLIST, RPMTAG_ORIGCOMPFILEDIRS);
} }

View File

@ -36,9 +36,9 @@ int makeTempFile(const char * prefix, /*@out@*/ const char ** fnptr,
/*@out@*/ FD_t * fdptr); /*@out@*/ FD_t * fdptr);
char * currentDirectory(void); /* result needs to be freed */ char * currentDirectory(void); /* result needs to be freed */
void compressFilelist(Header h); void compressFilelist(Header h);
void buildFileList(Header h, /*@out@*/ char *** fileListPtr, void buildFileList(Header h, /*@out@*/ const char *** fileListPtr,
/*@out@*/ int * fileCountPtr); /*@out@*/ int * fileCountPtr);
void buildOrigFileList(Header h, /*@out@*/ char *** fileListPtr, void buildOrigFileList(Header h, /*@out@*/ const char *** fileListPtr,
/*@out@*/ int * fileCountPtr); /*@out@*/ int * fileCountPtr);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -146,7 +146,9 @@ char * oldhdrReadFromFile(char * filename, struct oldrpmHeader * header) {
FD_t fd; FD_t fd;
fd = fdOpen(filename, O_RDONLY, 0); fd = fdOpen(filename, O_RDONLY, 0);
if (fdFileno(fd) < 0) return strerror(errno); if (Ferror(fd))
/* XXX Fstrerror */
return strerror(errno);
rc = oldhdrReadFromStream(fd, header); rc = oldhdrReadFromStream(fd, header);
Fclose(fd); Fclose(fd);

View File

@ -218,7 +218,7 @@ static int readPackageHeaders(FD_t fd, /*@out@*/struct rpmlead * leadPtr,
hdr = hdrPtr ? hdrPtr : &hdrBlock; hdr = hdrPtr ? hdrPtr : &hdrBlock;
lead = leadPtr ? leadPtr : &leadBlock; lead = leadPtr ? leadPtr : &leadBlock;
fstat(fdFileno(fd), &sb); fstat(Fileno(fd), &sb);
/* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */ /* if fd points to a socket, pipe, etc, sb.st_size is *always* zero */
if (S_ISREG(sb.st_mode) && sb.st_size < sizeof(*lead)) return 1; if (S_ISREG(sb.st_mode) && sb.st_size < sizeof(*lead)) return 1;

View File

@ -459,16 +459,17 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg,
{ FD_t fd; { FD_t fd;
fd = ufdOpen(arg, O_RDONLY, 0); fd = ufdOpen(arg, O_RDONLY, 0);
if (fdFileno(fd) < 0) { 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,urlStrerror(arg));
ufdClose(fd); Fclose(fd);
retcode = 1; retcode = 1;
break; break;
} }
retcode = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL); retcode = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
ufdClose(fd); Fclose(fd);
switch (retcode) { switch (retcode) {
case 0: case 0:

View File

@ -27,7 +27,9 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc)
/* open a file and set *fdp */ /* open a file and set *fdp */
if (*fdp == NULL && fnp && *fnp) { if (*fdp == NULL && fnp && *fnp) {
mode_t mode = (flags & O_CREAT) ? 0644 : 0; mode_t mode = (flags & O_CREAT) ? 0644 : 0;
if (fdFileno(fd = fdOpen(*fnp, flags, mode)) < 0) { fd = fdOpen(*fnp, flags, mode);
if (Ferror(fd)) {
/* XXX Fstrerror */
fprintf(stderr, _("%s: fdOpen failed: %s\n"), *fnp, fprintf(stderr, _("%s: fdOpen failed: %s\n"), *fnp,
strerror(errno)); strerror(errno));
return 1; return 1;

View File

@ -187,7 +187,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
for (filename = packages; *filename; filename++) { for (filename = packages; *filename; filename++) {
fd = fdOpen(*filename, O_RDONLY, 0); fd = fdOpen(*filename, O_RDONLY, 0);
if (fdFileno(fd) < 0) { if (Ferror(fd)) {
/* XXX Fstrerror */
rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), *filename); rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), *filename);
numFailed++; numFailed++;
packages[i] = NULL; packages[i] = NULL;
@ -328,7 +329,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
if (numSourcePackages && !stopInstall) { if (numSourcePackages && !stopInstall) {
for (i = 0; i < numSourcePackages; i++) { for (i = 0; i < numSourcePackages; i++) {
fd = fdOpen(sourcePackages[i], O_RDONLY, 0); fd = fdOpen(sourcePackages[i], O_RDONLY, 0);
if (fdFileno(fd) < 0) { if (Ferror(fd)) {
/* XXX Fstrerror */
rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"),
sourcePackages[i]); sourcePackages[i]);
continue; continue;
@ -455,7 +457,7 @@ int rpmInstallSource(const char * rootdir, const char * arg, const char ** specF
int rc; int rc;
fd = ufdOpen(arg, O_RDONLY, 0); fd = ufdOpen(arg, O_RDONLY, 0);
if (fdFileno(fd) < 0) { if (Ferror(fd)) {
/* XXX Fstrerror */ /* XXX Fstrerror */
rpmMessage(RPMMESS_ERROR, _("cannot open %s\n"), arg); rpmMessage(RPMMESS_ERROR, _("cannot open %s\n"), arg);
Fclose(fd); Fclose(fd);

View File

@ -28,6 +28,9 @@ int Fseek (FD_t fd, long int offset, int whence);
int Fclose ( /*@only@*/ FD_t fd); int Fclose ( /*@only@*/ FD_t fd);
FILE * Fopen (const char *path, const char *fmode); FILE * Fopen (const char *path, const char *fmode);
int Ferror (FD_t fd);
int Fileno (FD_t fd);
#endif /* H_RPMIO */ #endif /* H_RPMIO */
#ifndef H_RPMIO_F #ifndef H_RPMIO_F
@ -41,7 +44,6 @@ int timedRead(FD_t fd, /*@out@*/void * bufptr, int length);
extern /*@only@*/ /*@null@*/ FD_t fdNew(cookie_io_functions_t * iop); extern /*@only@*/ /*@null@*/ FD_t fdNew(cookie_io_functions_t * iop);
extern int fdValid(FD_t fd); extern int fdValid(FD_t fd);
extern int fdFileno(FD_t fd);
extern /*@only@*/ /*@null@*/ FD_t fdOpen(const char *pathname, int flags, mode_t mode); extern /*@only@*/ /*@null@*/ FD_t fdOpen(const char *pathname, int flags, mode_t mode);
extern /*@only@*/ /*@null@*/ FD_t fdDup(int fdno); extern /*@only@*/ /*@null@*/ FD_t fdDup(int fdno);
@ -88,9 +90,11 @@ extern cookie_io_functions_t bzdio;
#endif /* HAVE_BZLIB_H */ #endif /* HAVE_BZLIB_H */
/*@only@*/ FD_t ufdOpen(const char * pathname, int flags, mode_t mode); /*@only@*/ FD_t ufdOpen(const char * pathname, int flags, mode_t mode);
int ufdClose( /*@only@*/ FD_t fd); /*@dependent@*/ void * ufdGetUrlinfo(FD_t fd);
/*@observer@*/ const char *urlStrerror(const char *url); /*@observer@*/ const char *urlStrerror(const char *url);
extern cookie_io_functions_t ufdio;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -540,10 +540,11 @@ int rpmReadRC(const char * rcfiles)
/* Read another rcfile */ /* Read another rcfile */
fd = fdOpen(fn, O_RDONLY, 0); fd = fdOpen(fn, O_RDONLY, 0);
if (fdFileno(fd) < 0) { if (Ferror(fd)) {
/* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */ /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */
if (rcfiles == defrcfiles && myrcfiles != r) if (rcfiles == defrcfiles && myrcfiles != r)
continue; continue;
/* XXX Fstrerror */
rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."), rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."),
fn, strerror(errno)); fn, strerror(errno));
rc = 1; rc = 1;
@ -579,7 +580,7 @@ static int doReadRC(FD_t fd, const char * filename)
int rc; int rc;
{ struct stat sb; { struct stat sb;
fstat(fdFileno(fd), &sb); fstat(Fileno(fd), &sb);
next = alloca(sb.st_size + 2); next = alloca(sb.st_size + 2);
if (Fread(next, sb.st_size, 1, fd) != sb.st_size) { if (Fread(next, sb.st_size, 1, fd) != sb.st_size) {
rpmError(RPMERR_RPMRC, _("Failed to read %s: %s."), filename, rpmError(RPMERR_RPMRC, _("Failed to read %s: %s."), filename,
@ -654,7 +655,8 @@ static int doReadRC(FD_t fd, const char * filename)
} }
fdinc = fdOpen(fn, O_RDONLY, 0); fdinc = fdOpen(fn, O_RDONLY, 0);
if (fdFileno(fdinc) < 0) { if (Ferror(fdinc)) {
/* XXX Fstrerror */
rpmError(RPMERR_RPMRC, _("cannot open %s at %s:%d"), rpmError(RPMERR_RPMRC, _("cannot open %s at %s:%d"),
fn, filename, linenum); fn, filename, linenum);
rc = 1; rc = 1;
@ -825,7 +827,7 @@ static void defaultMachine(const char ** arch, const char ** os) {
/* we are on ncr-sysv4 */ /* we are on ncr-sysv4 */
char *prelid = NULL; char *prelid = NULL;
FD_t fd = fdOpen("/etc/.relid", O_RDONLY, 0700); FD_t fd = fdOpen("/etc/.relid", O_RDONLY, 0700);
if (fdFileno(fd) > 0) { if (!Ferror(fd)) {
chptr = (char *) xcalloc(1, 256); chptr = (char *) xcalloc(1, 256);
if (chptr != NULL) { if (chptr != NULL) {
int irelid = Fread(chptr, 256, 1, fd); int irelid = Fread(chptr, 256, 1, fd);

View File

@ -62,13 +62,14 @@ int ftpGetFileDesc(FD_t);
int ftpAbort( /*@only@*/ FD_t fd); int ftpAbort( /*@only@*/ FD_t fd);
int ftpClose( /*@only@*/ FD_t fd); int ftpClose( /*@only@*/ FD_t fd);
urltype urlIsURL(const char * url);
int urlSplit(const char *url, /*@out@*/ urlinfo **u);
/*@only@*/ urlinfo *newUrlinfo(void); /*@only@*/ urlinfo *newUrlinfo(void);
void freeUrlinfo( /*@only@*/ urlinfo *u); void freeUrlinfo( /*@only@*/ urlinfo *u);
void freeUrlinfoCache(void);
urltype urlIsURL(const char * url);
int urlSplit(const char *url, /*@out@*/ urlinfo **u);
int urlGetFile(const char * url, const char * dest); int urlGetFile(const char * url, const char * dest);
void urlInvalidateCache(const char * url);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -99,7 +99,7 @@ static int checkSize(FD_t fd, int size, int sigsize)
int headerArchiveSize; int headerArchiveSize;
struct stat statbuf; struct stat statbuf;
fstat(fdFileno(fd), &statbuf); fstat(Fileno(fd), &statbuf);
if (S_ISREG(statbuf.st_mode)) { if (S_ISREG(statbuf.st_mode)) {
headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize; headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize;

View File

@ -10,18 +10,18 @@ int timedRead(FD_t fd, void * bufptr, int length) {
struct timeval tv; struct timeval tv;
struct stat sb; struct stat sb;
fstat(fdFileno(fd), &sb); fstat(Fileno(fd), &sb);
if (S_ISREG(sb.st_mode)) if (S_ISREG(sb.st_mode))
return Fread(buf, length, 1, fd); return Fread(buf, length, 1, fd);
while (total < length) { while (total < length) {
FD_ZERO(&readSet); FD_ZERO(&readSet);
FD_SET(fdFileno(fd), &readSet); FD_SET(Fileno(fd), &readSet);
tv.tv_sec = 30; /* FIXME: this should be configurable */ tv.tv_sec = 30; /* FIXME: this should be configurable */
tv.tv_usec = 0; tv.tv_usec = 0;
if (select(fdFileno(fd) + 1, &readSet, NULL, NULL, &tv) != 1) if (select(Fileno(fd) + 1, &readSet, NULL, NULL, &tv) != 1)
return total; return total;
bytesRead = Fread(buf + total, length - total, 1, fd); bytesRead = Fread(buf + total, length - total, 1, fd);

View File

@ -310,11 +310,11 @@ static int runScript(Header h, const char * root, int progArgc, const char ** pr
if (errfd != NULL) { if (errfd != NULL) {
if (rpmIsVerbose()) { if (rpmIsVerbose()) {
out = fdDup(fdFileno(errfd)); out = fdDup(Fileno(errfd));
} else { } else {
out = fdOpen("/dev/null", O_WRONLY, 0); out = fdOpen("/dev/null", O_WRONLY, 0);
if (fdFileno(out) < 0) if (Ferror(out))
out = fdDup(fdFileno(errfd)); out = fdDup(Fileno(errfd));
} }
} else { } else {
out = fdDup(STDOUT_FILENO); out = fdDup(STDOUT_FILENO);
@ -331,14 +331,14 @@ static int runScript(Header h, const char * root, int progArgc, const char ** pr
close(pipes[0]); close(pipes[0]);
if (errfd != NULL) { if (errfd != NULL) {
if (fdFileno(errfd) != STDERR_FILENO) if (Fileno(errfd) != STDERR_FILENO)
dup2(fdFileno(errfd), STDERR_FILENO); dup2(Fileno(errfd), STDERR_FILENO);
if (fdFileno(out) != STDOUT_FILENO) if (Fileno(out) != STDOUT_FILENO)
dup2(fdFileno(out), STDOUT_FILENO); dup2(Fileno(out), STDOUT_FILENO);
/* make sure we don't close stdin/stderr/stdout by mistake! */ /* make sure we don't close stdin/stderr/stdout by mistake! */
if (fdFileno(out) > STDERR_FILENO && fdFileno(out) != fdFileno(errfd)) if (Fileno(out) > STDERR_FILENO && Fileno(out) != Fileno(errfd))
Fclose (out); Fclose (out);
if (fdFileno(errfd) > STDERR_FILENO) if (Fileno(errfd) > STDERR_FILENO)
Fclose (errfd); Fclose (errfd);
} }

View File

@ -13,7 +13,22 @@
#include <rpmurl.h> #include <rpmurl.h>
/*@access FD_t@*/ typedef /*@owned@*/ urlinfo * urlinfop;
/*@only@*/ /*@null@*/ static urlinfop *uCache = NULL;
static int uCount = 0;
urlinfo *newUrlinfo(void)
{
urlinfo *u;
if ((u = xmalloc(sizeof(*u))) == NULL)
return NULL;
memset(u, 0, sizeof(*u));
u->proxyp = -1;
u->port = -1;
u->ftpControl = -1;
u->ftpGetFileDoneNeeded = 0;
return u;
}
void freeUrlinfo(urlinfo *u) void freeUrlinfo(urlinfo *u)
{ {
@ -32,24 +47,23 @@ void freeUrlinfo(urlinfo *u)
FREE(u); FREE(u);
} }
urlinfo *newUrlinfo(void) void freeUrlinfoCache(void)
{ {
urlinfo *u; int i;
if ((u = xmalloc(sizeof(*u))) == NULL) for (i = 0; i < uCount; i++) {
return NULL; if (uCache[i])
memset(u, 0, sizeof(*u)); freeUrlinfo(uCache[i]);
u->proxyp = -1; }
u->port = -1; if (uCache)
u->ftpControl = -1; free(uCache);
u->ftpGetFileDoneNeeded = 0; uCache = NULL;
return u; uCount = 0;
} }
static int urlStrcmp(const char *str1, const char *str2) static int urlStrcmp(const char *str1, const char *str2)
{ {
if (str1 && str2) { if (str1 && str2)
return (strcmp(str1, str2)); return (strcmp(str1, str2));
} else
if (str1 != str2) if (str1 != str2)
return -1; return -1;
return 0; return 0;
@ -59,8 +73,6 @@ static void findUrlinfo(urlinfo **uret, int mustAsk)
{ {
urlinfo *u; urlinfo *u;
urlinfo **empty; urlinfo **empty;
/*@only@*/static urlinfo **uCache = NULL;
static int uCount = 0;
int i; int i;
if (uret == NULL) if (uret == NULL)
@ -76,6 +88,7 @@ static void findUrlinfo(urlinfo **uret, int mustAsk)
empty = &uCache[i]; empty = &uCache[i];
continue; continue;
} }
/* Check for cache-miss condition. A cache miss is /* Check for cache-miss condition. A cache miss is
* a) both items are not NULL and don't compare. * a) both items are not NULL and don't compare.
* b) either of the items is not NULL. * b) either of the items is not NULL.
@ -194,6 +207,30 @@ static void findUrlinfo(urlinfo **uret, int mustAsk)
return; return;
} }
static struct urlstring {
const char *leadin;
urltype ret;
} urlstrings[] = {
{ "file://", URL_IS_PATH },
{ "ftp://", URL_IS_FTP },
{ "http://", URL_IS_HTTP },
{ "-", URL_IS_DASH },
{ NULL, URL_IS_UNKNOWN }
};
urltype urlIsURL(const char * url)
{
struct urlstring *us;
for (us = urlstrings; us->leadin != NULL; us++) {
if (strncmp(url, us->leadin, strlen(us->leadin)))
continue;
return us->ret;
}
return URL_IS_UNKNOWN;
}
/* /*
* Split URL into components. The URL can look like * Split URL into components. The URL can look like
* service://user:password@host:port/path * service://user:password@host:port/path
@ -297,16 +334,20 @@ int urlGetFile(const char * url, const char * dest) {
int rc; int rc;
FD_t sfd = NULL; FD_t sfd = NULL;
FD_t tfd = NULL; FD_t tfd = NULL;
urlinfo * sfu;
sfd = ufdOpen(url, O_RDONLY, 0); sfd = ufdOpen(url, O_RDONLY, 0);
if (sfd == NULL || fdFileno(sfd) < 0) { if (sfd == NULL || Ferror(sfd)) {
/* XXX Fstrerror */
rpmMessage(RPMMESS_DEBUG, _("failed to open %s\n"), url); rpmMessage(RPMMESS_DEBUG, _("failed to open %s\n"), url);
ufdClose(sfd); Fclose(sfd);
return FTPERR_UNKNOWN; return FTPERR_UNKNOWN;
} }
if (sfd->fd_url != NULL && dest == NULL) { sfu = ufdGetUrlinfo(sfd);
const char *fileName = ((urlinfo *)sfd->fd_url)->path;
if (sfu != NULL && dest == NULL) {
const char *fileName = sfu->path;
if ((dest = strrchr(fileName, '/')) != NULL) if ((dest = strrchr(fileName, '/')) != NULL)
dest++; dest++;
else else
@ -314,10 +355,11 @@ int urlGetFile(const char * url, const char * dest) {
} }
tfd = fdOpen(dest, O_CREAT|O_WRONLY|O_TRUNC, 0600); tfd = fdOpen(dest, O_CREAT|O_WRONLY|O_TRUNC, 0600);
if (fdFileno(tfd) < 0) { if (Ferror(tfd)) {
/* XXX Fstrerror */
rpmMessage(RPMMESS_DEBUG, _("failed to create %s\n"), dest); rpmMessage(RPMMESS_DEBUG, _("failed to create %s\n"), dest);
Fclose(tfd); Fclose(tfd);
ufdClose(sfd); Fclose(sfd);
return FTPERR_UNKNOWN; return FTPERR_UNKNOWN;
} }
@ -325,18 +367,18 @@ int urlGetFile(const char * url, const char * dest) {
case URL_IS_FTP: case URL_IS_FTP:
if ((rc = ftpGetFile(sfd, tfd))) { if ((rc = ftpGetFile(sfd, tfd))) {
unlink(dest); unlink(dest);
ufdClose(sfd); /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ;
} }
/* XXX fdClose(sfd) done by copyData */ /* XXX Fclose(sfd) done by copyData */
break; break;
case URL_IS_HTTP: case URL_IS_HTTP:
case URL_IS_PATH: case URL_IS_PATH:
case URL_IS_DASH: case URL_IS_DASH:
if ((rc = httpGetFile(sfd, tfd))) { if ((rc = httpGetFile(sfd, tfd))) {
unlink(dest); unlink(dest);
ufdClose(sfd); /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ;
} }
/* XXX fdClose(sfd) done by copyData */ /* XXX Fclose(sfd) done by copyData */
break; break;
case URL_IS_UNKNOWN: case URL_IS_UNKNOWN:
default: default:

View File

@ -247,7 +247,7 @@ int rpmVerifyScript(const char * root, Header h, FD_t err)
/* ======================================================================== */ /* ======================================================================== */
static int verifyHeader(QVA_t *qva, Header h) static int verifyHeader(QVA_t *qva, Header h)
{ {
char ** fileList; const char ** fileList;
int count; int count;
int verifyResult; int verifyResult;
int i, ec, rc; int i, ec, rc;

File diff suppressed because it is too large Load Diff

71
rpm.c
View File

@ -1,6 +1,7 @@
#include "system.h" #include "system.h"
#include "rpmbuild.h" #include <rpmbuild.h>
#include <rpmurl.h>
#include "build.h" #include "build.h"
#include "install.h" #include "install.h"
@ -71,7 +72,7 @@ extern const char * rpmEVR;
extern int rpmFLAGS; extern int rpmFLAGS;
static struct rpmQVArguments rpmQVArgs; static struct rpmQVArguments rpmQVArgs;
static struct rpmBuildArguments buildArgs; static struct rpmBuildArguments rpmBArgs;
/* the structure describing the options we take and the defaults */ /* the structure describing the options we take and the defaults */
static struct poptOption optionsTable[] = { static struct poptOption optionsTable[] = {
@ -146,7 +147,7 @@ static struct poptOption optionsTable[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
rpmVerifyPoptTable, 0, (void *) &rpmQVArgs, NULL }, rpmVerifyPoptTable, 0, (void *) &rpmQVArgs, NULL },
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
rpmBuildPoptTable, 0, (void *) &buildArgs, NULL }, rpmBuildPoptTable, 0, (void *) &rpmBArgs, NULL },
{ 0, 0, 0, 0, 0, NULL, NULL } { 0, 0, 0, 0, 0, NULL, NULL }
}; };
@ -503,6 +504,7 @@ int main(int argc, const char ** argv)
{ {
enum modes bigMode = MODE_UNKNOWN; enum modes bigMode = MODE_UNKNOWN;
QVA_t *qva = &rpmQVArgs; QVA_t *qva = &rpmQVArgs;
struct rpmBuildArguments *ba = &rpmBArgs;
enum rpmQVSources QVSource = RPMQV_PACKAGE; enum rpmQVSources QVSource = RPMQV_PACKAGE;
int arg; int arg;
int installFlags = 0, uninstallFlags = 0, interfaceFlags = 0; int installFlags = 0, uninstallFlags = 0, interfaceFlags = 0;
@ -625,10 +627,10 @@ int main(int argc, const char ** argv)
if (qva->qva_queryFormat) xfree(qva->qva_queryFormat); if (qva->qva_queryFormat) xfree(qva->qva_queryFormat);
memset(qva, 0, sizeof(*qva)); memset(qva, 0, sizeof(*qva));
if (buildArgs.buildRootOverride) xfree(buildArgs.buildRootOverride); if (ba->buildRootOverride) xfree(ba->buildRootOverride);
if (buildArgs.targets) free(buildArgs.targets); if (ba->targets) free(ba->targets);
memset(&buildArgs, 0, sizeof(buildArgs)); memset(ba, 0, sizeof(*ba));
buildArgs.buildChar = ' '; ba->buildChar = ' ';
while ((arg = poptGetNextOpt(optCon)) > 0) { while ((arg = poptGetNextOpt(optCon)) > 0) {
optArg = poptGetOptArg(optCon); optArg = poptGetOptArg(optCon);
@ -686,8 +688,8 @@ int main(int argc, const char ** argv)
if (strlen(optArg) > 1) if (strlen(optArg) > 1)
argerror(errString); argerror(errString);
buildArgs.buildChar = optArg[0]; ba->buildChar = optArg[0];
switch (buildArgs.buildChar) { switch (ba->buildChar) {
case 'a': case 'a':
case 'b': case 'b':
case 'i': case 'i':
@ -860,10 +862,10 @@ int main(int argc, const char ** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((buildArgs.buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN) if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
bigMode = MODE_BUILD; bigMode = MODE_BUILD;
if ((buildArgs.buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN) if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
bigMode = MODE_BUILD; bigMode = MODE_BUILD;
if (initdb) { if (initdb) {
@ -887,7 +889,7 @@ int main(int argc, const char ** argv)
QVSource = qva->qva_source; QVSource = qva->qva_source;
} }
if (buildArgs.buildRootOverride && bigMode != MODE_BUILD && if (ba->buildRootOverride && bigMode != MODE_BUILD &&
bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) { bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
argerror("--buildroot may only be used during package builds"); argerror("--buildroot may only be used during package builds");
} }
@ -913,8 +915,8 @@ int main(int argc, const char ** argv)
argerror(_("unexpected query source")); argerror(_("unexpected query source"));
if (!(bigMode == MODE_INSTALL || if (!(bigMode == MODE_INSTALL ||
(bigMode==MODE_BUILD && (buildArgs.buildAmount & RPMBUILD_RMSOURCE))|| (bigMode==MODE_BUILD && (ba->buildAmount & RPMBUILD_RMSOURCE))||
(bigMode==MODE_BUILD && (buildArgs.buildAmount & RPMBUILD_RMSPEC))) (bigMode==MODE_BUILD && (ba->buildAmount & RPMBUILD_RMSPEC)))
&& force) && force)
argerror(_("only installation, upgrading, rmsource and rmspec may be forced")); argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
@ -1170,13 +1172,13 @@ int main(int argc, const char ** argv)
if (!poptPeekArg(optCon)) if (!poptPeekArg(optCon))
argerror(_("no packages files given for rebuild")); argerror(_("no packages files given for rebuild"));
buildArgs.buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL; ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
if (bigMode == MODE_REBUILD) { if (bigMode == MODE_REBUILD) {
buildArgs.buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
buildArgs.buildAmount |= RPMBUILD_RMSOURCE; ba->buildAmount |= RPMBUILD_RMSOURCE;
buildArgs.buildAmount |= RPMBUILD_RMSPEC; ba->buildAmount |= RPMBUILD_RMSPEC;
buildArgs.buildAmount |= RPMBUILD_CLEAN; ba->buildAmount |= RPMBUILD_CLEAN;
buildArgs.buildAmount |= RPMBUILD_RMBUILD; ba->buildAmount |= RPMBUILD_RMBUILD;
} }
while ((pkg = poptGetArg(optCon))) { while ((pkg = poptGetArg(optCon))) {
@ -1184,7 +1186,7 @@ int main(int argc, const char ** argv)
if (ec) if (ec)
break; break;
ec = build(specFile, &buildArgs, passPhrase, 0, cookie, rcfile, force, noDeps); ec = build(specFile, ba, passPhrase, 0, cookie, rcfile, force, noDeps);
if (ec) if (ec)
break; break;
free(cookie); free(cookie);
@ -1197,34 +1199,34 @@ int main(int argc, const char ** argv)
if (rpmGetVerbosity() == RPMMESS_NORMAL) if (rpmGetVerbosity() == RPMMESS_NORMAL)
rpmSetVerbosity(RPMMESS_VERBOSE); rpmSetVerbosity(RPMMESS_VERBOSE);
switch (buildArgs.buildChar) { switch (ba->buildChar) {
/* these fallthroughs are intentional */ /* these fallthroughs are intentional */
case 'a': case 'a':
buildArgs.buildAmount |= RPMBUILD_PACKAGESOURCE; ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
/*@fallthrough@*/ /*@fallthrough@*/
case 'b': case 'b':
buildArgs.buildAmount |= RPMBUILD_PACKAGEBINARY; ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
buildArgs.buildAmount |= RPMBUILD_CLEAN; ba->buildAmount |= RPMBUILD_CLEAN;
/*@fallthrough@*/ /*@fallthrough@*/
case 'i': case 'i':
buildArgs.buildAmount |= RPMBUILD_INSTALL; ba->buildAmount |= RPMBUILD_INSTALL;
if ((buildArgs.buildChar == 'i') && buildArgs.shortCircuit) if ((ba->buildChar == 'i') && ba->shortCircuit)
break; break;
/*@fallthrough@*/ /*@fallthrough@*/
case 'c': case 'c':
buildArgs.buildAmount |= RPMBUILD_BUILD; ba->buildAmount |= RPMBUILD_BUILD;
if ((buildArgs.buildChar == 'c') && buildArgs.shortCircuit) if ((ba->buildChar == 'c') && ba->shortCircuit)
break; break;
/*@fallthrough@*/ /*@fallthrough@*/
case 'p': case 'p':
buildArgs.buildAmount |= RPMBUILD_PREP; ba->buildAmount |= RPMBUILD_PREP;
break; break;
case 'l': case 'l':
buildArgs.buildAmount |= RPMBUILD_FILECHECK; ba->buildAmount |= RPMBUILD_FILECHECK;
break; break;
case 's': case 's':
buildArgs.buildAmount |= RPMBUILD_PACKAGESOURCE; ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
break; break;
} }
@ -1236,7 +1238,7 @@ int main(int argc, const char ** argv)
} }
while ((pkg = poptGetArg(optCon))) { while ((pkg = poptGetArg(optCon))) {
ec = build(pkg, &buildArgs, passPhrase, bigMode == MODE_TARBUILD, ec = build(pkg, ba, passPhrase, bigMode == MODE_TARBUILD,
NULL, rcfile, force, noDeps); NULL, rcfile, force, noDeps);
if (ec) if (ec)
break; break;
@ -1365,7 +1367,10 @@ int main(int argc, const char ** argv)
/* keeps memory leak checkers quiet */ /* keeps memory leak checkers quiet */
freeNames(); freeNames();
freeFilesystems(); freeFilesystems();
freeUrlinfoCache();
if (qva->qva_queryFormat) xfree(qva->qva_queryFormat); if (qva->qva_queryFormat) xfree(qva->qva_queryFormat);
if (ba->buildRootOverride) xfree(ba->buildRootOverride);
if (ba->targets) free(ba->targets);
#if HAVE_MCHECK_H && HAVE_MTRACE #if HAVE_MCHECK_H && HAVE_MTRACE
muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */

View File

@ -20,7 +20,7 @@ int main(int argc, char **argv)
fdi = ufdOpen(argv[1], O_RDONLY, 0644); fdi = ufdOpen(argv[1], O_RDONLY, 0644);
} }
if (fdFileno(fdi) < 0) { if (Fileno(fdi) < 0) {
perror("cannot open package"); perror("cannot open package");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

View File

@ -25,7 +25,7 @@
#define _(x) x #define _(x) x
#define xfree(_p) free((void *)_p) #define xfree(_p) free((void *)_p)
typedef int FD_t; typedef int FD_t;
#define fdFileno(_x) (_x) #define Ferror(_x) (_x)
#define fdOpen open #define fdOpen open
#define Fread(_b, _s, _n, _fd) read(_fd, _b, _s) #define Fread(_b, _s, _n, _fd) read(_fd, _b, _s)
#define Fclose(_fd) close(_fd) #define Fclose(_fd) close(_fd)
@ -1341,7 +1341,9 @@ int isCompressed(const char *file, int *compressed)
*compressed = COMPRESSED_NOT; *compressed = COMPRESSED_NOT;
if (fdFileno(fd = fdOpen(file, O_RDONLY, 0)) < 0) { fd = fdOpen(file, O_RDONLY, 0);
if (Ferror(fd)) {
/* XXX Fstrerror */
rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno)); rpmError(RPMERR_BADSPEC, _("File %s: %s"), file, strerror(errno));
return 1; return 1;
} }

View File

@ -14,7 +14,7 @@ int main(int argc, char ** argv)
fdi = fdOpen(argv[1], O_RDONLY, 0644); fdi = fdOpen(argv[1], O_RDONLY, 0644);
} }
if (fdFileno(fdi) < 0) { if (Fileno(fdi) < 0) {
fprintf(stderr, _("cannot open %s: %s\n"), argv[1], strerror(errno)); fprintf(stderr, _("cannot open %s: %s\n"), argv[1], strerror(errno));
exit(1); exit(1);
} }

View File

@ -836,7 +836,9 @@ rpmgettext(FD_t fd, const char *file, FILE *ofp)
} }
} }
if (fdFileno(fd = fdOpen(fni, O_RDONLY, 0644)) < 0) { fd = fdOpen(fni, O_RDONLY, 0644);
if (Ferror(fd)) {
/* XXX Fstrerror */
fprintf(stderr, _("rpmgettext: open %s: %s\n"), fni, strerror(errno)); fprintf(stderr, _("rpmgettext: open %s: %s\n"), fni, strerror(errno));
return 2; return 2;
} }

View File

@ -18,9 +18,9 @@ int main(int argc, char **argv)
fdi = fdDup(STDIN_FILENO); fdi = fdDup(STDIN_FILENO);
} else { } else {
fdi = fdOpen(argv[1], O_RDONLY, 0644); fdi = fdOpen(argv[1], O_RDONLY, 0644);
if (fdFileno(fdi) < 0) { if (Ferror(fdi)) {
perror(argv[1]); perror(argv[1]);
exit(1); exit(EXIT_FAILURE);
} }
} }

View File

@ -15,9 +15,9 @@ int main(int argc, char **argv)
fdi = fdDup(STDIN_FILENO); fdi = fdDup(STDIN_FILENO);
} else { } else {
fdi = fdOpen(argv[1], O_RDONLY, 0644); fdi = fdOpen(argv[1], O_RDONLY, 0644);
if (fdFileno(fdi) < 0) { if (Ferror(fdi)) {
perror(argv[1]); perror(argv[1]);
exit(1); exit(EXIT_FAILURE);
} }
} }

View File

@ -16,7 +16,7 @@ int main(int argc, char **argv)
fdi = fdDup(STDIN_FILENO); fdi = fdDup(STDIN_FILENO);
} else { } else {
fdi = fdOpen(argv[1], O_RDONLY, 0644); fdi = fdOpen(argv[1], O_RDONLY, 0644);
if (fdFileno(fdi) < 0) { if (Ferror(fdi)) {
perror(argv[1]); perror(argv[1]);
exit(1); exit(1);
} }