aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/helper/log.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/helper/log.c b/src/helper/log.c
index e7af803c..891613d3 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -251,9 +251,15 @@ COMMAND_HANDLER(handle_log_output_command)
{
if (CMD_ARGC == 1) {
FILE *file = fopen(CMD_ARGV[0], "w");
-
- if (file)
- log_output = file;
+ if (file == NULL) {
+ LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]);
+ return ERROR_FAIL;
+ }
+ if (log_output != stderr && log_output != NULL) {
+ /* Close previous log file, if it was open and wasn't stderr. */
+ fclose(log_output);
+ }
+ log_output = file;
}
return ERROR_OK;