From 6b0894cdb41d9698e593af717f4857313ea81c22 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Jan 2010 16:23:57 +0100 Subject: Logger: create log file with mode 0600 Signed-off-by: Denys Vlasenko --- lib/Plugins/Logger.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index f428aec5..3424d73d 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -63,29 +63,23 @@ std::string CLogger::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { - std::string description = make_description_logger(pCrashData); - description += "\n\n\n"; - FILE *fOut; - if (m_bAppendLogs) - { - fOut = fopen(m_sLogPath.c_str(), "a"); - } - else - { - fOut = fopen(m_sLogPath.c_str(), "w"); - } + /* open, not fopen - want to set mode if we create the file, not just open */ + const char *fname = m_sLogPath.c_str(); + int fd = open(fname, + m_bAppendLogs ? O_WRONLY|O_CREAT|O_APPEND : O_WRONLY|O_CREAT|O_TRUNC, + 0600); + if (fd < 0) + throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", fname); - if (fOut) - { - update_client(_("Writing report to '%s'"), m_sLogPath.c_str()); - fputs(description.c_str(), fOut); - fclose(fOut); - return "file://" + m_sLogPath; - } + update_client(_("Writing report to '%s'"), fname); + description += "\n\n\n"; + const char *desc = description.c_str(); + full_write(fd, desc, strlen(desc)); + close(fd); - throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", m_sLogPath.c_str()); + return "file://" + m_sLogPath; } PLUGIN_INFO(REPORTER, -- cgit