diff options
-rw-r--r-- | abrt.spec | 2 | ||||
-rw-r--r-- | lib/plugins/Logger.conf | 6 | ||||
-rw-r--r-- | lib/plugins/Logger.cpp | 132 | ||||
-rw-r--r-- | lib/plugins/Logger.h | 41 | ||||
-rw-r--r-- | lib/plugins/Makefile.am | 10 | ||||
-rw-r--r-- | src/daemon/abrt-action-print.cpp | 19 |
6 files changed, 15 insertions, 195 deletions
@@ -417,8 +417,6 @@ fi %files plugin-logger %defattr(-,root,root,-) -%config(noreplace) %{_sysconfdir}/%{name}/plugins/Logger.conf -%{_libdir}/%{name}/libLogger.so* %{_libdir}/%{name}/Logger.glade %{_mandir}/man7/abrt-Logger.7.gz %{_bindir}/abrt-action-print diff --git a/lib/plugins/Logger.conf b/lib/plugins/Logger.conf deleted file mode 100644 index f96c5b80..00000000 --- a/lib/plugins/Logger.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Configuration for Logger plugin -Enabled = yes - -LogPath = /var/log/abrt.log - -AppendLogs = yes diff --git a/lib/plugins/Logger.cpp b/lib/plugins/Logger.cpp deleted file mode 100644 index 8a47319f..00000000 --- a/lib/plugins/Logger.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - Logger.cpp - it simply writes report to a specified file - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "abrtlib.h" -#include "comm_layer_inner.h" -#include "abrt_exception.h" -#include "Logger.h" - -using namespace std; - -CLogger::CLogger() -{ - m_pSettings["LogPath"] = "/var/log/abrt.log"; - m_pSettings["AppendLogs"] = "yes"; -} - -CLogger::~CLogger() -{ -} - -void CLogger::SetSettings(const map_plugin_settings_t& pSettings) -{ - /* Can't simply do this: - - m_pSettings = pSettings; - - * - it will erase keys which aren't present in pSettings. - * Example: if Bugzilla.conf doesn't have "Login = foo", - * then there's no pSettings["Login"] and m_pSettings = pSettings - * will nuke default m_pSettings["Login"] = "", - * making GUI think that we have no "Login" key at all - * and thus never overriding it - even if it *has* an override! - */ - - map_plugin_settings_t::iterator it = m_pSettings.begin(); - while (it != m_pSettings.end()) - { - map_plugin_settings_t::const_iterator override = pSettings.find(it->first); - if (override != pSettings.end()) - { - VERB3 log(" logger settings[%s]='%s'", it->first.c_str(), it->second.c_str()); - it->second = override->second; - } - it++; - } -} - -string CLogger::Report(const map_crash_data_t& crash_data, - const map_plugin_settings_t& pSettings, - const char *pArgs) -{ - const char *log_path = "/var/log/abrt.log"; - bool append_logs = true; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("LogPath"); - if (it != end) - log_path = it->second.c_str(); - it = pSettings.find("AppendLogs"); - if (it != end) - append_logs = string_to_bool(it->second.c_str()); - - /* open, not fopen - want to set mode if we create the file, not just open */ - int fd = open(log_path, append_logs ? O_WRONLY|O_CREAT|O_APPEND : O_WRONLY|O_CREAT|O_TRUNC, 0600); - if (fd < 0) - throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'", log_path); - - update_client(_("Writing report to '%s'"), log_path); - - /* abrt-action-print -d DIR NULL */ - char *argv[4]; - char **pp = argv; - *pp++ = (char*)"abrt-action-print"; - *pp++ = (char*)"-d"; - *pp++ = (char*)get_crash_data_item_content_or_NULL(crash_data, CD_DUMPDIR); - *pp = NULL; - int pipefds[2]; - pid_t pid = fork_execv_on_steroids(EXECFLG_OUTPUT, // + EXECFLG_ERR2OUT, - argv, - pipefds, - /* unsetenv_vec: */ NULL, - /* dir: */ NULL, - /* uid(unused): */ 0 - ); - - /* Consume log from stdout, write it to log file */ - FILE *fp = fdopen(pipefds[0], "r"); - if (!fp) - die_out_of_memory(); - char *buf; - while ((buf = xmalloc_fgets(fp)) != NULL) - { - full_write_str(fd, buf); - } - fclose(fp); /* this also closes pipefds[0] */ - /* wait for child to actually exit, and prevent leaving a zombie behind */ - waitpid(pid, NULL, 0); - - /* Add separating empty lines, then close log file */ - full_write_str(fd, "\n\n\n"); - close(fd); - - const char *format = append_logs ? _("The report was appended to %s") : _("The report was stored to %s"); - return ssprintf(format, log_path); -} - -PLUGIN_INFO(REPORTER, - CLogger, - "Logger", - "0.0.1", - _("Writes report to a file"), - "zprikryl@redhat.com", - "https://fedorahosted.org/abrt/wiki", - PLUGINS_LIB_DIR"/Logger.glade"); diff --git a/lib/plugins/Logger.h b/lib/plugins/Logger.h deleted file mode 100644 index afe1b7c2..00000000 --- a/lib/plugins/Logger.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Logger.h - header file for Logger reporter plugin - - it simply writes report to specific file - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef LOGGER_H_ -#define LOGGER_H_ - -#include "plugin.h" -#include "reporter.h" - -class CLogger : public CReporter -{ - public: - CLogger(); - ~CLogger(); - - virtual void SetSettings(const map_plugin_settings_t& pSettings); - - virtual std::string Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs); -}; - -#endif /* LOGGER_H_ */ diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am index 02112215..2f1e7966 100644 --- a/lib/plugins/Makefile.am +++ b/lib/plugins/Makefile.am @@ -4,7 +4,6 @@ pluginslib_LTLIBRARIES = \ libCCpp.la \ libMailx.la \ libSQLite3.la \ - libLogger.la \ libKerneloopsScanner.la\ libKerneloops.la \ libKerneloopsReporter.la \ @@ -28,7 +27,6 @@ dist_pluginsconf_DATA = \ CCpp.conf \ Mailx.conf \ SQLite3.conf \ - Logger.conf \ Kerneloops.conf \ Bugzilla.conf \ RHTSupport.conf \ @@ -55,8 +53,7 @@ $(DESTDIR)/$(DEBUG_INFO_DIR): install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) sed 's: = /var/: = $(localstatedir)/:g' -i \ - $(DESTDIR)$(sysconfdir)/abrt/plugins/SQLite3.conf \ - $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf + $(DESTDIR)$(sysconfdir)/abrt/plugins/SQLite3.conf INC_PATH=$(srcdir)/../../inc UTILS_PATH=$(srcdir)/../utils @@ -97,11 +94,6 @@ libSQLite3_la_LDFLAGS = -avoid-version libSQLite3_la_LIBADD = $(SQLITE3_LIBS) $(GLIB_LIBS) libSQLite3_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(SQLITE3_CFLAGS) -DLOCALSTATEDIR='"$(localstatedir)"' $(GLIB_CFLAGS) -# Logger -libLogger_la_SOURCES = Logger.cpp Logger.h -libLogger_la_LDFLAGS = -avoid-version -libLogger_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" - # SOSreport libSOSreport_la_SOURCES = SOSreport.cpp SOSreport.h libSOSreport_la_LDFLAGS = -avoid-version diff --git a/src/daemon/abrt-action-print.cpp b/src/daemon/abrt-action-print.cpp index 75f5bd92..437387e1 100644 --- a/src/daemon/abrt-action-print.cpp +++ b/src/daemon/abrt-action-print.cpp @@ -28,6 +28,7 @@ static const char *dump_dir_name = "."; static const char *output_file = NULL; +static const char *open_mode = "w"; int main(int argc, char **argv) { @@ -52,9 +53,13 @@ int main(int argc, char **argv) OPT_END() }; -//BITROT: restore handling of: -// $Logger_AppendLogs=yes -// $Logger_LogPath=/var/log/abrt.log + char *env = getenv("Logger_LogPath"); + if (env) + output_file = env; + + env = getenv("Logger_AppendLogs"); + if (env && string_to_bool(env)) + open_mode = "a"; /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); @@ -62,7 +67,7 @@ int main(int argc, char **argv) if (output_file) { - if (!freopen(output_file, "w", stdout)) + if (!freopen(output_file, open_mode, stdout)) { perror_msg_and_die("Can't open '%s'", output_file); } @@ -89,6 +94,10 @@ int main(int argc, char **argv) } if (output_file) - log("The report was stored to %s", output_file); + { + const char *format = (open_mode[0] == 'a' ? _("The report was appended to %s") : _("The report was stored to %s")); + log(format, output_file); + } + return 0; } |