All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org
Cc: Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 09/11] pthread1: Don't close stderr() before opening log
Date: Fri, 29 Jan 2010 12:43:32 -0800	[thread overview]
Message-ID: <20100129204332.GH26721@us.ibm.com> (raw)
In-Reply-To: <20100129202842.GA25490-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>


From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
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-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
 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

  parent reply	other threads:[~2010-01-29 20:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-29 20:28 [PATCH 01/11] runtests.sh: Make test bit more generic Sukadev Bhattiprolu
     [not found] ` <20100129202842.GA25490-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-01-29 20:37   ` [PATCH 02/11] Make runtests.sh a wrapper for fileio tests Sukadev Bhattiprolu
2010-01-29 20:38   ` [PATCH 03/11] Check for failure while waiting for checkpoint-ready Sukadev Bhattiprolu
2010-01-29 20:42   ` [PATCH 04/11] Rename run-filelock1 to run-fcntltests.sh Sukadev Bhattiprolu
2010-01-29 20:42   ` [PATCH 05/11] Move event-notifications to libcrtest/common.c Sukadev Bhattiprolu
     [not found]     ` <20100129204228.GD26721-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-01-30  2:44       ` Serge E. Hallyn
2010-01-29 20:42   ` [PATCH 06/11] filelease1: Test restore of file leases Sukadev Bhattiprolu
2010-01-29 20:43   ` [PATCH 07/11] fsetown1: Test async I/O notification after restart Sukadev Bhattiprolu
2010-01-29 20:43   ` [PATCH 08/11] filelock1: Extend for mandatory locks Sukadev Bhattiprolu
2010-01-29 20:43   ` Sukadev Bhattiprolu [this message]
2010-01-29 20:44   ` [PATCH 10/11] filelock2: Test restart of process in F_GETLK Sukadev Bhattiprolu
2010-01-29 20:44   ` [PATCH 11/11] filelease2: Test C/R during lease-break-interval Sukadev Bhattiprolu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100129204332.GH26721@us.ibm.com \
    --to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.