1 |
(open_archive) switch from forking unpacker to using librpm |
2 |
--- URPM.xs 2011-12-06 14:57:46.606581011 +0000 |
3 |
+++ /URPM.xs 2011-10-11 14:59:42.972840095 +0000 |
4 |
@@ -1000,9 +1000,10 @@ update_provides_files(URPM__Package pkg, |
5 |
} |
6 |
} |
7 |
|
8 |
-int |
9 |
+FD_t |
10 |
open_archive(char *filename, pid_t *pid, int *empty_archive) { |
11 |
int fd; |
12 |
+ FD_t rfd = NULL; |
13 |
struct { |
14 |
char header[4]; |
15 |
char toc_d_count[4]; |
16 |
@@ -1019,65 +1020,26 @@ open_archive(char *filename, pid_t *pid, |
17 |
if (read(fd, &buf, sizeof(buf)) != sizeof(buf) || strncmp(buf.header, "cz[0", 4) || strncmp(buf.trailer, "0]cz", 4)) { |
18 |
/* this is not an archive, open it without magic, but first rewind at begin of file */ |
19 |
lseek(fd, 0, SEEK_SET); |
20 |
+ return fdDup(fd); |
21 |
} else if (pos == 0) { |
22 |
*empty_archive = 1; |
23 |
- fd = -1; |
24 |
} else { |
25 |
- /* this is an archive, create a pipe and fork for reading with uncompress defined inside */ |
26 |
- int fdno[2]; |
27 |
- |
28 |
- if (!pipe(fdno)) { |
29 |
- if ((*pid = fork()) != 0) { |
30 |
- fd_set readfds; |
31 |
- struct timeval timeout; |
32 |
- |
33 |
- FD_ZERO(&readfds); |
34 |
- FD_SET(fdno[0], &readfds); |
35 |
- timeout.tv_sec = 1; |
36 |
- timeout.tv_usec = 0; |
37 |
- select(fdno[0]+1, &readfds, NULL, NULL, &timeout); |
38 |
- |
39 |
- close(fd); |
40 |
- fd = fdno[0]; |
41 |
- close(fdno[1]); |
42 |
- } else { |
43 |
- char *unpacker[22]; /* enough for 40 bytes in uncompress to never overbuf */ |
44 |
- char *p = buf.uncompress; |
45 |
- int ip = 0; |
46 |
- char *ld_loader = getenv("LD_LOADER"); |
47 |
- |
48 |
- if (ld_loader && *ld_loader) { |
49 |
- unpacker[ip++] = ld_loader; |
50 |
- } |
51 |
- |
52 |
- buf.trailer[0] = 0; /* make sure end-of-string is right */ |
53 |
- while (*p) { |
54 |
- if (*p == ' ' || *p == '\t') *p++ = 0; |
55 |
- else { |
56 |
- unpacker[ip++] = p; |
57 |
- while (*p && *p != ' ' && *p != '\t') ++p; |
58 |
- } |
59 |
- } |
60 |
- unpacker[ip] = NULL; /* needed for execlp */ |
61 |
- |
62 |
- lseek(fd, 0, SEEK_SET); |
63 |
- dup2(fd, STDIN_FILENO); close(fd); |
64 |
- dup2(fdno[1], STDOUT_FILENO); close(fdno[1]); |
65 |
- |
66 |
- /* get rid of "decompression OK, trailing garbage ignored" */ |
67 |
- fd = open("/dev/null", O_WRONLY); |
68 |
- dup2(fd, STDERR_FILENO); close(fd); |
69 |
- |
70 |
- execvp(unpacker[0], unpacker); |
71 |
- exit(1); |
72 |
- } |
73 |
+ /* this is an archive, prepare for reading with uncompress defined inside */ |
74 |
+ rfd = Fopen(filename, "r.fdio"); |
75 |
+ if (strcmp(buf.uncompress, "gzip")) { |
76 |
+ rfd = Fdopen(rfd, "r.gzip"); |
77 |
+ } else if (strcmp(buf.uncompress, "bzip")) { |
78 |
+ rfd = Fdopen(rfd, "r.bzip2"); |
79 |
+ } else if (strcmp(buf.uncompress, "xz") || strcmp(buf.uncompress, "lzma")) { |
80 |
+ rfd = Fdopen(rfd, "r.xz"); |
81 |
} else { |
82 |
- close(fd); |
83 |
- fd = -1; |
84 |
+ free(rfd); |
85 |
+ rfd = NULL; |
86 |
} |
87 |
} |
88 |
} |
89 |
- return fd; |
90 |
+ close(fd); |
91 |
+ return rfd; |
92 |
} |
93 |
|
94 |
static int |
95 |
@@ -3439,18 +3403,15 @@ Urpm_parse_hdlist__XS(urpm, filename, .. |
96 |
|
97 |
if (depslist != NULL) { |
98 |
pid_t pid = 0; |
99 |
- int d; |
100 |
int empty_archive = 0; |
101 |
FD_t fd; |
102 |
|
103 |
- d = open_archive(filename, &pid, &empty_archive); |
104 |
- fd = fdDup(d); |
105 |
- close(d); |
106 |
+ fd = open_archive(filename, &pid, &empty_archive); |
107 |
|
108 |
if (empty_archive) { |
109 |
XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist)))); |
110 |
XPUSHs(sv_2mortal(newSViv(av_len(depslist)))); |
111 |
- } else if (d >= 0 && fd) { |
112 |
+ } else if (fd != NULL && !Ferror(fd)) { |
113 |
Header header; |
114 |
int start_id = 1 + av_len(depslist); |
115 |
int packing = 0; |
116 |
(open_archive) clean API |
117 |
diff -p -up ./URPM.xs.tv2 ./URPM.xs |
118 |
--- ./URPM.xs.tv2 2011-12-06 15:20:56.832673044 +0000 |
119 |
+++ ./URPM.xs 2011-12-06 15:20:41.735661297 +0000 |
120 |
@@ -1001,7 +1001,7 @@ update_provides_files(URPM__Package pkg, |
121 |
} |
122 |
|
123 |
FD_t |
124 |
-open_archive(char *filename, pid_t *pid, int *empty_archive) { |
125 |
+open_archive(char *filename, int *empty_archive) { |
126 |
int fd; |
127 |
FD_t rfd = NULL; |
128 |
struct { |
129 |
@@ -3402,11 +3402,10 @@ Urpm_parse_hdlist__XS(urpm, filename, .. |
130 |
HV *obsoletes = fobsoletes && SvROK(*fobsoletes) && SvTYPE(SvRV(*fobsoletes)) == SVt_PVHV ? (HV*)SvRV(*fobsoletes) : NULL; |
131 |
|
132 |
if (depslist != NULL) { |
133 |
- pid_t pid = 0; |
134 |
int empty_archive = 0; |
135 |
FD_t fd; |
136 |
|
137 |
- fd = open_archive(filename, &pid, &empty_archive); |
138 |
+ fd = open_archive(filename, &empty_archive); |
139 |
|
140 |
if (empty_archive) { |
141 |
XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist)))); |
142 |
@@ -3462,13 +3461,7 @@ Urpm_parse_hdlist__XS(urpm, filename, .. |
143 |
|
144 |
int ok = Fclose(fd) == 0; |
145 |
|
146 |
- if (pid) { |
147 |
- kill(pid, SIGTERM); |
148 |
- int status; |
149 |
- int rc = waitpid(pid, &status, 0); |
150 |
- ok = rc != -1 && WEXITSTATUS(status) != 1; /* in our standard case, gzip will exit with status code 2, meaning "decompression OK, trailing garbage ignored" */ |
151 |
- pid = 0; |
152 |
- } else if (!empty_archive) { |
153 |
+ if (!empty_archive) { |
154 |
ok = av_len(depslist) >= start_id; |
155 |
} |
156 |
SPAGAIN; |