From 18723d2d47f9e069667753703c12ba5139661957 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 7 Feb 2012 22:38:57 +0000 Subject: (open_archive) switch from forking unpacker to using librpm --- URPM.xs | 75 +++++++++++++++-------------------------------------------------- 1 file changed, 17 insertions(+), 58 deletions(-) (limited to 'URPM.xs') diff --git a/URPM.xs b/URPM.xs index 0167d11..b9e3dad 100644 --- a/URPM.xs +++ b/URPM.xs @@ -998,9 +998,10 @@ update_provides_files(URPM__Package pkg, HV *provides) { } } -int +FD_t open_archive(char *filename, pid_t *pid, int *empty_archive) { int fd; + FD_t rfd = NULL; struct { char header[4]; char toc_d_count[4]; @@ -1017,65 +1018,26 @@ open_archive(char *filename, pid_t *pid, int *empty_archive) { if (read(fd, &buf, sizeof(buf)) != sizeof(buf) || strncmp(buf.header, "cz[0", 4) || strncmp(buf.trailer, "0]cz", 4)) { /* this is not an archive, open it without magic, but first rewind at begin of file */ lseek(fd, 0, SEEK_SET); + return fdDup(fd); } else if (pos == 0) { *empty_archive = 1; - fd = -1; } else { - /* this is an archive, create a pipe and fork for reading with uncompress defined inside */ - int fdno[2]; - - if (!pipe(fdno)) { - if ((*pid = fork()) != 0) { - fd_set readfds; - struct timeval timeout; - - FD_ZERO(&readfds); - FD_SET(fdno[0], &readfds); - timeout.tv_sec = 1; - timeout.tv_usec = 0; - select(fdno[0]+1, &readfds, NULL, NULL, &timeout); - - close(fd); - fd = fdno[0]; - close(fdno[1]); - } else { - char *unpacker[22]; /* enough for 40 bytes in uncompress to never overbuf */ - char *p = buf.uncompress; - int ip = 0; - char *ld_loader = getenv("LD_LOADER"); - - if (ld_loader && *ld_loader) { - unpacker[ip++] = ld_loader; - } - - buf.trailer[0] = 0; /* make sure end-of-string is right */ - while (*p) { - if (*p == ' ' || *p == '\t') *p++ = 0; - else { - unpacker[ip++] = p; - while (*p && *p != ' ' && *p != '\t') ++p; - } - } - unpacker[ip] = NULL; /* needed for execlp */ - - lseek(fd, 0, SEEK_SET); - dup2(fd, STDIN_FILENO); close(fd); - dup2(fdno[1], STDOUT_FILENO); close(fdno[1]); - - /* get rid of "decompression OK, trailing garbage ignored" */ - fd = open("/dev/null", O_WRONLY); - dup2(fd, STDERR_FILENO); close(fd); - - execvp(unpacker[0], unpacker); - exit(1); - } + /* this is an archive, prepare for reading with uncompress defined inside */ + rfd = Fopen(filename, "r.fdio"); + if (strcmp(buf.uncompress, "gzip")) { + rfd = Fdopen(rfd, "r.gzip"); + } else if (strcmp(buf.uncompress, "bzip")) { + rfd = Fdopen(rfd, "r.bzip2"); + } else if (strcmp(buf.uncompress, "xz") || strcmp(buf.uncompress, "lzma")) { + rfd = Fdopen(rfd, "r.xz"); } else { - close(fd); - fd = -1; + free(rfd); + rfd = NULL; } } } - return fd; + close(fd); + return rfd; } static int @@ -3434,18 +3396,15 @@ Urpm_parse_hdlist__XS(urpm, filename, ...) if (depslist != NULL) { pid_t pid = 0; - int d; int empty_archive = 0; FD_t fd; - d = open_archive(filename, &pid, &empty_archive); - fd = fdDup(d); - close(d); + fd = open_archive(filename, &pid, &empty_archive); if (empty_archive) { mXPUSHs(newSViv(1 + av_len(depslist))); mXPUSHs(newSViv(av_len(depslist))); - } else if (d >= 0 && fd) { + } else if (fd != NULL && !Ferror(fd)) { Header header; int start_id = 1 + av_len(depslist); int packing = 0; -- cgit v1.2.1