/[packages]/cauldron/perl-URPM/current/SOURCES/URPM-3.38.5-switch-from-forking-unpacker-to-using-librpm.diff
ViewVC logotype

Contents of /cauldron/perl-URPM/current/SOURCES/URPM-3.38.5-switch-from-forking-unpacker-to-using-librpm.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 195423 - (show annotations) (download)
Thu Jan 12 20:41:19 2012 UTC (9 years, 8 months ago) by tv
File size: 4798 byte(s)
SILENT: new file ./SOURCES/URPM-3.38.5-switch-from-forking-unpacker-to-using-librpm.diff
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,17 @@ 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 + fprintf(stderr, "Failed to open hdlist: %s\n", Fstrerror(fd));
114 + } else if (fd) {
115 Header header;
116 int start_id = 1 + av_len(depslist);
117 int packing = 0;
118 (open_archive) clean API
119 diff -p -up ./URPM.xs.tv2 ./URPM.xs
120 --- ./URPM.xs.tv2 2011-12-06 15:20:56.832673044 +0000
121 +++ ./URPM.xs 2011-12-06 15:20:41.735661297 +0000
122 @@ -1001,7 +1001,7 @@ update_provides_files(URPM__Package pkg,
123 }
124
125 FD_t
126 -open_archive(char *filename, pid_t *pid, int *empty_archive) {
127 +open_archive(char *filename, int *empty_archive) {
128 int fd;
129 FD_t rfd = NULL;
130 struct {
131 @@ -3402,11 +3402,10 @@ Urpm_parse_hdlist__XS(urpm, filename, ..
132 HV *obsoletes = fobsoletes && SvROK(*fobsoletes) && SvTYPE(SvRV(*fobsoletes)) == SVt_PVHV ? (HV*)SvRV(*fobsoletes) : NULL;
133
134 if (depslist != NULL) {
135 - pid_t pid = 0;
136 int empty_archive = 0;
137 FD_t fd;
138
139 - fd = open_archive(filename, &pid, &empty_archive);
140 + fd = open_archive(filename, &empty_archive);
141
142 if (empty_archive) {
143 XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist))));
144 @@ -3462,13 +3461,7 @@ Urpm_parse_hdlist__XS(urpm, filename, ..
145
146 int ok = Fclose(fd) == 0;
147
148 - if (pid) {
149 - kill(pid, SIGTERM);
150 - int status;
151 - int rc = waitpid(pid, &status, 0);
152 - ok = rc != -1 && WEXITSTATUS(status) != 1; /* in our standard case, gzip will exit with status code 2, meaning "decompression OK, trailing garbage ignored" */
153 - pid = 0;
154 - } else if (!empty_archive) {
155 + if (!empty_archive) {
156 ok = av_len(depslist) >= start_id;
157 }
158 SPAGAIN;

  ViewVC Help
Powered by ViewVC 1.1.28