diff options
| author | Karel Klic <kklic@redhat.com> | 2011-03-01 12:08:36 +0100 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2011-03-01 12:08:36 +0100 |
| commit | 85f639b7fe277ba327e5013e5b101b4a67f14e1d (patch) | |
| tree | 7caa3999e8c987e3ddbc26f4bfbbdc73defca73f /src/include/abrtlib.h | |
| parent | fb52104af74bbf6eeda394880666df40b4354aba (diff) | |
| parent | 77468fcdd7cc05db52320c373a24a5490ff32f52 (diff) | |
merge changes from master
Diffstat (limited to 'src/include/abrtlib.h')
| -rw-r--r-- | src/include/abrtlib.h | 221 |
1 files changed, 98 insertions, 123 deletions
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 |
