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

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

This fixes a file descriptor leak on dselect subprocesses.
Guillem Jover лет назад: 12
Родитель
Сommit
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
     columns, shown by default, can be turned off with the new ‘A’ key,
     or bound to another key via the new “archdisplay” keybinding.
+  * Fix a descriptor leak on dselect subprocesses when --debug is used.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 1 - 1
dselect/main.cc

@@ -231,7 +231,7 @@ extern "C" {
     if (!fp)
       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);
   }
 

+ 5 - 1
lib/dpkg/debug.c

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

+ 1 - 1
lib/dpkg/debug.h

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