Blame src/include/libabrt.h

Packit 8ea169
/*
Packit 8ea169
 * Utility routines.
Packit 8ea169
 *
Packit 8ea169
 * Licensed under GPLv2, see file COPYING in this tarball for details.
Packit 8ea169
 */
Packit 8ea169
Packit 8ea169
/** @file libabrt.h */
Packit 8ea169
Packit 8ea169
#ifndef LIBABRT_H_
Packit 8ea169
#define LIBABRT_H_
Packit 8ea169
Packit 8ea169
#include <regex.h>
Packit 8ea169
Packit 8ea169
#include <gio/gio.h> /* dbus */
Packit 8ea169
#include "abrt-dbus.h"
Packit 8ea169
/* libreport's internal functions we use: */
Packit 8ea169
#include <libreport/internal_libreport.h>
Packit 8ea169
#include "hooklib.h"
Packit 8ea169
Packit 8ea169
#undef ARRAY_SIZE
Packit 8ea169
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
Packit 8ea169
Packit 8ea169
#ifdef __cplusplus
Packit 8ea169
extern "C" {
Packit 8ea169
#endif
Packit 8ea169
Packit 8ea169
/* Some libc's forget to declare these, do it ourself */
Packit 8ea169
extern char **environ;
Packit 8ea169
#if defined(__GLIBC__) && __GLIBC__ < 2
Packit 8ea169
int vdprintf(int d, const char *format, va_list ap);
Packit 8ea169
#endif
Packit 8ea169
Packit 8ea169
Packit 8ea169
#define low_free_space abrt_low_free_space
Packit 8ea169
/**
Packit 8ea169
  @brief Checks if there is enough free space to store the problem data
Packit 8ea169
Packit 8ea169
  @param setting_MaxCrashReportsSize Maximum data size
Packit 8ea169
  @param dump_location Location to check for the available space
Packit 8ea169
*/
Packit 8ea169
int low_free_space(unsigned setting_MaxCrashReportsSize, const char *dump_location);
Packit 8ea169
Packit 8ea169
#define trim_problem_dirs abrt_trim_problem_dirs
Packit 8ea169
void trim_problem_dirs(const char *dirname, double cap_size, const char *exclude_path);
Packit 8ea169
#define ensure_writable_dir_id abrt_ensure_writable_dir_uid_git
Packit 8ea169
void ensure_writable_dir_uid_gid(const char *dir, mode_t mode, uid_t uid, gid_t gid);
Packit 8ea169
#define ensure_writable_dir abrt_ensure_writable_dir
Packit 8ea169
void ensure_writable_dir(const char *dir, mode_t mode, const char *user);
Packit 8ea169
#define ensure_writable_dir_group abrt_ensure_writable_dir_group
Packit 8ea169
void ensure_writable_dir_group(const char *dir, mode_t mode, const char *user, const char *group);
Packit 8ea169
#define run_unstrip_n abrt_run_unstrip_n
Packit 8ea169
char *run_unstrip_n(const char *dump_dir_name, unsigned timeout_sec);
Packit 8ea169
#define get_backtrace abrt_get_backtrace
Packit 8ea169
char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char *debuginfo_dirs);
Packit 8ea169
Packit 8ea169
#define dir_is_in_dump_location abrt_dir_is_in_dump_location
Packit 8ea169
bool dir_is_in_dump_location(const char *dir_name);
Packit 8ea169
Packit 8ea169
enum {
Packit 8ea169
    DD_PERM_EVENTS  = 1 << 0,
Packit 8ea169
    DD_PERM_DAEMONS = 1 << 1,
Packit 8ea169
};
Packit 8ea169
#define dir_has_correct_permissions abrt_dir_has_correct_permissions
Packit 8ea169
bool dir_has_correct_permissions(const char *dir_name, int flags);
Packit 8ea169
#define allowed_new_user_problem_entry abrt_allowed_new_user_problem_entry
Packit 8ea169
bool allowed_new_user_problem_entry(uid_t uid, const char *name, const char *value);
Packit 8ea169
Packit 8ea169
#define g_settings_nMaxCrashReportsSize abrt_g_settings_nMaxCrashReportsSize
Packit 8ea169
extern unsigned int  g_settings_nMaxCrashReportsSize;
Packit 8ea169
#define g_settings_sWatchCrashdumpArchiveDir abrt_g_settings_sWatchCrashdumpArchiveDir
Packit 8ea169
extern char *        g_settings_sWatchCrashdumpArchiveDir;
Packit 8ea169
#define g_settings_dump_location abrt_g_settings_dump_location
Packit 8ea169
extern char *        g_settings_dump_location;
Packit 8ea169
#define g_settings_delete_uploaded abrt_g_settings_delete_uploaded
Packit 8ea169
extern bool          g_settings_delete_uploaded;
Packit 8ea169
#define g_settings_autoreporting abrt_g_settings_autoreporting
Packit 8ea169
extern bool          g_settings_autoreporting;
Packit 8ea169
#define g_settings_autoreporting_event abrt_g_settings_autoreporting_event
Packit 8ea169
extern char *        g_settings_autoreporting_event;
Packit 8ea169
#define g_settings_shortenedreporting abrt_g_settings_shortenedreporting
Packit 8ea169
extern bool          g_settings_shortenedreporting;
Packit 8ea169
#define g_settings_explorechroots abrt_g_settings_explorechroots
Packit 8ea169
extern bool          g_settings_explorechroots;
Packit 8ea169
#define g_settings_debug_level abrt_g_settings_debug_level
Packit 8ea169
extern unsigned int  g_settings_debug_level;
Packit 8ea169
Packit 8ea169
Packit 8ea169
#define load_abrt_conf abrt_load_abrt_conf
Packit 8ea169
int load_abrt_conf(void);
Packit 8ea169
#define free_abrt_conf_data abrt_free_abrt_conf_data
Packit 8ea169
void free_abrt_conf_data(void);
Packit 8ea169
Packit 8ea169
#define load_abrt_conf_file abrt_load_abrt_conf_file
Packit 8ea169
int load_abrt_conf_file(const char *file, map_string_t *settings);
Packit 8ea169
Packit 8ea169
#define load_abrt_plugin_conf_file abrt_load_abrt_plugin_conf_file
Packit 8ea169
int load_abrt_plugin_conf_file(const char *file, map_string_t *settings);
Packit 8ea169
Packit 8ea169
#define save_abrt_conf_file abrt_save_abrt_conf_file
Packit 8ea169
int save_abrt_conf_file(const char *file, map_string_t *settings);
Packit 8ea169
Packit 8ea169
#define save_abrt_plugin_conf_file abrt_save_abrt_plugin_conf_file
Packit 8ea169
int save_abrt_plugin_conf_file(const char *file, map_string_t *settings);
Packit 8ea169
Packit 8ea169
Packit 8ea169
void migrate_to_xdg_dirs(void);
Packit 8ea169
Packit 8ea169
int check_recent_crash_file(const char *filename, const char *executable);
Packit 8ea169
Packit 8ea169
/* Returns 1 if abrtd daemon is running, 0 otherwise. */
Packit 8ea169
#define daemon_is_ok abrt_daemon_is_ok
Packit 8ea169
int daemon_is_ok(void);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
@brief Sends notification to abrtd that a new problem has been detected
Packit 8ea169
Packit 8ea169
@param[in] path Path to the problem directory containing the problem data
Packit 8ea169
*/
Packit 8ea169
#define notify_new_path abrt_notify_new_path
Packit 8ea169
void notify_new_path(const char *path);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
@brief Sends notification to abrtd that a new problem has been detected and
Packit 8ea169
wait for the reply
Packit 8ea169
Packit 8ea169
@param path Path to the problem directory containing the problem data
Packit 8ea169
@param message The abrtd reply
Packit 8ea169
@return -errno on error otherwise return value of abrtd
Packit 8ea169
*/
Packit 8ea169
#define notify_new_path_with_response abrt_notify_new_path_with_response
Packit 8ea169
int notify_new_path_with_response(const char *path, char **message);
Packit 8ea169
Packit 8ea169
/* Note: should be public since unit tests need to call it */
Packit 8ea169
#define koops_extract_version abrt_koops_extract_version
Packit 8ea169
char *koops_extract_version(const char *line);
Packit 8ea169
#define kernel_tainted_short abrt_kernel_tainted_short
Packit 8ea169
char *kernel_tainted_short(const char *kernel_bt);
Packit 8ea169
#define kernel_tainted_long abrt_kernel_tainted_long
Packit 8ea169
char *kernel_tainted_long(const char *tainted_short);
Packit 8ea169
#define koops_hash_str_ext abrt_koops_hash_str_ext
Packit 8ea169
int koops_hash_str_ext(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *oops_buf, int frame_count, int duphas_flags);
Packit 8ea169
#define koops_hash_str abrt_koops_hash_str
Packit 8ea169
int koops_hash_str(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *oops_buf);
Packit 8ea169
Packit 8ea169
Packit 8ea169
#define koops_line_skip_level abrt_koops_line_skip_level
Packit 8ea169
int koops_line_skip_level(const char **c);
Packit 8ea169
#define koops_line_skip_jiffies abrt_koops_line_skip_jiffies
Packit 8ea169
void koops_line_skip_jiffies(const char **c);
Packit 8ea169
Packit 8ea169
/*
Packit 8ea169
 * extract_oops tries to find oops signatures in a log
Packit 8ea169
 */
Packit 8ea169
struct abrt_koops_line_info {
Packit 8ea169
    char *ptr;
Packit 8ea169
    int level;
Packit 8ea169
};
Packit 8ea169
Packit 8ea169
#define koops_extract_oopses_from_lines abrt_koops_extract_oopses_from_lines
Packit 8ea169
void koops_extract_oopses_from_lines(GList **oops_list, const struct abrt_koops_line_info *lines_info, int lines_info_size);
Packit 8ea169
#define koops_extract_oopses abrt_koops_extract_oopses
Packit 8ea169
void koops_extract_oopses(GList **oops_list, char *buffer, size_t buflen);
Packit 8ea169
#define koops_suspicious_strings_list abrt_koops_suspicious_strings_list
Packit 8ea169
GList *koops_suspicious_strings_list(void);
Packit 8ea169
#define koops_suspicious_strings_blacklist abrt_koops_suspicious_strings_blacklist
Packit 8ea169
GList *koops_suspicious_strings_blacklist(void);
Packit 8ea169
#define koops_print_suspicious_strings abrt_koops_print_suspicious_strings
Packit 8ea169
void koops_print_suspicious_strings(void);
Packit 8ea169
/**
Packit 8ea169
 * Prints all suspicious strings that do not match any of the regular
Packit 8ea169
 * expression in NULL terminated list.
Packit 8ea169
 *
Packit 8ea169
 * The regular expression should be compiled with REG_NOSUB flag.
Packit 8ea169
 */
Packit 8ea169
#define koops_print_suspicious_strings_filtered abrt_koops_print_suspicious_strings_filtered
Packit 8ea169
void koops_print_suspicious_strings_filtered(const regex_t **filterout);
Packit 8ea169
Packit 8ea169
/* dbus client api */
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Changes the access rights of the problem specified by problem id
Packit 8ea169
Packit 8ea169
  Requires authorization
Packit 8ea169
Packit 8ea169
  @return 0 if successful; non-zero on failure
Packit 8ea169
*/
Packit 8ea169
int chown_dir_over_dbus(const char *problem_dir_path);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Checks whether the given element name exists
Packit 8ea169
Packit 8ea169
  Might require authorization
Packit 8ea169
Packit 8ea169
  @return Positive number if such an element exist, 0 if doesn't and negative number if an error occurs.
Packit 8ea169
 */
Packit 8ea169
int test_exist_over_dbus(const char *problem_id, const char *element_name);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Checks whether the problem corresponding to the given ID is complete
Packit 8ea169
Packit 8ea169
  Might require authorization
Packit 8ea169
Packit 8ea169
  @return Positive number if the problem is complete, 0 if doesn't and negative number if an error occurs.
Packit 8ea169
 */
Packit 8ea169
int dbus_problem_is_complete(const char *problem_id);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @ Returns value of the given element name
Packit 8ea169
Packit 8ea169
  Might require authorization
Packit 8ea169
Packit 8ea169
  @return malloced string or NULL if no such an element exists; ERR_PTR in case of any error.
Packit 8ea169
 */
Packit 8ea169
char *load_text_over_dbus(const char *problem_id, const char *element_name);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
 @brief Delets multiple problems specified by their id (as returned from problem_data_save)
Packit 8ea169
Packit 8ea169
 @param problem_dir_paths List of problem ids
Packit 8ea169
Packit 8ea169
 @return 0 if operation was successful, non-zero on failure
Packit 8ea169
*/
Packit 8ea169
Packit 8ea169
int delete_problem_dirs_over_dbus(const GList *problem_dir_paths);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Fetches given problem elements for specified problem id
Packit 8ea169
Packit 8ea169
  @return returns non-zero value on failures and prints error message
Packit 8ea169
*/
Packit 8ea169
int fill_problem_data_over_dbus(const char *problem_dir_path, const char **elements, problem_data_t *problem_data);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Fetches problem information for specified problem id
Packit 8ea169
Packit 8ea169
  @return a valid pointer to problem_data_t or ERR_PTR on failure
Packit 8ea169
*/
Packit 8ea169
problem_data_t *get_problem_data_dbus(const char *problem_dir_path);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Fetches full problem data for specified problem id
Packit 8ea169
Packit 8ea169
  @return a valid pointer to problem_data_t or ERR_PTR on failure
Packit 8ea169
*/
Packit 8ea169
problem_data_t *get_full_problem_data_over_dbus(const char *problem_dir_path);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Fetches all problems from problem database
Packit 8ea169
Packit 8ea169
  @param authorize If set to true will try to fetch even problems owned by other users (will require root authorization over policy kit)
Packit 8ea169
Packit 8ea169
  @return List of problem ids or ERR_PTR on failure (NULL is an empty list)
Packit 8ea169
*/
Packit 8ea169
GList *get_problems_over_dbus(bool authorize);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @struct ignored_problems
Packit 8ea169
  @brief An opaque structure holding a list of ignored problems
Packit 8ea169
*/
Packit 8ea169
typedef struct ignored_problems ignored_problems_t;
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Initializes a new instance of ignored problems
Packit 8ea169
Packit 8ea169
  @param file_path A malloced string holding a path to a file containing the list of ignored problems. Function takes ownership of the malloced memory, which will be freed in ignored_problems_free()
Packit 8ea169
  @see ignored_problems_free()
Packit 8ea169
  @return Fully initialized instance of ignored problems struct which must be destroyed by ignored_problems_free()
Packit 8ea169
*/
Packit 8ea169
ignored_problems_t *ignored_problems_new(char *file_path);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Destroys an instance of ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. Supports the common behaviour where it accepts
Packit 8ea169
  NULL pointers.
Packit 8ea169
Packit 8ea169
  @param set A destroyed instance
Packit 8ea169
*/
Packit 8ea169
void ignored_problems_free(ignored_problems_t *set);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Adds a problem to the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems to which the problem will be added
Packit 8ea169
  @param problem_id An identifier of a problem which will be added to an ignored set
Packit 8ea169
*/
Packit 8ea169
void ignored_problems_add(ignored_problems_t *set, const char *problem_id);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Removes a problem from the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems from which the problem will be deleted
Packit 8ea169
  @param problem_id An identifier of a problem which will be removed from an ignored problems struct
Packit 8ea169
*/
Packit 8ea169
void ignored_problems_remove(ignored_problems_t *set, const char *problem_id);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Checks if a problem is in the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged. If any error occurs,
Packit 8ea169
  the function returns 0 value.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems in which the problem will be searched
Packit 8ea169
  @param problem_id An identifier of a problem
Packit 8ea169
  @return Non 0 value if the problem is ignored; otherwise returns 0 value.
Packit 8ea169
*/
Packit 8ea169
bool ignored_problems_contains(ignored_problems_t *set, const char *problem_id);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Adds a problem defined by its data to the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems to which the problem will be added
Packit 8ea169
  @param pd A data of a problem which will be added to an ignored set
Packit 8ea169
*/
Packit 8ea169
void ignored_problems_add_problem_data(ignored_problems_t *set, problem_data_t *pd);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Removes a problem defined by its data from the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems from which the problem will be deleted
Packit 8ea169
  @param pd A data of a problem which will be removed from an ignored problems struct
Packit 8ea169
*/
Packit 8ea169
void ignored_problems_remove_problem_data(ignored_problems_t *set, problem_data_t *pd);
Packit 8ea169
Packit 8ea169
/**
Packit 8ea169
  @brief Checks if a problem defined its data is in the ignored problems
Packit 8ea169
Packit 8ea169
  This function never fails. All errors will be logged. If any error occurs,
Packit 8ea169
  the function returns 0 value.
Packit 8ea169
Packit 8ea169
  @param set An instance of ignored problems in which the problem will be searched
Packit 8ea169
  @param pd A data of a problem
Packit 8ea169
  @return Non 0 value if the problem is ignored; otherwise returns 0 value.
Packit 8ea169
*/
Packit 8ea169
bool ignored_problems_contains_problem_data(ignored_problems_t *set, problem_data_t *pd);
Packit 8ea169
Packit 8ea169
#ifdef __cplusplus
Packit 8ea169
}
Packit 8ea169
#endif
Packit 8ea169
Packit 8ea169
#endif