From 02a1e38e6ce93dfad1a5e11e45e83cca0091c374 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 27 Apr 2017 08:46:03 -0700 Subject: [PATCH] SDL: improve error msg for unwritable config #105 Following up on 1ba2eef which fixed a crash caused by trying to write to a NULL FILE* due to fopen() failure: write the error message to stderr instead of trace.log and show the OS error using strerror_r(). --- src/common/ConfigManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 83d87a1d..0154055a 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -759,7 +759,9 @@ void SaveConfigFile() { FILE *f = fopen(configFile, "w"); if (f == NULL) { - log("Configuration file could not be opened %s\n", optarg); + char err_buf[4096]; + char* err_msg = strerror_r(errno, err_buf, 4096); + fprintf(stderr, "Configuration file '%s' could not be written to: %s\n", configFile, err_msg); return; } // Needs mixed case version of the option name to add new options into the ini