From d9e2d23b754c0a3a6ccfdaee423065e4a1cd7784 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 1 Dec 2010 17:40:44 +0100 Subject: factor out headers so that "report lib" API is separated out of abrt API This patch minimally affects code per se - it adds create_crash_dump_dir() function which takes in-memory representation of the dump (map_crash_data_t object) and creates an on-disk representation. Then it returns pointer to struct dump_dir. With this function, it is possible to run an event on a user-constructed map_crash_data_t: map_crash_data_t cd; add_to_crash_data(cd, "foo", "bar"); struct dump_dir *dd = create_crash_dump_dir(cd); char *dir_name = strdup(dd->dd_dir); dd_close(dd); run_event(run_state, dir_name, event); delete_crash_dump_dir(dir_name); which is, basically, what report library is about. The biggest part of the patch is reshuffling of header files, with the following result: three header files which are not cluttered by other ABRT stuff, and expose the following API each: crash_dump.h - in-memory crash dump data structs and ops dump_dir.h - on-disk crash dump data structs and ops run_event.h - run_event() and friends These is a test application, test_report.cpp.cpp, which demonstrates (and tests) usage of these headers. (grep for "test-report" and enable it in build system if you want it to be built). It creates a temporary dump in /var/run/abrt/tmp-NNNN-NNNNN and runs "report" event. Deleting of temp dump is disabled for testing purposes - you might want to see the contents. Here is how the binary looks like: text data bss dec hex filename 3730 668 48 4446 115e /usr/bin/test-report linux-vdso.so.1 => (0x00007ffffa80f000) libabrt.so.0 => /usr/lib64/libabrt.so.0 (0x00007fad1f35e000) libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x0000003c1f200000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003c2c200000) libm.so.6 => /lib64/libm.so.6 (0x00007fad1f0da000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003c28e00000) libc.so.6 => /lib64/libc.so.6 (0x00007fad1ed5b000) /lib64/ld-linux-x86-64.so.2 (0x00007fad1f570000) Next step would be to clean up the namespace, then rename libabrt.so into libreport.so, then split it into a separate package so that we can install it without installing other two abrt .so files. Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 8cd0664a..cb2755b0 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -78,8 +78,9 @@ int vdprintf(int d, const char *format, va_list ap); #include "hash_md5.h" #include "abrt_crash_dump.h" -#include "dump_dir.h" #include "abrt_types.h" +#include "dump_dir.h" +#include "run_event.h" #ifdef __cplusplus @@ -216,23 +217,6 @@ char* get_cmdline(pid_t pid); /* Returns 1 if abrtd daemon is running, 0 otherwise. */ 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. - */ -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 -- cgit From 47728cc3c70c2b6d3a645e5760b39b20bd946e39 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 6 Dec 2010 16:56:50 +0100 Subject: This patch changes crash data to use C structures. The smallest data element is: struct crash_item { char *content; unsigned flags; }; where content is, eh, content, and flags is a bit flag field. crash_data_t is a map of crash_item's, implemented as a pointer to heap-allocated GHashTable. vector_of_crash_data_t is a vector of crash_data_t's, implemented as a pointer to heap-allocated GPtrArray. Most operations have light wrappers around them to hide the nature of the containers. For example, to free vector_of_crash_data, you need to use free_vector_of_crash_data(ptr) instead of open-coding g_ptr_array_free. The wrapper is thin. The goal is not so much to hide the implementation, but more to make it easier to use the correct function. dbus (un)marshalling functions convert crash_item to three-element array of strings, in order to keep compatibility with abrt-gui (python). This can be changed later to use native representation. crash_data_t and vector_of_crash_data_t are represented in "natural" way, no funny stuff there. Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index cb2755b0..1fadd31a 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -237,10 +237,10 @@ 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); +char* make_description_bz(crash_data_t *crash_data); +char* make_description_reproduce_comment(crash_data_t *crash_data); +char* make_description_logger(crash_data_t *crash_data); +char* make_description_mailx(crash_data_t *crash_data); /** * Loads settings and stores it in second parameter. On success it -- cgit From fc9639c850a341e3010465ecb0eecb7f0cd03fc9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Dec 2010 10:30:30 +0100 Subject: remove unused function parse_args; make a few functions extern "C" Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 1fadd31a..a4337709 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -217,6 +217,13 @@ char* get_cmdline(pid_t pid); /* Returns 1 if abrtd daemon is running, 0 otherwise. */ int daemon_is_ok(); +char* make_description_bz(crash_data_t *crash_data); +char* make_description_reproduce_comment(crash_data_t *crash_data); +char* make_description_logger(crash_data_t *crash_data); +char* make_description_mailx(crash_data_t *crash_data); + +void parse_release(const char *pRelease, char **product, char **version); + #ifdef __cplusplus } #endif @@ -234,14 +241,6 @@ std::string to_string(T 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(crash_data_t *crash_data); -char* make_description_reproduce_comment(crash_data_t *crash_data); -char* make_description_logger(crash_data_t *crash_data); -char* make_description_mailx(crash_data_t *crash_data); - /** * Loads settings and stores it in second parameter. On success it * returns true, otherwise returns false. -- cgit From 816f3e001271ed8ab7fdadb6d90aeb2c61362dac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 14:51:47 +0100 Subject: removal of C++isms from libabrt, part 1 This patch converts libabrt usage of C++ map to a glib-based container, GHashTable. It is typedef-ed to map_string_h. We can't typedef it to map_string_t, since other parts of ABRT (daemon, cli) still use that name for C++ container. Also, exceptions are removed everywhere. Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index a4337709..f3a5de4e 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -224,6 +224,20 @@ char* make_description_mailx(crash_data_t *crash_data); void parse_release(const char *pRelease, char **product, char **version); +/** + * 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 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. + */ +bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); + #ifdef __cplusplus } #endif @@ -241,22 +255,6 @@ std::string to_string(T x) return unsigned_to_string(x); } -/** - * 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, ...) { -- cgit From def39238640489b41da5cdc8fd4a83d16d49fcc7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 15:03:24 +0100 Subject: removal of C++isms from libabrt, part 2 This patch rewrites a few places where we use C++ strings Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index f3a5de4e..d8dd361a 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -245,16 +245,6 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith /* C++ style stuff */ #ifdef __cplusplus -std::string unsigned_to_string(unsigned long long x); -std::string signed_to_string(long long x); -template 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); -} - // TODO: npajkovs: full rewrite ssprintf -> xasprintf static inline std::string ssprintf(const char *format, ...) { -- cgit From dc3c5b79ba1ee6fd7a98842fde43d072e004f93b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 16:07:31 +0100 Subject: add abrt_ prefixes to abrt-internal functions in libabrt.so Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 120 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 43 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index d8dd361a..d3f355e9 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -87,43 +87,64 @@ int vdprintf(int d, const char *format, va_list ap); 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); /* 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 @@ -146,6 +167,7 @@ enum { 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, @@ -154,53 +176,57 @@ 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); +//unused for now +///* 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); /* Random utility functions */ +#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 */ @@ -212,16 +238,23 @@ double get_dirsize_find_largest_dir( * 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(); +#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 abrt_parse_release void parse_release(const char *pRelease, char **product, char **version); /** @@ -236,6 +269,7 @@ void parse_release(const char *pRelease, char **product, char **version); * Otherwise empty value "" is inserted into pSettings. * @return if it success it returns true, otherwise it returns false. */ +#define load_conf_file abrt_load_conf_file bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); #ifdef __cplusplus -- cgit From df1b1d501106687fcf0039dc9771c4455c346df5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 22 Dec 2010 13:57:14 +0100 Subject: *: rename *crash_dump.* -> *crash_data.* Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index d3f355e9..0eb0f2d0 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -77,7 +77,7 @@ int vdprintf(int d, const char *format, va_list ap); #include "hash_sha1.h" #include "hash_md5.h" -#include "abrt_crash_dump.h" +#include "abrt_crash_data.h" #include "abrt_types.h" #include "dump_dir.h" #include "run_event.h" -- cgit From d108d7d2fbe0b178110295fd8335c258f699a5d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 6 Jan 2011 16:18:09 +0100 Subject: pass old pattern to ccpp hook and use it abrtd: instead of "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %p %s %u %c", sets coredump handler to "|/usr/libexec/abrt-ccpp-hook DEBUG_DUMPS_DIR %s %c %p %u %g %t %h %e OLD_PATTERN" abrt-ccpp-hook: expands OLD_PATTERN using values of %s %c %p %u %g %t %h %e and uses it as a name of "compat coredump". Patch has a feature which prevents usage of kernel-truncated OLD_PATTERN: it is passed as hex string *with terminating NUL* (encoded as 00). If ccpp hook doesn't see 00, it refuses to use OLD_PATTERN and uses string "core" instead. Run tested. On a new kernel, passes up to 27 char long old pattern. Longer patterns are still truncated. This may be improved in future kernels. Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 0eb0f2d0..2e23805a 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -233,6 +233,11 @@ double get_dirsize_find_largest_dir( const char *excluded /* can be NULL */ ); +/* Emit a string of hex representation of bytes */ +char* bin2hex(char *dst, const char *str, int count); +/* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */ +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, -- cgit From f4dcdc9a1ee5971bfda6acf079d615a6f40382b1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 Jan 2011 18:51:20 +0100 Subject: do not pollute library namespace: prefix bin2hex and hex2bin with abrt_ Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 2e23805a..9f428486 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -234,8 +234,10 @@ double get_dirsize_find_largest_dir( ); /* 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. -- cgit From e7fde9b01293d7bfdfe644b73f8ac679211d0b08 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 Jan 2011 18:53:22 +0100 Subject: remove C++-ism ssprintf from abrtlib.h Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 9f428486..88e52fff 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -283,23 +283,4 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith } #endif - -/* C++ style stuff */ -#ifdef __cplusplus -// TODO: npajkovs: full rewrite ssprintf -> xasprintf -static inline std::string ssprintf(const char *format, ...) -{ - va_list p; - char *string_ptr; - - va_start(p, format); - string_ptr = xvasprintf(format, p); - va_end(p); - - std::string res = string_ptr; - free(string_ptr); - return res; -} -#endif - #endif -- cgit From 6cff54c0b97d162e8c0461a28b10c260495458f2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 14 Jan 2011 14:02:07 +0100 Subject: preliminary cleanup patches Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 82 +++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 61 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 88e52fff..0c0d4be4 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -147,24 +147,24 @@ int xatoi_positive(const char *numstr); //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 @@ -178,49 +178,9 @@ pid_t fork_execv_on_steroids(int flags, * 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); - -//unused for now -///* 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 */ -- cgit From d7d62ea5ee19f5cad52dcfb2f2a49d8d36fa1228 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 18:34:08 +0100 Subject: introduce and use new helper function list_free_with_free Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 0c0d4be4..4ad2f6fc 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -42,6 +42,7 @@ #ifdef __cplusplus # include #endif +#include #ifdef HAVE_CONFIG_H # include "config.h" @@ -184,6 +185,12 @@ char *run_in_shell_and_save_output(int flags, /* 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 -- cgit From 7f5cbf38caa3c6fdd0afe3a4cb7a9bd3b3010596 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Jan 2011 21:17:49 +0100 Subject: split parse_release() into Bz and RHTS versions Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 4ad2f6fc..22b63baf 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -228,8 +228,10 @@ 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 abrt_parse_release -void parse_release(const char *pRelease, char **product, char **version); +#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 -- cgit From 55ae0eaea8684aa78089bbd0c2116e0c8cb25585 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 1 Feb 2011 16:04:30 +0100 Subject: abrt-cli -r DIR: copy non-writable DIR into $HOME/abrt/spool Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index 22b63baf..bb3dddc2 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -123,6 +123,8 @@ off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags); 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 -- cgit From 406b2cffd5e9120bea74ab01479039714ce9e2d5 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Thu, 17 Feb 2011 15:44:20 +0100 Subject: move steal_directory() into libreport --- src/include/abrtlib.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index bb3dddc2..c5959b34 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -250,6 +250,9 @@ void parse_release_for_rhts(const char *pRelease, char **product, char **version #define load_conf_file abrt_load_conf_file bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); +#define steal_directory abrt_steal_directory +struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name); + #ifdef __cplusplus } #endif -- cgit From 1bbf4c784aa9fda4d137013ea584874d56d45a33 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Feb 2011 18:25:40 +0100 Subject: gui-wizard-gtk: show error messages as msg boxes Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index c5959b34..ecae0de7 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -250,6 +250,8 @@ void parse_release_for_rhts(const char *pRelease, char **product, char **version #define load_conf_file abrt_load_conf_file bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); +/* 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); -- cgit From 39ce00f37c753ae7830a8f33631de468a0ec8212 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Feb 2011 17:16:28 +0100 Subject: show more useful columns in abrt-gtk; use human-readable time in dir names For most users, "hostname" is the same for every crash (it is their hostname). Not every problem even has "Application" field ("low on disk space" problem, for example, doesn't), whereas any problem should have "Reason" field. For non-root, it is useful to see which dumps are in /var/spool/abrt (and aren't writable), and which are in $HOME/.abrt/spool. Signed-off-by: Denys Vlasenko --- src/include/abrtlib.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/include/abrtlib.h') diff --git a/src/include/abrtlib.h b/src/include/abrtlib.h index ecae0de7..61731587 100644 --- a/src/include/abrtlib.h +++ b/src/include/abrtlib.h @@ -221,6 +221,12 @@ char* get_cmdline(pid_t pid); #define daemon_is_ok abrt_daemon_is_ok int daemon_is_ok(); +/* Takes ptr to time_t, or NULL if you want to use current time. + * Returns "YYYY-MM-DD-hh:mm:ss" string. + */ +#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 -- cgit