diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/Makefile.am | 22 | ||||
| -rw-r--r-- | src/include/abrt_crash_data.h (renamed from src/include/abrt_crash_dump.h) | 65 | ||||
| -rw-r--r-- | src/include/abrt_exception.h | 57 | ||||
| -rw-r--r-- | src/include/abrt_types.h | 28 | ||||
| -rw-r--r-- | src/include/abrtlib.h | 221 | ||||
| -rw-r--r-- | src/include/action.h | 44 | ||||
| -rw-r--r-- | src/include/analyzer.h | 34 | ||||
| -rw-r--r-- | src/include/comm_layer_inner.h | 61 | ||||
| -rw-r--r-- | src/include/dbus_common.h | 28 | ||||
| -rw-r--r-- | src/include/observer.h | 32 | ||||
| -rw-r--r-- | src/include/plugin.h | 113 | ||||
| -rw-r--r-- | src/include/report/crash_data.h | 101 | ||||
| -rw-r--r-- | src/include/report/dump_dir.h (renamed from src/include/dump_dir.h) | 18 | ||||
| -rw-r--r-- | src/include/report/run_event.h | 82 | ||||
| -rw-r--r-- | src/include/xfuncs.h | 38 |
15 files changed, 382 insertions, 562 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 3716d19e..477963c3 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -1,16 +1,12 @@ -HEADER_FILES = \ - abrt_exception.h \ +libreport_includedir = $(includedir)/report +libreport_include_HEADERS = \ + report/crash_data.h \ + report/dump_dir.h \ + report/run_event.h + +libabrt_includedir = $(includedir)/abrt +libabrt_include_HEADERS = \ abrtlib.h \ abrt_types.h \ - comm_layer_inner.h \ - abrt_crash_dump.h \ - dbus_common.h \ - dump_dir.h \ - observer.h \ - plugin.h \ - action.h \ - analyzer.h \ + abrt_crash_data.h \ xfuncs.h - -lib_includedir=$(includedir)/abrt/ -lib_include_HEADERS = $(HEADER_FILES) diff --git a/src/include/abrt_crash_dump.h b/src/include/abrt_crash_data.h index ed7ffe95..b71b046f 100644 --- a/src/include/abrt_crash_dump.h +++ b/src/include/abrt_crash_data.h @@ -19,8 +19,12 @@ #ifndef ABRT_CRASH_DUMP_H_ #define ABRT_CRASH_DUMP_H_ +#include "crash_data.h" #include "abrt_types.h" +// Text bigger than this usually is attached, not added inline +#define CD_TEXT_ATT_SIZE (2*1024) + // Keep in sync with CCDump.py: // Filenames in dump directory: @@ -32,7 +36,8 @@ #define FILENAME_REASON "reason" #define FILENAME_COREDUMP "coredump" #define FILENAME_BACKTRACE "backtrace" -#define FILENAME_MEMORYMAP "memorymap" +#define FILENAME_MAPS "maps" +#define FILENAME_SMAPS "smaps" #define FILENAME_DUPHASH "global_uuid" /* name is compat, to be renamed to "duphash" */ // Name of the function where the application crashed. // Optional. @@ -41,11 +46,11 @@ #define FILENAME_ARCHITECTURE "architecture" #define FILENAME_KERNEL "kernel" #define FILENAME_TIME "time" -#define FILENAME_RELEASE "release" /* from /etc/redhat-release */ -// filled by <what?> +// From /etc/syste-release or /etc/redhat-release +#define FILENAME_OS_RELEASE "os_release" +// Filled by <what?> #define FILENAME_PACKAGE "package" #define FILENAME_COMPONENT "component" -#define FILENAME_DESCRIPTION "description" /* package descr (not crash descr) */ #define FILENAME_COMMENT "comment" #define FILENAME_REPRODUCE "reproduce" #define FILENAME_RATING "rating" @@ -67,62 +72,18 @@ #define CD_EVENTS "Events" -// Crash data is a map of 3-element vectors of strings: type, editable, content -#define CD_TYPE 0 -#define CD_EDITABLE 1 -#define CD_CONTENT 2 - -// SYS - system value, should not be displayed -// BIN - binary data -// TXT - text data, can be displayed -#define CD_SYS "s" -#define CD_BIN "b" -#define CD_TXT "t" -// Text bigger than this usually is attached, not added inline -#define CD_TEXT_ATT_SIZE (2*1024) - -#define CD_ISEDITABLE "y" -#define CD_ISNOTEDITABLE "n" - - #ifdef __cplusplus extern "C" { #endif -extern const char *const must_have_files[]; - +#define is_editable_file abrt_is_editable_file bool is_editable_file(const char *file_name); +#define log_crash_data abrt_log_crash_data +void log_crash_data(crash_data_t *crash_data, const char *pfx); + #ifdef __cplusplus } #endif - -#ifdef __cplusplus - -// <key, data> -typedef map_vector_string_t map_crash_data_t; -typedef std::vector<map_crash_data_t> vector_map_crash_data_t; - -void add_to_crash_data_ext(map_crash_data_t& pCrashData, - const char *pItem, - const char *pType, - const char *pEditable, - const char *pContent); -// Uses type:CD_TXT, editable:CD_ISNOTEDITABLE -void add_to_crash_data(map_crash_data_t& pCrashData, - const char *pItem, - const char *pContent); - -void load_crash_data_from_crash_dump_dir(struct dump_dir *dd, map_crash_data_t& data); - -const char *get_crash_data_item_content_or_NULL(const map_crash_data_t& crash_data, const char *key); -// Aborts if key is not found: -const std::string& get_crash_data_item_content(const map_crash_data_t& crash_data, const char *key); - -void log_map_crash_data(const map_crash_data_t& data, const char *name); - -#endif /* __cplusplus */ - - #endif diff --git a/src/include/abrt_exception.h b/src/include/abrt_exception.h deleted file mode 100644 index b826bfa8..00000000 --- a/src/include/abrt_exception.h +++ /dev/null @@ -1,57 +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 ABRTEXCEPTION_H_ -#define ABRTEXCEPTION_H_ - -#include "abrtlib.h" - -typedef enum { - EXCEP_UNKNOW, - EXCEP_DD_OPEN, - EXCEP_DD_LOAD, - EXCEP_DD_SAVE, - EXCEP_DD_DELETE, - EXCEP_DL, - EXCEP_PLUGIN, - EXCEP_ERROR, -} abrt_exception_t; - -/* std::exception is a class with virtual members. - * deriving from it makes our ctor/dtor much more heavy, - * and those are inlined in every throw and catch site! - */ -class CABRTException /*: public std::exception*/ -{ - private: - abrt_exception_t m_type; - char *m_what; - - /* Not defined. You can't use it */ - CABRTException& operator= (const CABRTException&); - - public: - ~CABRTException() { free(m_what); } - CABRTException(abrt_exception_t type, const char* fmt, ...); - CABRTException(const CABRTException& rhs); - - abrt_exception_t type() { return m_type; } - const char* what() const { return m_what; } -}; - -#endif diff --git a/src/include/abrt_types.h b/src/include/abrt_types.h index 38804895..200946e1 100644 --- a/src/include/abrt_types.h +++ b/src/include/abrt_types.h @@ -20,6 +20,34 @@ #define ABRT_TYPES_H_ #ifdef __cplusplus +extern "C" { +#endif + +/* We can't typedef it to map_string_t, since other parts of ABRT + * (daemon, cli) still use that name for C++ container. For now, + * let's call it map_string_h: + */ +typedef GHashTable map_string_h; + +#define new_map_string abrt_new_map_string +map_string_h *new_map_string(void); +#define free_map_string abrt_free_map_string +void free_map_string(map_string_h *ms); +#define get_map_string_item_or_empty abrt_get_map_string_item_or_empty +const char *get_map_string_item_or_empty(map_string_h *ms, const char *key); +static inline +const char *get_map_string_item_or_NULL(map_string_h *ms, const char *key) +{ + return (const char*)g_hash_table_lookup(ms, key); +} + + +#ifdef __cplusplus +} +#endif + + +#ifdef __cplusplus #include <map> #include <set> diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 8cd0664a..61731587 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -42,6 +42,7 @@ #ifdef __cplusplus # include <string> #endif +#include <glib.h> #ifdef HAVE_CONFIG_H # include "config.h" @@ -77,74 +78,99 @@ int vdprintf(int d, const char *format, va_list ap); #include "hash_sha1.h" #include "hash_md5.h" -#include "abrt_crash_dump.h" -#include "dump_dir.h" +#include "abrt_crash_data.h" #include "abrt_types.h" +#include "dump_dir.h" +#include "run_event.h" #ifdef __cplusplus extern "C" { #endif +#define prefixcmp abrt_prefixcmp int prefixcmp(const char *str, const char *prefix); +#define suffixcmp abrt_suffixcmp int suffixcmp(const char *str, const char *suffix); +#define concat_path_file abrt_concat_path_file char *concat_path_file(const char *path, const char *filename); +#define append_to_malloced_string abrt_append_to_malloced_string char *append_to_malloced_string(char *mstr, const char *append); +#define skip_whitespace abrt_skip_whitespace char* skip_whitespace(const char *s); +#define skip_non_whitespace abrt_skip_non_whitespace char* skip_non_whitespace(const char *s); /* Like strcpy but can copy overlapping strings. */ +#define overlapping_strcpy abrt_overlapping_strcpy void overlapping_strcpy(char *dst, const char *src); /* A-la fgets, but malloced and of unlimited size */ +#define xmalloc_fgets abrt_xmalloc_fgets char *xmalloc_fgets(FILE *file); /* Similar, but removes trailing \n */ +#define xmalloc_fgetline abrt_xmalloc_fgetline char *xmalloc_fgetline(FILE *file); /* On error, copyfd_XX prints error messages and returns -1 */ enum { COPYFD_SPARSE = 1 << 0, }; +#define copyfd_eof abrt_copyfd_eof off_t copyfd_eof(int src_fd, int dst_fd, int flags); +#define copyfd_size abrt_copyfd_size off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags); +#define copyfd_exact_size abrt_copyfd_exact_size void copyfd_exact_size(int src_fd, int dst_fd, off_t size); +#define copy_file abrt_copy_file off_t copy_file(const char *src_name, const char *dst_name, int mode); +#define copy_file_recursive abrt_copy_file_recursive +int copy_file_recursive(const char *source, const char *dest); /* Returns malloc'ed block */ +#define encode_base64 abrt_encode_base64 char *encode_base64(const void *src, int length); +#define xatou abrt_xatou unsigned xatou(const char *numstr); +#define xatoi abrt_xatoi int xatoi(const char *numstr); /* Using xatoi() instead of naive atoi() is not always convenient - * in many places people want *non-negative* values, but store them * in signed int. Therefore we need this one: - * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */ -int xatoi_u(const char *numstr); + * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc. + * It should really be named xatoi_nonnegative (since it allows 0), + * but that would be too long. + */ +#define xatoi_positive abrt_xatoi_positive +int xatoi_positive(const char *numstr); -unsigned long long monotonic_ns(void); -unsigned long long monotonic_us(void); -unsigned monotonic_sec(void); +//unused for now +//unsigned long long monotonic_ns(void); +//unsigned long long monotonic_us(void); +//unsigned monotonic_sec(void); enum { - /* on return, pipefds[1] is fd to which parent may write - * and deliver data to child's stdin: */ - EXECFLG_INPUT = 1 << 0, - /* on return, pipefds[0] is fd from which parent may read - * child's stdout: */ - EXECFLG_OUTPUT = 1 << 1, - /* open child's stdin to /dev/null: */ - EXECFLG_INPUT_NUL = 1 << 2, - /* open child's stdout to /dev/null: */ - EXECFLG_OUTPUT_NUL = 1 << 3, - /* redirect child's stderr to stdout: */ - EXECFLG_ERR2OUT = 1 << 4, - /* open child's stderr to /dev/null: */ - EXECFLG_ERR_NUL = 1 << 5, - /* suppress perror_msg("Can't execute 'foo'") if exec fails */ - EXECFLG_QUIET = 1 << 6, - EXECFLG_SETGUID = 1 << 7, - EXECFLG_SETSID = 1 << 8, + /* on return, pipefds[1] is fd to which parent may write + * and deliver data to child's stdin: */ + EXECFLG_INPUT = 1 << 0, + /* on return, pipefds[0] is fd from which parent may read + * child's stdout: */ + EXECFLG_OUTPUT = 1 << 1, + /* open child's stdin to /dev/null: */ + EXECFLG_INPUT_NUL = 1 << 2, + /* open child's stdout to /dev/null: */ + EXECFLG_OUTPUT_NUL = 1 << 3, + /* redirect child's stderr to stdout: */ + EXECFLG_ERR2OUT = 1 << 4, + /* open child's stderr to /dev/null: */ + EXECFLG_ERR_NUL = 1 << 5, + /* suppress perror_msg("Can't execute 'foo'") if exec fails */ + EXECFLG_QUIET = 1 << 6, + EXECFLG_SETGUID = 1 << 7, + EXECFLG_SETSID = 1 << 8, }; /* Returns pid */ +#define fork_execv_on_steroids abrt_fork_execv_on_steroids pid_t fork_execv_on_steroids(int flags, char **argv, int *pipefds, @@ -153,110 +179,67 @@ pid_t fork_execv_on_steroids(int flags, uid_t uid); /* Returns malloc'ed string. NULs are retained, and extra one is appended * after the last byte (this NUL is not accounted for in *size_p) */ +#define run_in_shell_and_save_output abrt_run_in_shell_and_save_output char *run_in_shell_and_save_output(int flags, - const char *cmd, - const char *dir, - size_t *size_p); - -/* Networking helpers */ -typedef struct len_and_sockaddr { - socklen_t len; - union { - struct sockaddr sa; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } u; -} len_and_sockaddr; -enum { - LSA_LEN_SIZE = offsetof(len_and_sockaddr, u), - LSA_SIZEOF_SA = sizeof(struct sockaddr) > sizeof(struct sockaddr_in6) ? - sizeof(struct sockaddr) : sizeof(struct sockaddr_in6), -}; -void setsockopt_reuseaddr(int fd); -int setsockopt_broadcast(int fd); -int setsockopt_bindtodevice(int fd, const char *iface); -len_and_sockaddr* get_sock_lsa(int fd); -void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen); -unsigned lookup_port(const char *port, const char *protocol, unsigned default_port); -int get_nport(const struct sockaddr *sa); -void set_nport(len_and_sockaddr *lsa, unsigned port); -len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af); -len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af); -len_and_sockaddr* host2sockaddr(const char *host, int port); -len_and_sockaddr* xhost2sockaddr(const char *host, int port); -len_and_sockaddr* xdotted2sockaddr(const char *host, int port); -int xsocket_type(len_and_sockaddr **lsap, int family, int sock_type); -int xsocket_stream(len_and_sockaddr **lsap); -int create_and_bind_stream_or_die(const char *bindaddr, int port); -int create_and_bind_dgram_or_die(const char *bindaddr, int port); -int create_and_connect_stream_or_die(const char *peer, int port); -int xconnect_stream(const len_and_sockaddr *lsa); -char* xmalloc_sockaddr2host(const struct sockaddr *sa); -char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa); -char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa); -char* xmalloc_sockaddr2dotted(const struct sockaddr *sa); -char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa); + const char *cmd, + const char *dir, + size_t *size_p); /* Random utility functions */ +/* Frees every element'd data using free(), + * then frees list itself using g_list_free(list): + */ +#define list_free_with_free abrt_list_free_with_free +void list_free_with_free(GList *list); + +#define get_dirsize abrt_get_dirsize double get_dirsize(const char *pPath); +#define get_dirsize_find_largest_dir abrt_get_dirsize_find_largest_dir double get_dirsize_find_largest_dir( const char *pPath, char **worst_dir, /* can be NULL */ const char *excluded /* can be NULL */ ); +/* Emit a string of hex representation of bytes */ +#define bin2hex abrt_bin2hex +char* bin2hex(char *dst, const char *str, int count); +/* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */ +#define hex2bin abrt_hex2bin +char* hex2bin(char *dst, const char *str, int count); + /* Returns command line of running program. * Caller is responsible to free() the returned value. * If the pid is not valid or command line can not be obtained, * empty string is returned. */ +#define get_cmdline abrt_get_cmdline char* get_cmdline(pid_t pid); /* Returns 1 if abrtd daemon is running, 0 otherwise. */ +#define daemon_is_ok abrt_daemon_is_ok int daemon_is_ok(); -struct run_event_state { - int (*post_run_callback)(const char *dump_dir_name, void *param); - void *post_run_param; - char* (*logging_callback)(char *log_line, void *param); - void *logging_param; -}; -static inline struct run_event_state *new_run_event_state() - { return (struct run_event_state*)xzalloc(sizeof(struct run_event_state)); } -static inline void free_run_event_state(struct run_event_state *state) - { free(state); } -/* Returns exitcode of first failed action, or first nonzero return value - * of post_run_callback. If all actions are successful, returns 0. - * If no actions were run for the event, returns -1. +/* Takes ptr to time_t, or NULL if you want to use current time. + * Returns "YYYY-MM-DD-hh:mm:ss" string. */ -int run_event(struct run_event_state *state, const char *dump_dir_name, const char *event); -char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const char *pfx); - -#ifdef __cplusplus -} -#endif - - -/* C++ style stuff */ -#ifdef __cplusplus -std::string unsigned_to_string(unsigned long long x); -std::string signed_to_string(long long x); -template <class T> inline -std::string to_string(T x) -{ - if ((T)~(T)0 < (T)0) /* T is a signed type */ - return signed_to_string(x); - return unsigned_to_string(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); +#define iso_date_string abrt_iso_date_string +char *iso_date_string(time_t *pt); + +#define make_description_bz abrt_make_description_bz +char* make_description_bz(crash_data_t *crash_data); +#define make_description_reproduce_comment abrt_make_description_reproduce_comment +char* make_description_reproduce_comment(crash_data_t *crash_data); +#define make_description_logger abrt_make_description_logger +char* make_description_logger(crash_data_t *crash_data); +#define make_description_mailx abrt_make_description_mailx +char* make_description_mailx(crash_data_t *crash_data); + +#define parse_release_for_bz abrt_parse_release_for_bz +void parse_release_for_bz(const char *pRelease, char **product, char **version); +#define parse_release_for_rhts abrt_parse_release_for_rhts +void parse_release_for_rhts(const char *pRelease, char **product, char **version); /** * Loads settings and stores it in second parameter. On success it @@ -264,29 +247,21 @@ char* make_description_mailx(const map_crash_data_t& pCrashData); * * @param path A path of config file. * Config file consists of "key=value" lines. - * @param settings A readed plugin's settings. + * @param settings A read 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); +#define load_conf_file abrt_load_conf_file +bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); -// TODO: npajkovs: full rewrite ssprintf -> xasprintf -static inline std::string ssprintf(const char *format, ...) -{ - va_list p; - char *string_ptr; +/* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename. + * Returns NULL if copying failed. In this case, logs a message before returning. */ +#define steal_directory abrt_steal_directory +struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name); - va_start(p, format); - string_ptr = xvasprintf(format, p); - va_end(p); - - std::string res = string_ptr; - free(string_ptr); - return res; +#ifdef __cplusplus } #endif diff --git a/src/include/action.h b/src/include/action.h deleted file mode 100644 index 21183366..00000000 --- a/src/include/action.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Action.h - header file for action plugin - - 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 ACTION_H_ -#define ACTION_H_ - -#include "plugin.h" - -/** - * An abstract class. The class defines an action plugin interface. - */ -class CAction : public CPlugin -{ - public: - /** - * A Method which performs particular action. As the first parameter it - * takes an action directory. It could be either a directory of actual - * crash or it could be a directory contains all crashes. It depends on - * who call the plugin. The plugin can takes arguments, but the plugin - * has to parse them by itself. - * @param pActionDir An actual directory. - * @param pArgs Plugin's arguments. - */ - virtual void Run(const char *pActionDir, const char *pArgs, int force) = 0; -}; - -#endif diff --git a/src/include/analyzer.h b/src/include/analyzer.h deleted file mode 100644 index 1d78d576..00000000 --- a/src/include/analyzer.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Analyzer.h - header file for analyzer plugin - - 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 ANALYZER_H_ -#define ANALYZER_H_ - -#include <string> -#include "plugin.h" - -/** - * An abstract class. The class defines an analyzer plugin interface. - */ -class CAnalyzer : public CPlugin -{ -}; - -#endif /*ANALYZER_H_*/ diff --git a/src/include/comm_layer_inner.h b/src/include/comm_layer_inner.h deleted file mode 100644 index 2cca9add..00000000 --- a/src/include/comm_layer_inner.h +++ /dev/null @@ -1,61 +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 COMMLAYERINNER_H_ -#define COMMLAYERINNER_H_ - -#ifdef __cplusplus - -#include "observer.h" - -void init_daemon_logging(CObserver *pObs); - -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Set client's name (dbus ID). NULL unsets it. - */ -void set_client_name(const char* name); - -/* - * Ask a client to warn the user about a non-fatal, but unexpected condition. - * In GUI, it will usually be presented as a popup message. - * Usually there is no need to call it directly, just use [p]error_msg(). - */ -//now static: -//void warn_client(const char *msg); -//use [p]error_msg[_and_die] instead, it sends the message as a warning to client -//as well as to the log. - -/* - * Logs a message to a client. - * In UI, it will usually appear as a new status line message in GUI, - * or as a new message line in CLI. - */ -void update_client(const char *fmt, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/dbus_common.h b/src/include/dbus_common.h deleted file mode 100644 index 6c739169..00000000 --- a/src/include/dbus_common.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright (C) 2009 Jiri Moskovcak (jmoskovc@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 DBUSCOMMON_H_ -#define DBUSCOMMON_H_ - -#include "abrt_crash_dump.h" - -#define ABRTD_DBUS_NAME "com.redhat.abrt" -#define ABRTD_DBUS_PATH "/com/redhat/abrt" -#define ABRTD_DBUS_IFACE "com.redhat.abrt" - -#endif diff --git a/src/include/observer.h b/src/include/observer.h deleted file mode 100644 index 1c8f2355..00000000 --- a/src/include/observer.h +++ /dev/null @@ -1,32 +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 OBSERVER_H_ -#define OBSERVER_H_ - -#include <string> -#include "dbus_common.h" - -class CObserver { - public: - virtual ~CObserver() {} - virtual void Status(const char *pMessage, const char* peer) = 0; - virtual void Warning(const char *pMessage, const char* peer) = 0; -}; - -#endif diff --git a/src/include/plugin.h b/src/include/plugin.h deleted file mode 100644 index 3f652e65..00000000 --- a/src/include/plugin.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - Plugin.h - header file for plugin. It contains mandatory macros - and common function for plugins - - 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 PLUGIN_H_ -#define PLUGIN_H_ - -#include "abrt_types.h" -#include "abrt_crash_dump.h" - -#define PLUGINS_MAGIC_NUMBER 6 - -#define PLUGINS_CONF_EXTENSION "conf" -#define PLUGINS_LIB_EXTENSION "so" -#define PLUGINS_LIB_PREFIX "lib" - -/** - * An abstract class. The class defines a common plugin interface. If a plugin - * has some settings, then a *Settings(*) method has to be written. - */ -class CPlugin -{ - protected: - map_plugin_settings_t m_pSettings; - - public: - CPlugin(); - /** - * A destructor. - */ - virtual ~CPlugin(); - /** - * A method, which initializes a plugin. It is not mandatory method. - */ - virtual void Init(); - /** - * A method, which deinitializes a plugin. It is not mandatory method. - */ - virtual void DeInit(); - /** - * A method, which takes a settings and apply them. It is not a mandatory method. - * @param pSettings Plugin's settings - */ - virtual void SetSettings(const map_plugin_settings_t& pSettings); - /** - * A method, which return current settings. It is not mandatory method. - * @return Plugin's settings - */ -/// -// virtual const map_plugin_settings_t& GetSettings(); -}; - -/** - * An enum of plugin types. - */ -typedef enum { - ANALYZER, /**< An analyzer plugin*/ - ACTION, /**< An action plugin*/ - REPORTER, /**< A reporter plugin*/ - DATABASE, /**< A database plugin*/ - MAX_PLUGIN_TYPE = DATABASE, -} plugin_type_t; - -/** - * A struct contains all needed data about particular plugin. - */ -typedef struct SPluginInfo -{ - const plugin_type_t m_Type; /**< Plugin type.*/ - const char *const m_sName; /**< Plugin name.*/ - const char *const m_sVersion; /**< Plugin version.*/ - const char *const m_sDescription; /**< Plugin description.*/ - const char *const m_sEmail; /**< Plugin author's email.*/ - const char *const m_sWWW; /**< Plugin's home page.*/ - const char *const m_sGTKBuilder; /**< Plugin's gui description.*/ - const int m_nMagicNumber; /**< Plugin magical number.*/ -} plugin_info_t; - -#define PLUGIN_INFO(type, plugin_class, name, version, description, email, www, gtk_builder)\ - extern "C" CPlugin* plugin_new()\ - {\ - return new plugin_class();\ - }\ - extern "C" const plugin_info_t plugin_info =\ - {\ - type,\ - name,\ - version,\ - description,\ - email,\ - www,\ - gtk_builder,\ - PLUGINS_MAGIC_NUMBER,\ - }; - -#endif diff --git a/src/include/report/crash_data.h b/src/include/report/crash_data.h new file mode 100644 index 00000000..3854118a --- /dev/null +++ b/src/include/report/crash_data.h @@ -0,0 +1,101 @@ +/* + Copyright (C) 2009 Abrt team. + 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 CRASH_DATA_H_ +#define CRASH_DATA_H_ + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct dump_dir; + +enum { + CD_FLAG_BIN = (1 << 0), + CD_FLAG_TXT = (1 << 1), + CD_FLAG_ISEDITABLE = (1 << 2), + CD_FLAG_ISNOTEDITABLE = (1 << 3), +}; + +struct crash_item { + char *content; + unsigned flags; +}; +typedef struct crash_item crash_item; + +/* In-memory crash data structure and accessors */ + +typedef GHashTable crash_data_t; + +crash_data_t *new_crash_data(void); + +static inline void free_crash_data(crash_data_t *crash_data) +{ + if (crash_data) + g_hash_table_destroy(crash_data); +} + +void add_to_crash_data_ext(crash_data_t *crash_data, + const char *name, + const char *content, + unsigned flags); +/* Uses CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE flags */ +void add_to_crash_data(crash_data_t *crash_data, + const char *name, + const char *content); + +static inline struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key) +{ + return (struct crash_item *)g_hash_table_lookup(crash_data, key); +} +const char *get_crash_item_content_or_NULL(crash_data_t *crash_data, const char *key); +/* Aborts if key is not found: */ +const char *get_crash_item_content_or_die(crash_data_t *crash_data, const char *key); + + +/* Vector of these structures */ + +typedef GPtrArray vector_of_crash_data_t; + +static inline crash_data_t *get_crash_data(vector_of_crash_data_t *vector, unsigned i) +{ + return (crash_data_t *)g_ptr_array_index(vector, i); +} + +vector_of_crash_data_t *new_vector_of_crash_data(void); +static inline void free_vector_of_crash_data(vector_of_crash_data_t *vector) +{ + if (vector) + g_ptr_array_free(vector, TRUE); +} + + +/* Conversions between in-memory and on-disk formats */ + +void load_crash_data_from_dump_dir(crash_data_t *crash_data, struct dump_dir *dd); +crash_data_t *create_crash_data_from_dump_dir(struct dump_dir *dd); + +struct dump_dir *create_dump_dir_from_crash_data(crash_data_t *crash_data, const char *base_dir_name); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/dump_dir.h b/src/include/report/dump_dir.h index 7a38f1e4..1376d7f3 100644 --- a/src/include/dump_dir.h +++ b/src/include/report/dump_dir.h @@ -21,16 +21,21 @@ #ifndef DUMP_DIR_H_ #define DUMP_DIR_H_ +/* For DIR */ +#include <sys/types.h> +#include <dirent.h> + #ifdef __cplusplus extern "C" { #endif enum { DD_FAIL_QUIETLY = (1 << 0), + DD_OPEN_READONLY = (1 << 1), }; struct dump_dir { - char *dd_dir; + char *dd_dirname; DIR *next_dir; int locked; uid_t dd_uid; @@ -40,22 +45,27 @@ struct dump_dir { void dd_close(struct dump_dir *dd); struct dump_dir *dd_opendir(const char *dir, int flags); +/* Pass uid = (uid_t)-1L to disable chown'ing of newly created files + * (IOW: if you aren't running under root): + */ struct dump_dir *dd_create(const char *dir, uid_t uid); +void dd_create_basic_files(struct dump_dir *dd, uid_t uid); int dd_exist(struct dump_dir *dd, const char *path); DIR *dd_init_next_file(struct dump_dir *dd); int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name); enum { /* DD_FAIL_QUIETLY bit is valid for dd_load_text_ext too, */ - DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (1 << 1), + DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE = (1 << 2), }; char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned flags); char* dd_load_text(const struct dump_dir *dd, const char *name); void dd_save_text(struct dump_dir *dd, const char *name, const char *data); void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size); -void dd_delete(struct dump_dir *dd); +/* Returns 0 if directory is deleted or not found */ +int dd_delete(struct dump_dir *dd); -void delete_crash_dump_dir(const char *dd_dir); +void delete_dump_dir(const char *dirname); #ifdef __cplusplus } diff --git a/src/include/report/run_event.h b/src/include/report/run_event.h new file mode 100644 index 00000000..7fd8edea --- /dev/null +++ b/src/include/report/run_event.h @@ -0,0 +1,82 @@ +/* + Copyright (C) 2009 Abrt team. + 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 RUN_EVENT_H_ +#define RUN_EVENT_H_ + +#include "crash_data.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct dump_dir; + +struct run_event_state { + int children_count; + + /* Used only for post-create dup detection. TODO: document its API */ + int (*post_run_callback)(const char *dump_dir_name, void *param); + void *post_run_param; + + /* Can take ownership of log_line, which is malloced. In this case, return NULL. + * Otherwise should return log_line (it will be freed by caller) + */ + char* (*logging_callback)(char *log_line, void *param); + void *logging_param; + + /* Internal data for async command execution */ + GList *commands; + pid_t command_pid; + int command_out_fd; +}; +struct run_event_state *new_run_event_state(void); +void free_run_event_state(struct run_event_state *state); + +/* Asyncronous command execution */ + +/* Returns 0 if no commands found for this dump_dir_name+event, else >0 */ +int prepare_commands(struct run_event_state *state, const char *dump_dir_name, const char *event); +/* Returns -1 is no more commands needs to be executed, + * else sets state->command_pid and state->command_out_fd and returns >=0 + */ +int spawn_next_command(struct run_event_state *state, const char *dump_dir_name, const char *event); +/* Cleans up internal state created in prepare_commands */ +void free_commands(struct run_event_state *state); + +/* Syncronous command execution */ + +/* Returns exit code of first failed action, or first nonzero return value + * of post_run_callback. If all actions are successful, returns 0. + */ +int run_event_on_dir_name(struct run_event_state *state, const char *dump_dir_name, const char *event); +int run_event_on_crash_data(struct run_event_state *state, crash_data_t *data, const char *event); + +/* Querying for possible events */ + +/* Scans event.conf for events starting with pfx which are applicable + * to dd, or (if dd is NULL), to dump_dir. + * Returns a malloced string with '\n'-terminated event names. + */ +char *list_possible_events(struct dump_dir *dd, const char *dump_dir_name, const char *pfx); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/xfuncs.h b/src/include/xfuncs.h index 20284564..61188c81 100644 --- a/src/include/xfuncs.h +++ b/src/include/xfuncs.h @@ -29,43 +29,69 @@ extern "C" { #endif +#define ndelay_on abrt_ndelay_on int ndelay_on(int fd); +#define ndelay_off abrt_ndelay_off int ndelay_off(int fd); +#define close_on_exec_on abrt_close_on_exec_on int close_on_exec_on(int fd); -void* xcalloc(size_t nmemb, size_t size); +#define xmalloc abrt_xmalloc void* xmalloc(size_t size); +#define xrealloc abrt_xrealloc void* xrealloc(void *ptr, size_t size); +#define xzalloc abrt_xzalloc void* xzalloc(size_t size); +#define xstrdup abrt_xstrdup char* xstrdup(const char *s); +#define xstrndup abrt_xstrndup char* xstrndup(const char *s, int n); +#define xpipe abrt_xpipe void xpipe(int filedes[2]); +#define xdup abrt_xdup void xdup(int from); +#define xdup2 abrt_xdup2 void xdup2(int from, int to); +#define xmove_fd abrt_xmove_fd void xmove_fd(int from, int to); +#define xwrite abrt_xwrite void xwrite(int fd, const void *buf, size_t count); +#define xwrite_str abrt_xwrite_str void xwrite_str(int fd, const char *str); +#define xlseek abrt_xlseek off_t xlseek(int fd, off_t offset, int whence); +#define xchdir abrt_xchdir void xchdir(const char *path); +#define xvasprintf abrt_xvasprintf char* xvasprintf(const char *format, va_list p); +#define xasprintf abrt_xasprintf char* xasprintf(const char *format, ...); +#define xsetenv abrt_xsetenv void xsetenv(const char *key, const char *value); +#define xsocket abrt_xsocket int xsocket(int domain, int type, int protocol); +#define xbind abrt_xbind void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); +#define xlisten abrt_xlisten void xlisten(int s, int backlog); +#define xsendto abrt_xsendto ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, socklen_t tolen); +#define xstat abrt_xstat void xstat(const char *name, struct stat *stat_buf); +#define xopen3 abrt_xopen3 int xopen3(const char *pathname, int flags, int mode); +#define xopen abrt_xopen int xopen(const char *pathname, int flags); +#define xunlink abrt_xunlink void xunlink(const char *pathname); /* Just testing dent->d_type == DT_REG is wrong: some filesystems @@ -74,18 +100,28 @@ void xunlink(const char *pathname); * This function handles this case. Note: it returns 0 on symlinks * even if they point to regular files. */ +#define is_regular_file abrt_is_regular_file int is_regular_file(struct dirent *dent, const char *dirname); + +#define dot_or_dotdot abrt_dot_or_dotdot bool dot_or_dotdot(const char *filename); +#define last_char_is abrt_last_char_is char *last_char_is(const char *s, int c); +#define string_to_bool abrt_string_to_bool bool string_to_bool(const char *s); +#define xseteuid abrt_xseteuid void xseteuid(uid_t euid); +#define xsetegid abrt_xsetegid void xsetegid(gid_t egid); +#define xsetreuid abrt_xsetreuid void xsetreuid(uid_t ruid, uid_t euid); +#define xsetregid abrt_xsetregid void xsetregid(gid_t rgid, gid_t egid); /* Returns getpwuid(uid)->pw_dir or NULL */ +#define get_home_dir abrt_get_home_dir const char *get_home_dir(uid_t uid); #ifdef __cplusplus |
