diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-26 13:21:07 +0100 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-26 13:21:07 +0100 |
commit | 7ca9930ec1fc0aef059a2d8e81f7db6b3c1085ce (patch) | |
tree | f08ad3a408d5ae61b8ea6e483016cf45d722a491 | |
parent | 286312ff8017b4d0c0521a3f7c595c85b6f57c52 (diff) | |
download | abrt-7ca9930ec1fc0aef059a2d8e81f7db6b3c1085ce.tar.gz abrt-7ca9930ec1fc0aef059a2d8e81f7db6b3c1085ce.tar.xz abrt-7ca9930ec1fc0aef059a2d8e81f7db6b3c1085ce.zip |
reorganize libraries
This patch does not change any code per se,
it renames libABRTfoo -> libabrt_bar and moves a few functions around.
After the patch, we are left with the following libs:
libabrt - the stuff shared among most of abrt (like xmalloc, logging)
libabrt_daemon - only daemon-related things are here
(should probably be just moved into daemon - later)
libabrt_dbus - daemon, cli and applet use this
libabrt_web - abrt-action-foo where foo deals with network/web/ftp/...
As a result, we have following reductions in dependent libs:
/usr/libexec/abrt-hook-ccpp:
linux-vdso.so.1 => ()
- libABRTUtils.so.0 => /usr/lib64/libABRTUtils.so.0 ()
+ libabrt.so.0 => /usr/lib64/libabrt.so.0 ()
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 ()
- libdbus-1.so.3 => /lib64/libdbus-1.so.3 ()
- libpthread.so.0 => /lib64/libpthread.so.0 ()
- librt.so.1 => /lib64/librt.so.1 ()
- libdl.so.2 => /lib64/libdl.so.2 ()
/usr/libexec/abrt-action-upload:
linux-vdso.so.1 => ()
libtar.so.1 => /usr/lib64/libtar.so.1 ()
libcurl.so.4 => /usr/lib64/libcurl.so.4 ()
- libABRTdUtils.so.0 => /usr/lib64/libABRTdUtils.so.0 ()
- libABRTUtils.so.0 => /usr/lib64/libABRTUtils.so.0 ()
+ libabrt.so.0 => /usr/lib64/libabrt.so.0 ()
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 ()
- libdbus-1.so.3 => /lib64/libdbus-1.so.3 ()
Similar savings are in almost every abrt-action-foo.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r-- | src/applet/Makefile.am | 5 | ||||
-rw-r--r-- | src/btparser/Makefile.am | 2 | ||||
-rw-r--r-- | src/cli/Makefile.am | 4 | ||||
-rw-r--r-- | src/cli/report.cpp | 3 | ||||
-rw-r--r-- | src/daemon/Makefile.am | 12 | ||||
-rw-r--r-- | src/daemon/rpm.c | 24 | ||||
-rw-r--r-- | src/daemon/rpm.h | 2 | ||||
-rw-r--r-- | src/hooks/Makefile.am | 5 | ||||
-rw-r--r-- | src/include/abrtlib.h | 22 | ||||
-rw-r--r-- | src/include/plugin.h | 22 | ||||
-rw-r--r-- | src/lib/Makefile.am | 81 | ||||
-rw-r--r-- | src/lib/Plugin.cpp | 75 | ||||
-rw-r--r-- | src/lib/abrt_packages.h | 33 | ||||
-rw-r--r-- | src/lib/daemon_is_ok.c (renamed from src/lib/abrt_packages.c) | 50 | ||||
-rw-r--r-- | src/lib/get_cmdline.c (renamed from src/lib/daemon.c) | 34 | ||||
-rw-r--r-- | src/lib/load_plugin_settings.cpp | 94 | ||||
-rw-r--r-- | src/lib/make_descr.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 32 | ||||
-rw-r--r-- | src/plugins/abrt-action-bugzilla.cpp | 2 | ||||
-rw-r--r-- | src/plugins/abrt-action-kerneloops.cpp | 2 | ||||
-rw-r--r-- | src/plugins/abrt-action-mailx.cpp | 5 | ||||
-rw-r--r-- | src/plugins/abrt-action-print.cpp | 1 | ||||
-rw-r--r-- | src/plugins/abrt-action-rhtsupport.cpp | 3 | ||||
-rw-r--r-- | src/plugins/abrt-action-upload.cpp | 3 |
24 files changed, 250 insertions, 268 deletions
diff --git a/src/applet/Makefile.am b/src/applet/Makefile.am index 32d38b1f..4207e818 100644 --- a/src/applet/Makefile.am +++ b/src/applet/Makefile.am @@ -22,14 +22,13 @@ abrt_applet_CPPFLAGS = \ # $(LIBNOTIFY_CFLAGS) # $(DBUS_GLIB_CFLAGS) abrt_applet_LDADD = \ - ../lib/libABRTUtils.la \ + ../lib/libabrt.la \ + ../lib/libabrt_dbus.la \ -lglib-2.0 \ -lgthread-2.0 \ $(DBUS_LIBS) \ $(LIBNOTIFY_LIBS) \ $(GTK_LIBS) -# ../../lib/Utils/libABRTdUtils.la -# $(DL_LIBS) DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ diff --git a/src/btparser/Makefile.am b/src/btparser/Makefile.am index d69a68ba..349483a8 100644 --- a/src/btparser/Makefile.am +++ b/src/btparser/Makefile.am @@ -15,7 +15,7 @@ libbtparser_la_SOURCES = \ utils.h utils.c libbtparser_la_CFLAGS = -Wall -Werror -D_GNU_SOURCE -I../lib libbtparser_la_LDFLAGS = -version-info 1:1:0 -libbtparser_la_LIBADD = ../lib/libABRTUtils.la +libbtparser_la_LIBADD = ../lib/libabrt.la # From http://www.seul.org/docs/autotut/ # Version consists 3 numbers: CURRENT, REVISION, AGE. diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index bbfaa9d0..3584fd6c 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -16,8 +16,8 @@ abrt_cli_CPPFLAGS = \ # $(GTK_CFLAGS) abrt_cli_LDADD = \ - ../lib/libABRTUtils.la \ - ../lib/libABRTdUtils.la \ + ../lib/libabrt.la \ + ../lib/libabrt_dbus.la \ $(GLIB_LIBS) man_MANS = abrt-cli.1 diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 1378b6b0..78a38916 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -21,7 +21,6 @@ #include "run-command.h" #include "dbus.h" #include "abrtlib.h" -#include "plugin.h" // LoadPluginSettings /* Field separator for the crash report file that is edited by user. */ #define FIELD_SEP "%----" @@ -534,7 +533,7 @@ static void get_reporter_plugin_settings(const vector_string_t& reporters, { map_string_t single_plugin_settings; std::string path = std::string(homedir) + "/.abrt/" - + it->first + "."PLUGINS_CONF_EXTENSION; + + it->first + ".conf"; /* Load plugin config in the home dir. Do not skip lines with empty value (but containing a "key="), because user may want to override password from /etc/abrt/plugins/*.conf, but he prefers to enter it every time he reports. */ diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index c53af01b..34c7aa7b 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -36,8 +36,9 @@ abrtd_CPPFLAGS = \ abrtd_LDADD = \ $(DL_LIBS) \ $(DBUS_LIBS) \ - ../lib/libABRTUtils.la \ - ../lib/libABRTdUtils.la + ../lib/libabrt.la \ + ../lib/libabrt_daemon.la \ + ../lib/libabrt_dbus.la abrt_server_SOURCES = \ abrt-server.c @@ -54,7 +55,7 @@ abrt_server_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_server_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_handle_crashdump_SOURCES = \ abrt-handle-crashdump.c @@ -73,7 +74,7 @@ abrt_handle_crashdump_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_handle_crashdump_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_save_package_data_SOURCES = \ rpm.h rpm.c \ @@ -95,8 +96,7 @@ abrt_action_save_package_data_CPPFLAGS = \ -Wall -Werror abrt_action_save_package_data_LDADD = \ $(RPM_LIBS) \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt.la dbusabrtconfdir = ${sysconfdir}/dbus-1/system.d/ dist_dbusabrtconf_DATA = dbus-abrt.conf diff --git a/src/daemon/rpm.c b/src/daemon/rpm.c index 52ab8ac0..a726d357 100644 --- a/src/daemon/rpm.c +++ b/src/daemon/rpm.c @@ -26,6 +26,30 @@ static GList *list_fingerprints = NULL; +/* cuts the name from the NVR format: foo-1.2.3-1.el6 + returns a newly allocated string +*/ +char* get_package_name_from_NVR_or_NULL(const char* packageNVR) +{ + char* package_name = NULL; + if (packageNVR != NULL) + { + VERB1 log("packageNVR %s", packageNVR); + package_name = xstrdup(packageNVR); + char *pos = strrchr(package_name, '-'); + if (pos != NULL) + { + *pos = 0; + pos = strrchr(package_name, '-'); + if (pos != NULL) + { + *pos = 0; + } + } + } + return package_name; +} + void rpm_init() { int status = rpmReadConfigFiles((const char*)NULL, (const char*)NULL); diff --git a/src/daemon/rpm.h b/src/daemon/rpm.h index 4a82dee9..12b11ca8 100644 --- a/src/daemon/rpm.h +++ b/src/daemon/rpm.h @@ -80,6 +80,8 @@ char* rpm_get_package_nvr(const char* filename); */ char* rpm_get_component(const char* filename); +char* get_package_name_from_NVR_or_NULL(const char* packageNVR); + #ifdef __cplusplus } #endif diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am index 76fe84c9..2f57d2e7 100644 --- a/src/hooks/Makefile.am +++ b/src/hooks/Makefile.am @@ -12,7 +12,7 @@ abrt_hook_ccpp_CPPFLAGS = \ -DVAR_RUN=\"$(VAR_RUN)\" \ -D_GNU_SOURCE abrt_hook_ccpp_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la # dumpoops dumpoops_SOURCES = \ @@ -30,7 +30,8 @@ dumpoops_CPPFLAGS = \ -D_GNU_SOURCE # build will succeed, but at runtime plugins do need ABRT*d*Utils dumpoops_LDADD = \ - ../lib/libABRTUtils.la \ + ../lib/libabrt_daemon.la \ + ../lib/libabrt.la \ $(GLIB_FLAGS) python_PYTHON = abrt.pth abrt_exception_handler.py diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index f069d311..cbaafc60 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -80,7 +80,6 @@ int vdprintf(int d, const char *format, va_list ap); #include "crash_types.h" #include "dump_dir.h" #include "abrt_types.h" -#include "abrt_packages.h" #ifdef __cplusplus @@ -254,6 +253,27 @@ std::string to_string(T x) void parse_args(const char *psArgs, vector_string_t& pArgs, int quote = -1); void parse_release(const char *pRelease, char **product, char **version); +char* make_description_bz(const map_crash_data_t& pCrashData); +char* make_description_reproduce_comment(const map_crash_data_t& pCrashData); +char* make_description_logger(const map_crash_data_t& pCrashData); +char* make_description_mailx(const map_crash_data_t& pCrashData); + +/** + * Loads settings and stores it in second parameter. On success it + * returns true, otherwise returns false. + * + * @param path A path of config file. + * Config file consists of "key=value" lines. + * @param settings A readed plugin's settings. + * @param skipKeysWithoutValue + * If true, lines in format "key=" (without value) are skipped. + * Otherwise empty value "" is inserted into pSettings. + * @return if it success it returns true, otherwise it returns false. + */ +extern bool LoadPluginSettings(const char *pPath, + map_plugin_settings_t& pSettings, + bool skipKeysWithoutValue = true); + // TODO: npajkovs: full rewrite ssprintf -> xasprintf static inline std::string ssprintf(const char *format, ...) { diff --git a/src/include/plugin.h b/src/include/plugin.h index e0f45b6c..0ab85617 100644 --- a/src/include/plugin.h +++ b/src/include/plugin.h @@ -110,26 +110,4 @@ typedef struct SPluginInfo PLUGINS_MAGIC_NUMBER,\ }; -/* helper functions */ -char* make_description_bz(const map_crash_data_t& pCrashData); -char* make_description_reproduce_comment(const map_crash_data_t& pCrashData); -char* make_description_logger(const map_crash_data_t& pCrashData); -char* make_dsc_mailx(const map_crash_data_t& pCrashData); - -/** - * Loads settings and stores it in second parameter. On success it - * returns true, otherwise returns false. - * - * @param path A path of config file. - * Config file consists of "key=value" lines. - * @param settings A readed plugin's settings. - * @param skipKeysWithoutValue - * If true, lines in format "key=" (without value) are skipped. - * Otherwise empty value "" is inserted into pSettings. - * @return if it success it returns true, otherwise it returns false. - */ -extern bool LoadPluginSettings(const char *pPath, - map_plugin_settings_t& pSettings, - bool skipKeysWithoutValue = true); - #endif diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 0561e316..92f5e645 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,10 +1,13 @@ -# ABRTUtils has small set of deps. This reduces deps of smaller abrt binaries -# ABRTdUtils has much more. It is used by daemon and plugins only -# ABRT_web_utils is used only by some abrt-action-foo programs, not by daemon +# libabrt - the stuff shared among most of abrt (like xmalloc, logging) +# libabrt_daemon - only daemon/server/dbus related things are here +# libabrt_dbus - daemon, cli and applet use this +# libabrt_web - abrt-action-foo where foo deals with network/web/ftp/... lib_LTLIBRARIES = \ - libABRTUtils.la \ - libABRTdUtils.la \ - libABRT_web_utils.la + libabrt.la \ + libabrt_daemon.la \ + libabrt_dbus.la \ + libabrt_web.la + HEADER_DIR = $(srcdir)/../include AM_CPPFLAGS = -I$(HEADER_DIR) @@ -12,11 +15,8 @@ AM_CPPFLAGS = -I$(HEADER_DIR) # time.cpp # xconnect.cpp -libABRTUtils_la_SOURCES = \ +libabrt_la_SOURCES = \ xfuncs.c \ - concat_path_file.c \ - append_to_malloced_string.c \ - overlapping_strcpy.c \ encbase64.c \ stdio_helpers.c \ hash_md5.c hash_md5.h \ @@ -24,22 +24,44 @@ libABRTUtils_la_SOURCES = \ read_write.c read_write.h \ logging.c logging.h \ copyfd.c \ - daemon.c \ + concat_path_file.c \ + append_to_malloced_string.c \ + overlapping_strcpy.c \ skip_whitespace.c \ + stringops.cpp \ + strbuf.c strbuf.h \ xatonum.c numtoa.cpp \ spawn.c \ - stringops.cpp \ dirsize.c \ dump_dir.c \ - strbuf.c strbuf.h \ - abrt_dbus.c abrt_dbus.h \ + get_cmdline.c \ + daemon_is_ok.c \ + load_plugin_settings.cpp \ + make_descr.cpp \ + run_event.c \ CrashTypes.cpp \ ABRTException.cpp \ - run_event.c \ - abrt_packages.c abrt_packages.h \ hooklib.c hooklib.h \ + parse_release.cpp \ parse_options.c parse_options.h -libABRTUtils_la_CPPFLAGS = \ +libabrt_la_CPPFLAGS = \ + -Wall -Werror \ + -I$(srcdir)/../include \ + -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ + -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ + -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ + -DCONF_DIR=\"$(CONF_DIR)\" \ + -DVAR_RUN=\"$(VAR_RUN)\" \ + $(GLIB_CFLAGS) \ + -D_GNU_SOURCE +libabrt_la_LDFLAGS = \ + -version-info 0:1:0 +libabrt_la_LIBADD = \ + $(GLIB_LIBS) + +libabrt_dbus_la_SOURCES = \ + abrt_dbus.c abrt_dbus.h +libabrt_dbus_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ @@ -50,19 +72,16 @@ libABRTUtils_la_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ -D_GNU_SOURCE -libABRTUtils_la_LDFLAGS = \ +libabrt_dbus_la_LDFLAGS = \ -version-info 0:1:0 -libABRTUtils_la_LIBADD = \ +libabrt_dbus_la_LIBADD = \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ - -ldl + $(DBUS_LIBS) -libABRTdUtils_la_SOURCES = \ - parse_release.cpp \ - make_descr.cpp \ +libabrt_daemon_la_SOURCES = \ $(HEADER_DIR)/comm_layer_inner.h CommLayerInner.cpp \ $(HEADER_DIR)/plugin.h Plugin.cpp -libABRTdUtils_la_CPPFLAGS = \ +libabrt_daemon_la_CPPFLAGS = \ -Wall \ -I$(srcdir)/../include \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ @@ -71,15 +90,15 @@ libABRTdUtils_la_CPPFLAGS = \ -DCONF_DIR=\"$(CONF_DIR)\" \ -DVAR_RUN=\"$(VAR_RUN)\" \ -D_GNU_SOURCE -libABRTdUtils_la_LDFLAGS = \ +libabrt_daemon_la_LDFLAGS = \ -version-info 0:1:0 -libABRTdUtils_la_LIBADD = \ +libabrt_daemon_la_LIBADD = \ -ldl -libABRT_web_utils_la_SOURCES = \ +libabrt_web_la_SOURCES = \ abrt_curl.h abrt_curl.c \ abrt_xmlrpc.h abrt_xmlrpc.cpp -libABRT_web_utils_la_CPPFLAGS = \ +libabrt_web_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ @@ -91,9 +110,9 @@ libABRT_web_utils_la_CPPFLAGS = \ $(LIBXML_CFLAGS) \ $(XMLRPC_CFLAGS) $(XMLRPC_CLIENT_CFLAGS) \ -D_GNU_SOURCE -libABRT_web_utils_la_LDFLAGS = \ +libabrt_web_la_LDFLAGS = \ -version-info 0:1:0 -libABRT_web_utils_la_LIBADD = \ +libabrt_web_la_LIBADD = \ $(CURL_LIBS) \ $(LIBXML_LIBS) \ $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) diff --git a/src/lib/Plugin.cpp b/src/lib/Plugin.cpp index bf237959..0c2137f5 100644 --- a/src/lib/Plugin.cpp +++ b/src/lib/Plugin.cpp @@ -39,78 +39,3 @@ void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) } } } - -bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, - bool skipKeysWithoutValue /*= true*/) -{ - FILE *fp = stdin; - if (strcmp(pPath, "-") != 0) - { - fp = fopen(pPath, "r"); - if (!fp) - return false; - } - - char *line; - while ((line = xmalloc_fgetline(fp)) != NULL) - { - unsigned ii; - bool is_value = false; - bool valid = false; - bool in_quote = false; - std::string key; - std::string value; - for (ii = 0; line[ii] != '\0'; ii++) - { - if (line[ii] == '"') - { - in_quote = !in_quote; - } - if (isspace(line[ii]) && !in_quote) - { - continue; - } - if (line[ii] == '#' && !in_quote && key == "") - { - break; - } - if (line[ii] == '=' && !in_quote) - { - is_value = true; - valid = true; - continue; - } - if (!is_value) - { - key += line[ii]; - } - else - { - value += line[ii]; - } - } - - /* Skip broken or empty lines. */ - if (!valid) - goto free_line; - - /* Skip lines with empty key. */ - if (key.length() == 0) - goto free_line; - - if (skipKeysWithoutValue && value.length() == 0) - goto free_line; - - /* Skip lines with unclosed quotes. */ - if (in_quote) - goto free_line; - - pSettings[key] = value; - free_line: - free(line); - } - - if (fp != stdin) - fclose(fp); - return true; -} diff --git a/src/lib/abrt_packages.h b/src/lib/abrt_packages.h deleted file mode 100644 index 6a952f5e..00000000 --- a/src/lib/abrt_packages.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 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 ABRT_PACKAGES_H -#define ABRT_PACKAGES_H - -#ifdef __cplusplus -extern "C" { -#endif - -char* get_package_name_from_NVR_or_NULL(const char* packageNVR); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/lib/abrt_packages.c b/src/lib/daemon_is_ok.c index bbf0e729..dc1e94c9 100644 --- a/src/lib/abrt_packages.c +++ b/src/lib/daemon_is_ok.c @@ -1,6 +1,5 @@ /* - Copyright (C) 2010 ABRT team - Copyright (C) 2010 RedHat Inc + 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 @@ -18,26 +17,35 @@ */ #include "abrtlib.h" -/* cuts the name from the NVR format: foo-1.2.3-1.el6 - returns a newly allocated string -*/ -char* get_package_name_from_NVR_or_NULL(const char* packageNVR) +int daemon_is_ok() { - char* package_name = NULL; - if (packageNVR != NULL) + int fd = open(VAR_RUN"/abrtd.pid", O_RDONLY); + if (fd < 0) + { + return 0; + } + + char pid[sizeof(pid_t)*3 + 2]; + int len = read(fd, pid, sizeof(pid)-1); + close(fd); + if (len <= 0) + return 0; + + pid[len] = '\0'; + *strchrnul(pid, '\n') = '\0'; + /* paranoia: we don't want to check /proc//stat or /proc///stat */ + if (pid[0] == '\0' || pid[0] == '/') + return 0; + + char path[sizeof("/proc/%s/stat") + sizeof(pid)]; + sprintf(path, "/proc/%s/stat", pid); + struct stat sb; + if (stat(path, &sb) == -1) { - VERB1 log("packageNVR %s", packageNVR); - package_name = xstrdup(packageNVR); - char *pos = strrchr(package_name, '-'); - if (pos != NULL) - { - *pos = 0; - pos = strrchr(package_name, '-'); - if (pos != NULL) - { - *pos = 0; - } - } + return 0; } - return package_name; + + /* TODO: maybe readlink /proc/PID/exe and check that it is "xxx/abrt"? */ + + return 1; } diff --git a/src/lib/daemon.c b/src/lib/get_cmdline.c index 944aef0c..9855eb3c 100644 --- a/src/lib/daemon.c +++ b/src/lib/get_cmdline.c @@ -17,8 +17,6 @@ */ #include "abrtlib.h" -#define VAR_RUN_PID_FILE VAR_RUN"/abrtd.pid" - static char *append_escaped(char *start, const char *s) { char hex_char_buf[] = "\\x00"; @@ -105,35 +103,3 @@ char* get_cmdline(pid_t pid) return xstrdup(escaped_cmdline + 1); /* +1 skips extraneous leading space */ } - -int daemon_is_ok() -{ - int fd = open(VAR_RUN_PID_FILE, O_RDONLY); - if (fd < 0) - { - return 0; - } - - char pid[sizeof(pid_t)*3 + 2]; - int len = read(fd, pid, sizeof(pid)-1); - close(fd); - if (len <= 0) - return 0; - - pid[len] = '\0'; - *strchrnul(pid, '\n') = '\0'; - /* paranoia: we don't want to check /proc//stat or /proc///stat */ - if (pid[0] == '\0' || pid[0] == '/') - return 0; - - /* TODO: maybe readlink and check that it is "xxx/abrt"? */ - char path[sizeof("/proc/%s/stat") + sizeof(pid)]; - sprintf(path, "/proc/%s/stat", pid); - struct stat sb; - if (stat(path, &sb) == -1) - { - return 0; - } - - return 1; -} diff --git a/src/lib/load_plugin_settings.cpp b/src/lib/load_plugin_settings.cpp new file mode 100644 index 00000000..1052f19e --- /dev/null +++ b/src/lib/load_plugin_settings.cpp @@ -0,0 +1,94 @@ +/* + 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" + +bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, + bool skipKeysWithoutValue /*= true*/) +{ + FILE *fp = stdin; + if (strcmp(pPath, "-") != 0) + { + fp = fopen(pPath, "r"); + if (!fp) + return false; + } + + char *line; + while ((line = xmalloc_fgetline(fp)) != NULL) + { + unsigned ii; + bool is_value = false; + bool valid = false; + bool in_quote = false; + std::string key; + std::string value; + for (ii = 0; line[ii] != '\0'; ii++) + { + if (line[ii] == '"') + { + in_quote = !in_quote; + } + if (isspace(line[ii]) && !in_quote) + { + continue; + } + if (line[ii] == '#' && !in_quote && key == "") + { + break; + } + if (line[ii] == '=' && !in_quote) + { + is_value = true; + valid = true; + continue; + } + if (!is_value) + { + key += line[ii]; + } + else + { + value += line[ii]; + } + } + + /* Skip broken or empty lines. */ + if (!valid) + goto free_line; + + /* Skip lines with empty key. */ + if (key.length() == 0) + goto free_line; + + if (skipKeysWithoutValue && value.length() == 0) + goto free_line; + + /* Skip lines with unclosed quotes. */ + if (in_quote) + goto free_line; + + pSettings[key] = value; + free_line: + free(line); + } + + if (fp != stdin) + fclose(fp); + return true; +} diff --git a/src/lib/make_descr.cpp b/src/lib/make_descr.cpp index 90c73667..a0cb5691 100644 --- a/src/lib/make_descr.cpp +++ b/src/lib/make_descr.cpp @@ -75,7 +75,7 @@ static const char *const blacklisted_items[] = { NULL }; -char* make_dsc_mailx(const map_crash_data_t & crash_data) +char* make_description_mailx(const map_crash_data_t & crash_data) { struct strbuf *buf_dsc = strbuf_new(); struct strbuf *buf_additional_files = strbuf_new(); diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index c60c06fe..57b99e85 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -90,7 +90,7 @@ abrt_action_analyze_c_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_c_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_analyze_python_SOURCES = \ abrt-action-analyze-python.c @@ -108,7 +108,7 @@ abrt_action_analyze_python_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_python_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_analyze_oops_SOURCES = \ abrt-action-analyze-oops.c @@ -126,7 +126,7 @@ abrt_action_analyze_oops_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_analyze_oops_LDADD = \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_generate_backtrace_SOURCES = \ abrt-action-generate-backtrace.c @@ -144,7 +144,7 @@ abrt_action_generate_backtrace_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_generate_backtrace_LDADD = \ - ../lib/libABRTUtils.la \ + ../lib/libabrt.la \ ../btparser/libbtparser.la abrt_action_bugzilla_SOURCES = \ @@ -165,9 +165,8 @@ abrt_action_bugzilla_CPPFLAGS = \ -Wall -Werror abrt_action_bugzilla_LDADD = \ $(GLIB_LIBS) \ - ../lib/libABRT_web_utils.la \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt_web.la \ + ../lib/libabrt.la abrt_action_rhtsupport_SOURCES = \ abrt_rh_support.h abrt_rh_support.c \ @@ -191,9 +190,8 @@ abrt_action_rhtsupport_LDFLAGS = -ltar abrt_action_rhtsupport_LDADD = \ $(GLIB_LIBS) \ $(XMLRPC_LIBS) $(XMLRPC_CLIENT_LIBS) \ - ../lib/libABRT_web_utils.la \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt_web.la \ + ../lib/libabrt.la abrt_action_upload_SOURCES = \ abrt-action-upload.cpp @@ -217,8 +215,7 @@ abrt_action_upload_LDFLAGS = -ltar abrt_action_upload_LDADD = \ $(GLIB_LIBS) \ $(CURL_LIBS) \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_kerneloops_SOURCES = \ abrt-action-kerneloops.cpp @@ -238,9 +235,8 @@ abrt_action_kerneloops_CPPFLAGS = \ -Wall -Werror # libABRTdUtils is used only because of LoadPluginSettings: abrt_action_kerneloops_LDADD = \ - ../lib/libABRT_web_utils.la \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt_web.la \ + ../lib/libabrt.la abrt_action_mailx_SOURCES = \ abrt-action-mailx.cpp @@ -259,8 +255,7 @@ abrt_action_mailx_CPPFLAGS = \ -D_GNU_SOURCE \ -Wall -Werror abrt_action_mailx_LDADD = \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt.la abrt_action_print_SOURCES = \ abrt-action-print.cpp @@ -280,7 +275,6 @@ abrt_action_print_CPPFLAGS = \ -Wall -Werror # libABRTdUtils is used only because of make_description_logger: abrt_action_print_LDADD = \ - ../lib/libABRTdUtils.la \ - ../lib/libABRTUtils.la + ../lib/libabrt.la DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp index 62d3bd63..7b51e9aa 100644 --- a/src/plugins/abrt-action-bugzilla.cpp +++ b/src/plugins/abrt-action-bugzilla.cpp @@ -21,8 +21,6 @@ #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* make_description_bz */ - #define XML_RPC_SUFFIX "/xmlrpc.cgi" #define MAX_HOPS 5 diff --git a/src/plugins/abrt-action-kerneloops.cpp b/src/plugins/abrt-action-kerneloops.cpp index 4c820081..4ca375d1 100644 --- a/src/plugins/abrt-action-kerneloops.cpp +++ b/src/plugins/abrt-action-kerneloops.cpp @@ -22,8 +22,6 @@ #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* LoadPluginSettings */ - #define PROGNAME "abrt-action-kerneloops" /* helpers */ diff --git a/src/plugins/abrt-action-mailx.cpp b/src/plugins/abrt-action-mailx.cpp index d11a0d5f..a7f9a488 100644 --- a/src/plugins/abrt-action-mailx.cpp +++ b/src/plugins/abrt-action-mailx.cpp @@ -24,9 +24,6 @@ #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* LoadPluginSettings */ - - #define PROGNAME "abrt-action-mailx" static void exec_and_feed_input(uid_t uid, const char* text, char **args) @@ -93,7 +90,7 @@ static void create_and_send_email( unsigned arg_size = 0; args = append_str_to_vector(args, arg_size, "/bin/mailx"); - char *dsc = make_dsc_mailx(pCrashData); + char *dsc = make_description_mailx(pCrashData); if (send_binary_data) { diff --git a/src/plugins/abrt-action-print.cpp b/src/plugins/abrt-action-print.cpp index a4db373a..26bea102 100644 --- a/src/plugins/abrt-action-print.cpp +++ b/src/plugins/abrt-action-print.cpp @@ -22,7 +22,6 @@ #include "parse_options.h" #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* make_description_logger */ #define PROGNAME "abrt-action-print" diff --git a/src/plugins/abrt-action-rhtsupport.cpp b/src/plugins/abrt-action-rhtsupport.cpp index aecd30c8..a88291d0 100644 --- a/src/plugins/abrt-action-rhtsupport.cpp +++ b/src/plugins/abrt-action-rhtsupport.cpp @@ -25,9 +25,6 @@ #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* make_description_bz */ - - #define PROGNAME "abrt-action-rhtsupport" static void report_to_rhtsupport( diff --git a/src/plugins/abrt-action-upload.cpp b/src/plugins/abrt-action-upload.cpp index 0bf54bea..726b9183 100644 --- a/src/plugins/abrt-action-upload.cpp +++ b/src/plugins/abrt-action-upload.cpp @@ -24,9 +24,6 @@ #include "crash_types.h" #include "abrt_exception.h" -#include "plugin.h" /* LoadPluginSettings */ - - #define PROGNAME "abrt-action-upload" //TODO: use this for better logging |