From f4e1572a28add215857628bbf070056ed422f8b1 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Tue, 22 Aug 2000 21:21:58 +0000 Subject: [PATCH] updates from Chip Salzenberg to clean up fd handling --- ChangeLog | 6 ++++++ debian/changelog | 1 + dpkg-deb/build.c | 2 +- dpkg-deb/extract.c | 3 ++- lib/lock.c | 2 ++ main/archives.c | 4 ++-- main/configure.c | 2 +- main/filesdb.c | 3 +++ 8 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66d40828..6c230ed1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Aug 21 12:58:15 CEST 2000 Wichert Akkerman + + * lib/lock.c, main/filesdb.c, main/archives.c, main/configure.c, + dpkg-deb/build.c, dpkg-deb/extract.c: updates from Chip Salzenberg + to clean up fd handling + Thu Aug 10 21:08:00 CEST 2000 peter karlsson * po/sv.po: More corrections and translation updates. diff --git a/debian/changelog b/debian/changelog index a6ee003f..cd7b2ab2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,7 @@ dpkg (1.7.0) unstable; urgency=low * archtable: add ia64; revert sparc64 so that it turns into sparc. There wont be a full binary-sparc64 port. * dselect/main.cc: small fixups to get it to compile with gcc-2.96 + * Clean up fd handling in some places. Closes: Bug#69359,#69360,#69361 -- Wichert Akkerman UNRELEASED diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index 56530a72..60398f29 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -334,7 +334,7 @@ void do_build(const char *const *argv) { strcat(tfbuf,"/dpkg.XXXXXX"); /* And run gzip to compress our control archive */ if (!(c2= m_fork())) { - m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); + m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); close(gzfd); execlp(GZIP,"gzip","-9c",(char*)0); ohshite(_("failed to exec gzip -9c")); } close(p1[0]); diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index fb69c1f5..8bfb9ecc 100644 --- a/dpkg-deb/extract.c +++ b/dpkg-deb/extract.c @@ -267,7 +267,7 @@ void extracthalf(const char *debar, const char *directory, execlp(GZIP,"gzip","-dc",(char*)0); ohshite(_("failed to exec gzip -dc")); } if (readfromfd != fileno(ar)) close(readfromfd); - close(p2[1]); + if (taroption) close(p2[1]); if (taroption && directory) { if (chdir(directory)) { @@ -287,6 +287,7 @@ void extracthalf(const char *debar, const char *directory, strcpy(buffer, taroption); strcat(buffer, "f"); m_dup2(p2[0],0); + close(p2[0]); execlp(TAR,"tar",buffer,"-",(char*)0); ohshite(_("failed to exec tar")); } diff --git a/lib/lock.c b/lib/lock.c index ae95df34..6ae29bf5 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -78,5 +78,7 @@ void lockdatabase(const char *admindir) { ohshit(_("status database area is locked by another process")); ohshite(_("unable to lock dpkg status database")); } + n= fcntl(dblockfd, F_GETFD); + if (n >= 0) fcntl(dblockfd, F_SETFD, n | FD_CLOEXEC); push_cleanup(cu_unlockdb,~0, 0,0, 0); } diff --git a/main/archives.c b/main/archives.c index 0e87865b..72a27803 100644 --- a/main/archives.c +++ b/main/archives.c @@ -735,7 +735,7 @@ void archivefiles(const char *const *argv) { if (!(fc= m_fork())) { const char *const *ap; int i; - m_dup2(pi[1],1); close(pi[0]); + m_dup2(pi[1],1); close(pi[0]); close(pi[1]); for (i=0, ap=argv; *ap; ap++, i++); arglist= m_malloc(sizeof(char*)*(i+15)); arglist[0]= FIND; @@ -760,10 +760,10 @@ void archivefiles(const char *const *argv) { execvp(FIND, (char* const*)arglist); ohshite(_("failed to exec find for --recursive")); } + close(pi[1]); nfiles= 0; pf= fdopen(pi[0],"r"); if (!pf) ohshite(_("failed to fdopen find's pipe")); - close(pi[1]); varbufreset(&findoutput); while ((c= fgetc(pf)) != EOF) { varbufaddc(&findoutput,c); diff --git a/main/configure.c b/main/configure.c index fe69e475..f3d407d5 100644 --- a/main/configure.c +++ b/main/configure.c @@ -546,7 +546,7 @@ static void md5hash(struct pkginfo *pkg, char hashbuf[33], const char *fn) { m_pipe(p1); push_cleanup(cu_closepipe,ehflag_bombout, 0,0, 1,(void*)&p1[0]); if (!(c1= m_fork())) { - m_dup2(fd,0); m_dup2(p1[1],1); close(p1[0]); + m_dup2(fd,0); m_dup2(p1[1],1); close(p1[0]); close(p1[1]); execlp(MD5SUM,MD5SUM,(char*)0); ohshite(_("failed to exec md5sum")); } diff --git a/main/filesdb.c b/main/filesdb.c index 182e130d..1545c317 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -479,6 +480,8 @@ void ensure_diversions(void) { fclose(file); onerr_abort--; return; } } + l= fcntl(fileno(file), F_GETFD); + if (l >= 0) fcntl(fileno(file), F_SETFD, l | FD_CLOEXEC); if (diversionsfile) fclose(diversionsfile); diversionsfile= file; -- 2.39.5