[PATCH 09/11] pthread1: Don't close stderr() before opening log

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Sukadev Bhattiprolu <sukadev@xxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Jan 2010 22:47:24 -0800
Subject: [PATCH 09/11] pthread1: Don't close stderr() before opening log

If we encounter an error while opening the log file, we write to stderr.
In which case, we need the 'stderr' to remain open at least till the log
file is open.

Signed-off-by: Sukadev Bhattiprolu <sukadev@xxxxxxxxxxxxxxxxxx>
---
 process-tree/pthread1.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/process-tree/pthread1.c b/process-tree/pthread1.c
index fa45127..d1743de 100644
--- a/process-tree/pthread1.c
+++ b/process-tree/pthread1.c
@@ -9,6 +9,10 @@
 
 int num_threads = 5;
 FILE *logfp;
+/*
+ * Use LOG_PREFIX with thread index as suffix, if each thread needs a
+ * separate log file. For now, we use a single log
+ */
 #define LOG_PREFIX		"logs.d/pthread1"
 
 static void usage(char *argv[])
@@ -137,7 +141,6 @@ main(int argc, char *argv[])
 	pthread_t *tid_list;
 	char log_file[256];
 
-	for (i=0; i<100; i++) close(i);
 	sprintf(log_file, "%s.log", LOG_PREFIX);
 
 	logfp = fopen(log_file, "w");
@@ -148,6 +151,13 @@ main(int argc, char *argv[])
 		do_exit(1);
 	}
 
+	fprintf(stderr, "Redirecting output to logfile %s\n", log_file);
+
+	for (i=0; i<100; i++) {
+		if (i != fileno(logfp))
+			close(i);
+	}
+
 	if (test_done()) {
 		printf("Remove %s before running test\n", TEST_DONE);
 		do_exit(1);
-- 
1.6.0.4

_______________________________________________
Containers mailing list
Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linux-foundation.org/mailman/listinfo/containers

[Index of Archives]     [Cgroups]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux