aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2012-02-07 22:38:57 +0000
committerThierry Vignaud <tv@mageia.org>2012-02-07 22:38:57 +0000
commit18723d2d47f9e069667753703c12ba5139661957 (patch)
tree560111ddd81f77d81eb5528ca34f7fa1ad8c27a5
parent8fbdaab95b2ed7549e8ed436f5c21948ca2797b9 (diff)
downloadperl-URPM-18723d2d47f9e069667753703c12ba5139661957.tar
perl-URPM-18723d2d47f9e069667753703c12ba5139661957.tar.gz
perl-URPM-18723d2d47f9e069667753703c12ba5139661957.tar.bz2
perl-URPM-18723d2d47f9e069667753703c12ba5139661957.tar.xz
perl-URPM-18723d2d47f9e069667753703c12ba5139661957.zip
(open_archive) switch from forking unpacker to using librpm
-rw-r--r--NEWS2
-rw-r--r--URPM.xs75
2 files changed, 19 insertions, 58 deletions
diff --git a/NEWS b/NEWS
index a01bcff..3a8db75 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- switch from forking unpacker to using librpm
+
Version 3.38.7 - 07 February 2012
- cleanups
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;