Просмотр исходного кода

updates from Chip Salzenberg to clean up fd handling

Wichert Akkerman лет назад: 26
Родитель
Сommit
f4e1572a28
8 измененных файлов с 18 добавлено и 5 удалено
  1. 6 0
      ChangeLog
  2. 1 0
      debian/changelog
  3. 1 1
      dpkg-deb/build.c
  4. 2 1
      dpkg-deb/extract.c
  5. 2 0
      lib/lock.c
  6. 2 2
      main/archives.c
  7. 1 1
      main/configure.c
  8. 3 0
      main/filesdb.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Mon Aug 21 12:58:15 CEST 2000 Wichert Akkerman <wakkerma@debian.org>
+
+  * 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 <peterk@debian.org>
 
   * po/sv.po: More corrections and translation updates.

+ 1 - 0
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 <wakkerma@debian.org>  UNRELEASED
 

+ 1 - 1
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]);

+ 2 - 1
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"));
     }

+ 2 - 0
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);
 }

+ 2 - 2
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);

+ 1 - 1
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"));
     }

+ 3 - 0
main/filesdb.c

@@ -22,6 +22,7 @@
 
 #include <assert.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/stat.h>
@@ -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;