20 #ifndef LIBREPORT_INTERNAL_H_
21 #define LIBREPORT_INTERNAL_H_
38 #include <sys/socket.h>
41 #include <sys/types.h>
43 #include <arpa/inet.h>
50 #include <sys/param.h>
65 # define _(S) gettext(S)
75 extern char **environ;
76 #if defined(__GLIBC__) && __GLIBC__ < 2
77 int vdprintf(
int d,
const char *format, va_list ap);
81 #define NORETURN __attribute__ ((noreturn))
84 #define ERR_PTR ((void*)(uintptr_t)1)
87 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
92 #include "event_config.h"
95 #include "run_event.h"
103 #define prefixcmp libreport_prefixcmp
104 int prefixcmp(
const char *str,
const char *prefix);
105 #define suffixcmp libreport_suffixcmp
106 int suffixcmp(
const char *str,
const char *suffix);
107 #define strtrim libreport_strtrim
108 char *strtrim(
char *str);
109 #define strtrimch libreport_strtrimch
110 char *strtrimch(
char *str,
int ch);
111 #define concat_path_file libreport_concat_path_file
112 char *concat_path_file(
const char *path,
const char *filename);
113 #define append_to_malloced_string libreport_append_to_malloced_string
114 char *append_to_malloced_string(
char *mstr,
const char *append);
115 #define skip_whitespace libreport_skip_whitespace
116 char* skip_whitespace(
const char *s);
117 #define skip_non_whitespace libreport_skip_non_whitespace
118 char* skip_non_whitespace(
const char *s);
120 #define overlapping_strcpy libreport_overlapping_strcpy
121 void overlapping_strcpy(
char *dst,
const char *src);
124 #define xmalloc_fgets libreport_xmalloc_fgets
125 char *xmalloc_fgets(FILE *file);
127 #define xmalloc_fgetline libreport_xmalloc_fgetline
128 char *xmalloc_fgetline(FILE *file);
130 #define xmalloc_fopen_fgetline_fclose libreport_fopen_fgetline_fclose
131 char *xmalloc_fopen_fgetline_fclose(
const char *filename);
136 COPYFD_SPARSE = 1 << 0,
138 #define copyfd_eof libreport_copyfd_eof
139 off_t copyfd_eof(
int src_fd,
int dst_fd,
int flags);
140 #define copyfd_size libreport_copyfd_size
141 off_t copyfd_size(
int src_fd,
int dst_fd, off_t size,
int flags);
142 #define copyfd_exact_size libreport_copyfd_exact_size
143 void copyfd_exact_size(
int src_fd,
int dst_fd, off_t size);
144 #define copy_file libreport_copy_file
145 off_t copy_file(
const char *src_name,
const char *dst_name,
int mode);
146 #define copy_file_recursive libreport_copy_file_recursive
147 int copy_file_recursive(
const char *source,
const char *dest);
151 #define xread libreport_xread
152 void xread(
int fd,
void *buf,
size_t count);
153 #define safe_read libreport_safe_read
154 ssize_t safe_read(
int fd,
void *buf,
size_t count);
155 #define safe_write libreport_safe_write
156 ssize_t safe_write(
int fd,
const void *buf,
size_t count);
157 #define full_read libreport_full_read
158 ssize_t full_read(
int fd,
void *buf,
size_t count);
159 #define full_write libreport_full_write
160 ssize_t full_write(
int fd,
const void *buf,
size_t count);
161 #define full_write_str libreport_full_write_str
162 ssize_t full_write_str(
int fd,
const char *buf);
163 #define xmalloc_read libreport_xmalloc_read
164 void* xmalloc_read(
int fd,
size_t *maxsz_p);
165 #define xmalloc_open_read_close libreport_xmalloc_open_read_close
166 void* xmalloc_open_read_close(
const char *filename,
size_t *maxsz_p);
167 #define xmalloc_xopen_read_close libreport_xmalloc_xopen_read_close
168 void* xmalloc_xopen_read_close(
const char *filename,
size_t *maxsz_p);
172 #define encode_base64 libreport_encode_base64
173 char *encode_base64(
const void *src,
int length);
179 #define sanitize_utf8 libreport_sanitize_utf8
180 char *sanitize_utf8(
const char *src, uint32_t control_chars_to_sanitize);
182 SANITIZE_ALL = 0xffffffff,
183 SANITIZE_TAB = (1 << 9),
184 SANITIZE_LF = (1 << 10),
185 SANITIZE_CR = (1 << 13),
188 #define SHA1_RESULT_LEN (5 * 4)
195 #define sha1_begin libreport_sha1_begin
197 #define sha1_hash libreport_sha1_hash
198 void sha1_hash(
sha1_ctx_t *ctx,
const void *buffer,
size_t len);
199 #define sha1_end libreport_sha1_end
203 #define xatou libreport_xatou
204 unsigned xatou(
const char *numstr);
205 #define xatoi libreport_xatoi
206 int xatoi(
const char *numstr);
214 #define xatoi_positive libreport_xatoi_positive
215 int xatoi_positive(
const char *numstr);
222 #define safe_waitpid libreport_safe_waitpid
223 pid_t safe_waitpid(pid_t pid,
int *wstat,
int options);
228 EXECFLG_INPUT = 1 << 0,
231 EXECFLG_OUTPUT = 1 << 1,
233 EXECFLG_INPUT_NUL = 1 << 2,
235 EXECFLG_OUTPUT_NUL = 1 << 3,
237 EXECFLG_ERR2OUT = 1 << 4,
239 EXECFLG_ERR_NUL = 1 << 5,
241 EXECFLG_QUIET = 1 << 6,
242 EXECFLG_SETGUID = 1 << 7,
243 EXECFLG_SETSID = 1 << 8,
244 EXECFLG_SETPGID = 1 << 9,
252 #define fork_execv_on_steroids libreport_fork_execv_on_steroids
253 pid_t fork_execv_on_steroids(
int flags,
261 #define run_in_shell_and_save_output libreport_run_in_shell_and_save_output
262 char *run_in_shell_and_save_output(
int flags,
269 #define is_in_string_list libreport_is_in_string_list
270 bool is_in_string_list(
const char *name,
char **v);
272 #define is_in_comma_separated_list libreport_is_in_comma_separated_list
273 bool is_in_comma_separated_list(
const char *value,
const char *list);
274 #define is_in_comma_separated_list_of_glob_patterns libreport_is_in_comma_separated_list_of_glob_patterns
275 bool is_in_comma_separated_list_of_glob_patterns(
const char *value,
const char *list);
280 #define list_free_with_free libreport_list_free_with_free
281 void list_free_with_free(GList *list);
283 #define get_dirsize libreport_get_dirsize
284 double get_dirsize(
const char *pPath);
285 #define get_dirsize_find_largest_dir libreport_get_dirsize_find_largest_dir
286 double get_dirsize_find_largest_dir(
293 #define ndelay_on libreport_ndelay_on
294 int ndelay_on(
int fd);
295 #define ndelay_off libreport_ndelay_off
296 int ndelay_off(
int fd);
297 #define close_on_exec_on libreport_close_on_exec_on
298 int close_on_exec_on(
int fd);
300 #define xmalloc libreport_xmalloc
301 void* xmalloc(
size_t size);
302 #define xrealloc libreport_xrealloc
303 void* xrealloc(
void *ptr,
size_t size);
304 #define xzalloc libreport_xzalloc
305 void* xzalloc(
size_t size);
306 #define xstrdup libreport_xstrdup
307 char* xstrdup(
const char *s);
308 #define xstrndup libreport_xstrndup
309 char* xstrndup(
const char *s,
int n);
311 #define xpipe libreport_xpipe
312 void xpipe(
int filedes[2]);
313 #define xdup libreport_xdup
315 #define xdup2 libreport_xdup2
316 void xdup2(
int from,
int to);
317 #define xmove_fd libreport_xmove_fd
318 void xmove_fd(
int from,
int to);
320 #define xwrite libreport_xwrite
321 void xwrite(
int fd,
const void *buf,
size_t count);
322 #define xwrite_str libreport_xwrite_str
323 void xwrite_str(
int fd,
const char *str);
325 #define xlseek libreport_xlseek
326 off_t xlseek(
int fd, off_t offset,
int whence);
328 #define xchdir libreport_xchdir
329 void xchdir(
const char *path);
331 #define xvasprintf libreport_xvasprintf
332 char* xvasprintf(
const char *format, va_list p);
333 #define xasprintf libreport_xasprintf
334 char* xasprintf(
const char *format, ...);
336 #define xsetenv libreport_xsetenv
337 void xsetenv(
const char *key,
const char *value);
348 #define safe_unsetenv libreport_safe_unsetenv
349 void safe_unsetenv(
const char *var_val);
351 #define xsocket libreport_xsocket
352 int xsocket(
int domain,
int type,
int protocol);
353 #define xbind libreport_xbind
354 void xbind(
int sockfd,
struct sockaddr *my_addr, socklen_t addrlen);
355 #define xlisten libreport_xlisten
356 void xlisten(
int s,
int backlog);
357 #define xsendto libreport_xsendto
358 ssize_t xsendto(
int s,
const void *buf,
size_t len,
359 const struct sockaddr *to, socklen_t tolen);
361 #define xstat libreport_xstat
362 void xstat(
const char *name,
struct stat *stat_buf);
363 #define fstat_st_size_or_die libreport_fstat_st_size_or_die
364 off_t fstat_st_size_or_die(
int fd);
366 #define xopen3 libreport_xopen3
367 int xopen3(
const char *pathname,
int flags,
int mode);
368 #define xopen libreport_xopen
369 int xopen(
const char *pathname,
int flags);
370 #define xunlink libreport_xunlink
371 void xunlink(
const char *pathname);
379 #define is_regular_file libreport_is_regular_file
380 int is_regular_file(
struct dirent *dent,
const char *dirname);
382 #define dot_or_dotdot libreport_dot_or_dotdot
383 bool dot_or_dotdot(
const char *filename);
384 #define last_char_is libreport_last_char_is
385 char *last_char_is(
const char *s,
int c);
387 #define string_to_bool libreport_string_to_bool
388 bool string_to_bool(
const char *s);
390 #define xseteuid libreport_xseteuid
391 void xseteuid(uid_t euid);
392 #define xsetegid libreport_xsetegid
393 void xsetegid(gid_t egid);
394 #define xsetreuid libreport_xsetreuid
395 void xsetreuid(uid_t ruid, uid_t euid);
396 #define xsetregid libreport_xsetregid
397 void xsetregid(gid_t rgid, gid_t egid);
401 #define bin2hex libreport_bin2hex
402 char* bin2hex(
char *dst,
const char *str,
int count);
404 #define hex2bin libreport_hex2bin
405 char* hex2bin(
char *dst,
const char *str,
int count);
410 LOGMODE_STDIO = (1 << 0),
411 LOGMODE_SYSLOG = (1 << 1),
412 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
413 LOGMODE_CUSTOM = (1 << 2),
416 #define g_custom_logger libreport_g_custom_logger
417 extern void (*g_custom_logger)(
const char*);
418 #define msg_prefix libreport_msg_prefix
419 extern const char *msg_prefix;
420 #define msg_eol libreport_msg_eol
421 extern const char *msg_eol;
422 #define logmode libreport_logmode
424 #define xfunc_error_retval libreport_xfunc_error_retval
425 extern int xfunc_error_retval;
428 #define g_verbose libreport_g_verbose
429 extern int g_verbose;
431 #define VERB1 if (g_verbose >= 1)
433 #define VERB2 if (g_verbose >= 2)
435 #define VERB3 if (g_verbose >= 3)
439 #define xfunc_die libreport_xfunc_die
440 void xfunc_die(
void) NORETURN;
441 #define log_msg libreport_log_msg
442 void log_msg(
const char *s, ...) __attribute__ ((format (printf, 1, 2)));
445 #define log(...) log_msg(__VA_ARGS__)
447 #define error_msg libreport_error_msg
448 void error_msg(
const char *s, ...) __attribute__ ((format (printf, 1, 2)));
449 #define error_msg_and_die libreport_error_msg_and_die
450 void error_msg_and_die(
const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
452 #define perror_msg libreport_perror_msg
453 void perror_msg(
const char *s, ...) __attribute__ ((format (printf, 1, 2)));
454 #define perror_msg_and_die libreport_perror_msg_and_die
455 void perror_msg_and_die(
const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
456 #define die_out_of_memory libreport_die_out_of_memory
457 void die_out_of_memory(
void) NORETURN;
475 #define strbuf_new libreport_strbuf_new
476 struct strbuf *strbuf_new(
void);
483 #define strbuf_free libreport_strbuf_free
491 #define strbuf_free_nobuf libreport_strbuf_free_nobuf
498 #define strbuf_clear libreport_strbuf_clear
505 #define strbuf_append_char libreport_strbuf_append_char
512 #define strbuf_append_str libreport_strbuf_append_str
520 #define strbuf_prepend_str libreport_strbuf_prepend_str
528 #define strbuf_append_strf libreport_strbuf_append_strf
530 const char *format, ...);
536 #define strbuf_append_strfv libreport_strbuf_append_strfv
538 const char *format, va_list p);
545 #define strbuf_prepend_strf libreport_strbuf_prepend_strf
547 const char *format, ...);
553 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv
555 const char *format, va_list p);
559 typedef GHashTable map_string_h;
560 #define new_map_string libreport_new_map_string
561 map_string_h *new_map_string(
void);
562 #define free_map_string libreport_free_map_string
563 void free_map_string(map_string_h *ms);
564 #define get_map_string_item_or_empty libreport_get_map_string_item_or_empty
565 const char *get_map_string_item_or_empty(map_string_h *ms,
const char *key);
567 const char *get_map_string_item_or_NULL(map_string_h *ms,
const char *key)
569 return (
const char*)g_hash_table_lookup(ms, key);
578 #define get_cmdline libreport_get_cmdline
579 char* get_cmdline(pid_t pid);
580 #define get_environ libreport_get_environ
581 char* get_environ(pid_t pid);
586 #define iso_date_string libreport_iso_date_string
587 char *iso_date_string(
const time_t *pt);
588 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
591 MAKEDESC_SHOW_FILES = (1 << 0),
592 MAKEDESC_SHOW_MULTILINE = (1 << 1),
593 MAKEDESC_SHOW_ONLY_LIST = (1 << 2),
594 MAKEDESC_WHITELIST = (1 << 3),
596 #define make_description libreport_make_description
597 char *make_description(problem_data_t *problem_data,
char **names_to_skip,
unsigned max_text_size,
unsigned desc_flags);
598 #define make_description_bz libreport_make_description_bz
599 char* make_description_bz(problem_data_t *problem_data,
unsigned max_text_size);
600 #define make_description_logger libreport_make_description_logger
601 char* make_description_logger(problem_data_t *problem_data,
unsigned max_text_size);
606 #define parse_release_for_bz libreport_parse_release_for_bz
607 void parse_release_for_bz(
const char *pRelease,
char **product,
char **version);
608 #define parse_release_for_rhts libreport_parse_release_for_rhts
609 void parse_release_for_rhts(
const char *pRelease,
char **product,
char **version);
625 #define load_conf_file libreport_load_conf_file
626 bool load_conf_file(
const char *pPath, map_string_h *settings,
bool skipKeysWithoutValue);
628 #define save_conf_file libreport_save_conf_file
629 bool save_conf_file(
const char *path, map_string_h *settings);
630 #define save_user_settings libreport_save_user_settings
631 bool save_user_settings();
632 #define load_user_settings libreport_load_user_settings
633 bool load_user_settings(
const char *application_name);
634 #define set_user_setting libreport_set_user_setting
635 void set_user_setting(
const char *name,
const char *value);
636 #define get_user_setting libreport_get_user_setting
637 const char *get_user_setting(
const char *name);
638 #define load_forbidden_words libreport_load_forbidden_words
639 GList *load_forbidden_words();
640 #define get_file_list libreport_get_file_list
641 GList *get_file_list(
const char *path,
const char *ext);
642 #define free_file_list libreport_free_file_list
643 void free_file_list(GList *filelist);
644 #define new_file_obj libreport_new_file_obj
645 file_obj_t *new_file_obj(
const char* fullpath,
const char* filename);
646 #define free_file_obj libreport_free_file_obj
648 #define load_workflow_config_data libreport_load_workflow_config_data
649 GHashTable *load_workflow_config_data(
const char* path);
652 int delete_dump_dir_possibly_using_abrtd(
const char *dump_dir_name);
656 #define steal_directory libreport_steal_directory
657 struct dump_dir *steal_directory(
const char *base_dir,
const char *dump_dir_name);
665 #define open_directory_for_writing libreport_open_directory_for_writing
666 struct dump_dir *open_directory_for_writing(
667 const char *dump_dir_name,
668 bool (*ask_continue)(
const char *,
const char *));
682 #define CD_MAX_TEXT_SIZE (1024*1024)
688 #define CD_TEXT_ATT_SIZE_BZ (4*1024)
690 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE)
694 #define FILENAME_TIME "time"
695 #define FILENAME_REASON "reason"
696 #define FILENAME_UID "uid"
704 #define FILENAME_ANALYZER "analyzer"
705 #define FILENAME_TYPE "type"
706 #define FILENAME_EXECUTABLE "executable"
707 #define FILENAME_PID "pid"
708 #define FILENAME_PWD "pwd"
709 #define FILENAME_ROOTDIR "rootdir"
710 #define FILENAME_BINARY "binary"
711 #define FILENAME_CMDLINE "cmdline"
712 #define FILENAME_COREDUMP "coredump"
713 #define FILENAME_CGROUP "cgroup"
714 #define FILENAME_BACKTRACE "backtrace"
715 #define FILENAME_MAPS "maps"
716 #define FILENAME_SMAPS "smaps"
717 #define FILENAME_PROC_PID_STATUS "proc_pid_status"
718 #define FILENAME_ENVIRON "environ"
719 #define FILENAME_LIMITS "limits"
720 #define FILENAME_OPEN_FDS "open_fds"
725 #define FILENAME_DUPHASH "duphash"
729 #define FILENAME_CRASH_FUNCTION "crash_function"
730 #define FILENAME_ARCHITECTURE "architecture"
731 #define FILENAME_KERNEL "kernel"
733 #define FILENAME_OS_RELEASE "os_release"
734 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir"
736 #define FILENAME_PACKAGE "package"
737 #define FILENAME_COMPONENT "component"
738 #define FILENAME_COMMENT "comment"
739 #define FILENAME_RATING "backtrace_rating"
740 #define FILENAME_HOSTNAME "hostname"
742 #define FILENAME_REMOTE "remote"
743 #define FILENAME_TAINTED "kernel_tainted"
744 #define FILENAME_TAINTED_SHORT "kernel_tainted_short"
745 #define FILENAME_TAINTED_LONG "kernel_tainted_long"
746 #define FILENAME_VMCORE "vmcore"
747 #define FILENAME_KERNEL_LOG "kernel_log"
750 #define FILENAME_DESCRIPTION "description"
756 #define FILENAME_UUID "uuid"
758 #define FILENAME_COUNT "count"
765 #define FILENAME_REPORTED_TO "reported_to"
766 #define FILENAME_EVENT_LOG "event_log"
772 #define FILENAME_NOT_REPORTABLE "not-reportable"
773 #define FILENAME_CORE_BACKTRACE "core_backtrace"
774 #define FILENAME_REMOTE_RESULT "remote_result"
775 #define FILENAME_PKG_EPOCH "pkg_epoch"
776 #define FILENAME_PKG_NAME "pkg_name"
777 #define FILENAME_PKG_VERSION "pkg_version"
778 #define FILENAME_PKG_RELEASE "pkg_release"
779 #define FILENAME_PKG_ARCH "pkg_arch"
780 #define FILENAME_USERNAME "username"
781 #define FILENAME_ABRT_VERSION "abrt_version"
784 #define CD_DUMPDIR "Directory"
786 #define cmp_problem_data libreport_cmp_problem_data
787 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename);
798 EVENT_LOG_HIGH_WATERMARK = 30 * 1024,
799 EVENT_LOG_LOW_WATERMARK = 20 * 1024,
802 #define log_problem_data libreport_log_problem_data
803 void log_problem_data(problem_data_t *problem_data,
const char *pfx);
806 const char *abrt_init(
char **argv);
807 #define export_abrt_envvars libreport_export_abrt_envvars
808 void export_abrt_envvars(
int pfx);
809 #define g_progname libreport_g_progname
810 extern const char *g_progname;
812 enum parse_opt_type {
823 enum parse_opt_type type;
825 const char *long_name;
838 #define OPT_END() { OPTION_END }
839 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
840 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) }
841 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) }
842 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) }
843 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) }
844 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) }
846 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose"))
847 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
849 #define parse_opts libreport_parse_opts
850 unsigned parse_opts(
int argc,
char **argv,
const struct options *opt,
853 #define show_usage_and_die libreport_show_usage_and_die
854 void show_usage_and_die(
const char *usage,
const struct options *opt) NORETURN;
859 struct abrt_post_state;