[Devel] [PATCH 5/8] cr_tests: simple: Fix stdio

Matt Helsley matthltc at us.ibm.com
Tue Mar 9 14:48:17 PST 2010


The perror() after calling checkpoint() is useless -- stderr is closed.
Fix it by using dup2() to redirect stderr to the specified file. Do
the same for stdout just in case we want to use printf later.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 simple/ckpt.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/simple/ckpt.c b/simple/ckpt.c
index 739eb0a..2f7d0bb 100644
--- a/simple/ckpt.c
+++ b/simple/ckpt.c
@@ -62,8 +62,8 @@ int main(int argc, char *argv[])
 
 	/* TODO these may no longer need to be closed? */
 	close(0);
-	close(1);
-	close(2);
+	dup2(fileno(file), 1);
+	dup2(fileno(file), 2);
 
 	fprintf(file, "hello, world!\n");
 	fflush(file);
-- 
1.6.3.3

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




More information about the Devel mailing list