diff options
author | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2012-11-20 23:55:03 +0000 |
---|---|---|
committer | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2012-11-20 23:55:03 +0000 |
commit | 76c9067b47078a3d01fad44e1f95d70f3bc0f57a (patch) | |
tree | 626a06b8922c07136e46d5c1ff0a748715ea0635 /src | |
parent | 839f4efec60a066326106d5db9538a00d0faaf6d (diff) |
Check for errors when redirecting stdout/stderr
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4919 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/main/CommandLine.c | 23 |
1 files 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); } |