Bug#2256: dpkg 1.0.11: make --new faster, descriptor leaks
Package: dpkg
Here is a patch that makes dpkg-deb much faster on new-style packages,
and fixes some descriptor leaks.
--- dpkg-1.0.11/dpkg-deb/build.c.~1~ Sun Jan 14 18:56:34 1996
+++ dpkg-1.0.11/dpkg-deb/build.c Fri Jan 26 21:43:29 1996
@@ -141,6 +141,7 @@
m_pipe(p1);
if (!(c1= m_fork())) {
m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
+ fclose (ar);
if (chdir(directory)) ohshite("failed to chdir to `%.255s'",directory);
if (chdir(BUILDCONTROLDIR)) ohshite("failed to chdir to .../" BUILDCONTROLDIR);
execlp(TAR,"tar","-cf","-",".",(char*)0); ohshite("failed to exec tar -cf");
@@ -149,6 +150,7 @@
if (!(gz= tmpfile())) ohshite("failed to make tmpfile (control)");
if (!(c2= m_fork())) {
m_dup2(p1[0],0); m_dup2(fileno(gz),1); close(p1[0]);
+ fclose (gz); fclose (ar);
execlp(GZIP,"gzip","-9c",(char*)0); ohshite("failed to exec gzip -9c");
}
close(p1[0]);
@@ -177,6 +179,7 @@
if (lseek(fileno(gz),0,SEEK_SET)) ohshite("failed to rewind tmpfile (control)");
if (!(c3= m_fork())) {
m_dup2(fileno(gz),0); m_dup2(fileno(ar),1);
+ fclose (gz); fclose (ar);
execlp(CAT,"cat",(char*)0); ohshite("failed to exec cat (control)");
}
waitsubproc(c3,"cat (control)",0);
@@ -188,6 +191,7 @@
m_pipe(p2);
if (!(c4= m_fork())) {
m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
+ fclose (gz); fclose (ar);
if (chdir(directory)) ohshite("failed to chdir to `%.255s'",directory);
execlp(TAR,"tar","--exclude",BUILDCONTROLDIR,"-cf","-",".",(char*)0);
ohshite("failed to exec tar --exclude");
@@ -196,6 +200,7 @@
if (!(c5= m_fork())) {
m_dup2(p2[0],0); close(p2[0]);
m_dup2(oldformatflag ? fileno(ar) : fileno(gz),1);
+ fclose (gz); fclose (ar);
execlp(GZIP,"gzip","-9c",(char*)0);
ohshite("failed to exec gzip -9c from tar --exclude");
}
@@ -215,6 +220,7 @@
if (lseek(fileno(gz),0,SEEK_SET)) ohshite("failed to rewind tmpfile (data)");
if (!(c3= m_fork())) {
m_dup2(fileno(gz),0); m_dup2(fileno(ar),1);
+ fclose (gz); fclose (ar);
execlp(CAT,"cat",(char*)0); ohshite("failed to exec cat (data)");
}
waitsubproc(c3,"cat (data)",0);
--- dpkg-1.0.11/dpkg-deb/extract.c.~1~ Sun Jan 14 18:56:34 1996
+++ dpkg-1.0.11/dpkg-deb/extract.c Fri Jan 26 22:03:29 1996
@@ -104,7 +104,6 @@
int readfromfd, oldformat, header_done, adminmember, c;
ar= fopen(debar,"r"); if (!ar) ohshite("failed to read archive `%.255s'",debar);
- setvbuf(ar,0,_IONBF,0);
if (fstat(fileno(ar),&stab)) ohshite("failed to fstat archive");
if (!fgets(versionbuf,sizeof(versionbuf),ar)) readfail(ar,debar,"version number");
@@ -201,6 +200,7 @@
ohshit("`%.255s' is not a debian format archive",debar);
}
+ fflush (ar);
if (oldformat) {
if (admininfo) {
m_pipe(p1);
@@ -241,12 +241,14 @@
if (!(c2= m_fork())) {
m_dup2(readfromfd,0);
- if (admininfo) close(p1[0]);
+ if (readfromfd != fileno (ar)) close (readfromfd);
+ fclose (ar);
if (taroption) { m_dup2(p2[1],1); close(p2[0]); close(p2[1]); }
execlp(GZIP,"gzip","-dc",(char*)0); ohshite("failed to exec gzip -dc");
}
if (readfromfd != fileno(ar)) close(readfromfd);
close(p2[1]);
+ fclose (ar);
if (taroption && directory) {
if (chdir(directory)) {
@@ -262,6 +264,7 @@
if (taroption) {
if (!(c3= m_fork())) {
m_dup2(p2[0],0);
+ close (p2[0]);
execlp(TAR,"tar",taroption,"-f","-",(char*)0);
ohshite("failed to exec tar");
}
--- dpkg-1.0.11/dpkg-deb/info.c.~1~ Sun Jan 14 18:56:34 1996
+++ dpkg-1.0.11/dpkg-deb/info.c Fri Jan 26 21:45:23 1996
@@ -91,9 +91,11 @@
if (co) {
if (!(c1= m_fork())) {
m_dup2(fileno(co),0);
+ fclose (co);
execlp(CAT,"cat",(char*)0); ohshite("failed to exec cat component");
}
waitsubproc(c1,"cat component",0);
+ fclose (co);
} else if (errno == ENOENT) {
if (fprintf(stderr, BACKEND ": `%.255s' contains no control component `%.255s'\n",
debar, component) == EOF) werr("stderr");
@@ -163,6 +165,7 @@
}
if (!lines) if (putc('\n',stdout) == EOF) werr("stdout");
}
+ fclose (cc);
}
static void info_field(const char *debar, const char *directory,
@@ -206,6 +209,7 @@
if (ferror(cc)) ohshite("failed during read of `control' component");
if (doing) putc('\n',stdout);
if (ferror(stdout)) werr("stdout");
+ fclose (cc);
}
void do_info(const char *const *argv) {
--
Andreas Schwab "And now for something
schwab@issan.informatik.uni-dortmund.de completely different"
Reply to: