From 76c9067b47078a3d01fad44e1f95d70f3bc0f57a Mon Sep 17 00:00:00 2001 From: eschnett Date: Tue, 20 Nov 2012 23:55:03 +0000 Subject: Check for errors when redirecting stdout/stderr git-svn-id: http://svn.cactuscode.org/flesh/trunk@4919 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/main/CommandLine.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c index 4aded14f..6b4b1f2e 100644 --- a/src/main/CommandLine.c +++ b/src/main/CommandLine.c @@ -687,6 +687,7 @@ void CCTKi_CommandLineFinished (void) { int myproc; char *logfilename; + FILE *newfile; /* Are we in a paramcheck run ? */ @@ -735,17 +736,33 @@ void CCTKi_CommandLineFinished (void) if (requested_stdout_redirection) { sprintf (logfilename, "%s/CCTK_Proc%u.out", logdir, myproc); - freopen (logfilename, "w", stdout); + newfile = freopen (logfilename, "w", stdout); + if (! newfile) + { + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Could not redirect stdout to logfile '%s'", logfilename); + } } else { - freopen (NULL_DEVICE, "w", stdout); + newfile = freopen (NULL_DEVICE, "w", stdout); + if (! newfile) + { + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Could not disable stdout " + "(was trying to redirect it to '%s')", NULL_DEVICE); + } } if (requested_stderr_redirection) { sprintf (logfilename, "%s/CCTK_Proc%u.err", logdir, myproc); - freopen (logfilename, "w", stderr); + newfile = freopen (logfilename, "w", stderr); + if (! newfile) + { + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Could not redirect stderr to logfile '%s'", logfilename); + } } free (logfilename); } -- cgit v1.2.3