--
James Hunt
____________________________________
http://upstart.ubuntu.com/cookbook
http://upstart.ubuntu.com/cookbook/upstart_cookbook.pdf
=== modified file 'ChangeLog'
--- ChangeLog	2012-03-07 12:13:28 +0000
+++ ChangeLog	2012-03-16 08:53:54 +0000
@@ -1,3 +1,11 @@
+2012-03-16  James Hunt  <[email protected]>
+
+	[ Steve Langasek <[email protected]> ]
+	* init/tests/test_job_process:
+	  - close_all_files(): New function to ensure test environment
+	    has only expected fds open.
+	  - main(): Call close_all_files().
+
 2012-03-07  James Hunt  <[email protected]>
 
 	* init/job.c: job_new(): Initialize log array.

=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c	2012-03-07 12:13:28 +0000
+++ init/tests/test_job_process.c	2012-03-16 08:53:54 +0000
@@ -154,7 +154,7 @@
 static char *argv0;
 
 static int get_available_pty_count (void) __attribute__((unused));
-
+static void close_all_files (void);
 
 /**
  * fd_valid:
@@ -391,6 +391,22 @@
 	return max - nr;
 }
 
+/* Helper function to close all fds above 2, in case any have been leaked
+ * to us from the environment (and thence to the child process)
+ */
+static void
+close_all_files (void)
+{
+	unsigned long i;
+	struct rlimit rlim;
+
+	if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
+		return;
+
+	for (i = 3; i < rlim.rlim_cur; i++)
+		close(i);
+}
+
 /* XXX: Note that none of these tests attempts to test with a Session
  * passed to job_class_new() since to do so would modify the home
  * directory of the user running these tests (BAD!!).
@@ -8616,6 +8632,8 @@
 		exit (1);
 	}
 
+	close_all_files (); 
+
 	job_class_init ();
 	nih_error_init ();
 	nih_io_init ();

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to