Преглед на файлове

libdpkg: Set close-on-exec for the debug output

This fixes a file descriptor leak on dselect subprocesses.
Guillem Jover преди 12 години
родител
ревизия
d3d2ba1dd3
променени са 4 файла, в които са добавени 8 реда и са изтрити 3 реда
  1. 1 0
      debian/changelog
  2. 1 1
      dselect/main.cc
  3. 5 1
      lib/dpkg/debug.c
  4. 1 1
      lib/dpkg/debug.h

+ 1 - 0
debian/changelog

@@ -12,6 +12,7 @@ dpkg (1.17.12) UNRELEASED; urgency=low
   * Add new architecture columns to dselect package list view. The new
   * Add new architecture columns to dselect package list view. The new
     columns, shown by default, can be turned off with the new ‘A’ key,
     columns, shown by default, can be turned off with the new ‘A’ key,
     or bound to another key via the new “archdisplay” keybinding.
     or bound to another key via the new “archdisplay” keybinding.
+  * Fix a descriptor leak on dselect subprocesses when --debug is used.
 
 
   [ Updated programs translations ]
   [ Updated programs translations ]
   * German (Sven Joachim).
   * German (Sven Joachim).

+ 1 - 1
dselect/main.cc

@@ -231,7 +231,7 @@ extern "C" {
     if (!fp)
     if (!fp)
       ohshite(_("couldn't open debug file `%.255s'\n"), v);
       ohshite(_("couldn't open debug file `%.255s'\n"), v);
 
 
-    debug_set_output(fp);
+    debug_set_output(fp, v);
     debug_set_mask(dbg_general | dbg_depcon);
     debug_set_mask(dbg_general | dbg_depcon);
   }
   }
 
 

+ 5 - 1
lib/dpkg/debug.c

@@ -25,6 +25,7 @@
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
+#include <dpkg/dpkg.h>
 #include <dpkg/report.h>
 #include <dpkg/report.h>
 #include <dpkg/debug.h>
 #include <dpkg/debug.h>
 
 
@@ -33,10 +34,13 @@ static FILE *debug_output = NULL;
 
 
 /**
 /**
  * Set the debugging output file.
  * Set the debugging output file.
+ *
+ * Marks the file descriptor as close-on-exec.
  */
  */
 void
 void
-debug_set_output(FILE *output)
+debug_set_output(FILE *output, const char *filename)
 {
 {
+	setcloexec(fileno(output), filename);
 	dpkg_set_report_buffer(output);
 	dpkg_set_report_buffer(output);
 	debug_output = output;
 	debug_output = output;
 }
 }

+ 1 - 1
lib/dpkg/debug.h

@@ -54,7 +54,7 @@ enum debugflags {
 	dbg_triggersstupid = 040000,
 	dbg_triggersstupid = 040000,
 };
 };
 
 
-void debug_set_output(FILE *output);
+void debug_set_output(FILE *output, const char *filename);
 void debug_set_mask(int mask);
 void debug_set_mask(int mask);
 bool debug_has_flag(int flag);
 bool debug_has_flag(int flag);
 void debug(int flag, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
 void debug(int flag, const char *fmt, ...) DPKG_ATTR_PRINTF(2);