libreport
2.1.3
A tool to inform users about various problems on the running system
|
00001 /* 00002 Copyright (C) 2010 ABRT team 00003 Copyright (C) 2010 RedHat Inc 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #ifndef LIBREPORT_INTERNAL_H_ 00021 #define LIBREPORT_INTERNAL_H_ 00022 00023 #include <assert.h> 00024 #include <ctype.h> 00025 #include <dirent.h> 00026 #include <errno.h> 00027 #include <fcntl.h> 00028 #include <inttypes.h> 00029 #include <setjmp.h> 00030 #include <signal.h> 00031 #include <stdio.h> 00032 #include <stdlib.h> 00033 #include <stdarg.h> 00034 #include <stddef.h> 00035 #include <string.h> 00036 #include <sys/poll.h> 00037 #include <sys/mman.h> 00038 #include <sys/socket.h> 00039 #include <sys/stat.h> 00040 #include <sys/time.h> 00041 #include <sys/types.h> 00042 #include <sys/wait.h> 00043 #include <arpa/inet.h> /* sockaddr_in, sockaddr_in6 etc */ 00044 #include <termios.h> 00045 #include <time.h> 00046 #include <unistd.h> 00047 #include <stdbool.h> 00048 /* Try to pull in PATH_MAX */ 00049 #include <limits.h> 00050 #include <sys/param.h> 00051 #ifndef PATH_MAX 00052 # define PATH_MAX 256 00053 #endif 00054 #include <pwd.h> 00055 #include <grp.h> 00056 #include <glib.h> 00057 00058 #ifdef HAVE_CONFIG_H 00059 # include "config.h" 00060 #endif 00061 00062 /* Must be after #include "config.h" */ 00063 #if ENABLE_NLS 00064 # include <libintl.h> 00065 # define _(S) gettext(S) 00066 #else 00067 # define _(S) (S) 00068 #endif 00069 00070 #if HAVE_LOCALE_H 00071 # include <locale.h> 00072 #endif /* HAVE_LOCALE_H */ 00073 00074 /* Some libc's forget to declare these, do it ourself */ 00075 extern char **environ; 00076 #if defined(__GLIBC__) && __GLIBC__ < 2 00077 int vdprintf(int d, const char *format, va_list ap); 00078 #endif 00079 00080 #undef NORETURN 00081 #define NORETURN __attribute__ ((noreturn)) 00082 00083 #undef ERR_PTR 00084 #define ERR_PTR ((void*)(uintptr_t)1) 00085 00086 #undef ARRAY_SIZE 00087 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) 00088 00089 00090 /* Pull in entire public libreport API */ 00091 #include "dump_dir.h" 00092 #include "event_config.h" 00093 #include "problem_data.h" 00094 #include "report.h" 00095 #include "run_event.h" 00096 #include "workflow.h" 00097 #include "file_obj.h" 00098 00099 #ifdef __cplusplus 00100 extern "C" { 00101 #endif 00102 00103 #define prefixcmp libreport_prefixcmp 00104 int prefixcmp(const char *str, const char *prefix); 00105 #define suffixcmp libreport_suffixcmp 00106 int suffixcmp(const char *str, const char *suffix); 00107 #define strtrim libreport_strtrim 00108 char *strtrim(char *str); 00109 #define strtrimch libreport_strtrimch 00110 char *strtrimch(char *str, int ch); 00111 #define concat_path_file libreport_concat_path_file 00112 char *concat_path_file(const char *path, const char *filename); 00113 #define append_to_malloced_string libreport_append_to_malloced_string 00114 char *append_to_malloced_string(char *mstr, const char *append); 00115 #define skip_whitespace libreport_skip_whitespace 00116 char* skip_whitespace(const char *s); 00117 #define skip_non_whitespace libreport_skip_non_whitespace 00118 char* skip_non_whitespace(const char *s); 00119 /* Like strcpy but can copy overlapping strings. */ 00120 #define overlapping_strcpy libreport_overlapping_strcpy 00121 void overlapping_strcpy(char *dst, const char *src); 00122 00123 /* A-la fgets, but malloced and of unlimited size */ 00124 #define xmalloc_fgets libreport_xmalloc_fgets 00125 char *xmalloc_fgets(FILE *file); 00126 /* Similar, but removes trailing \n */ 00127 #define xmalloc_fgetline libreport_xmalloc_fgetline 00128 char *xmalloc_fgetline(FILE *file); 00129 /* Useful for easy reading of various /proc files */ 00130 #define xmalloc_fopen_fgetline_fclose libreport_xmalloc_fopen_fgetline_fclose 00131 char *xmalloc_fopen_fgetline_fclose(const char *filename); 00132 00133 00134 /* On error, copyfd_XX prints error messages and returns -1 */ 00135 enum { 00136 COPYFD_SPARSE = 1 << 0, 00137 }; 00138 #define copyfd_eof libreport_copyfd_eof 00139 off_t copyfd_eof(int src_fd, int dst_fd, int flags); 00140 #define copyfd_size libreport_copyfd_size 00141 off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags); 00142 #define copyfd_exact_size libreport_copyfd_exact_size 00143 void copyfd_exact_size(int src_fd, int dst_fd, off_t size); 00144 #define copy_file libreport_copy_file 00145 off_t copy_file(const char *src_name, const char *dst_name, int mode); 00146 #define copy_file_recursive libreport_copy_file_recursive 00147 int copy_file_recursive(const char *source, const char *dest); 00148 00149 // NB: will return short read on error, not -1, 00150 // if some data was read before error occurred 00151 #define xread libreport_xread 00152 void xread(int fd, void *buf, size_t count); 00153 #define safe_read libreport_safe_read 00154 ssize_t safe_read(int fd, void *buf, size_t count); 00155 #define safe_write libreport_safe_write 00156 ssize_t safe_write(int fd, const void *buf, size_t count); 00157 #define full_read libreport_full_read 00158 ssize_t full_read(int fd, void *buf, size_t count); 00159 #define full_write libreport_full_write 00160 ssize_t full_write(int fd, const void *buf, size_t count); 00161 #define full_write_str libreport_full_write_str 00162 ssize_t full_write_str(int fd, const char *buf); 00163 #define xmalloc_read libreport_xmalloc_read 00164 void* xmalloc_read(int fd, size_t *maxsz_p); 00165 #define xmalloc_open_read_close libreport_xmalloc_open_read_close 00166 void* xmalloc_open_read_close(const char *filename, size_t *maxsz_p); 00167 #define xmalloc_xopen_read_close libreport_xmalloc_xopen_read_close 00168 void* xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p); 00169 00170 00171 /* Returns malloc'ed block */ 00172 #define encode_base64 libreport_encode_base64 00173 char *encode_base64(const void *src, int length); 00174 00175 /* Returns NULL if the string needs no sanitizing. 00176 * control_chars_to_sanitize is a bit mask. 00177 * If Nth bit is set, Nth control char will be sanitized (replaced by [XX]). 00178 */ 00179 #define sanitize_utf8 libreport_sanitize_utf8 00180 char *sanitize_utf8(const char *src, uint32_t control_chars_to_sanitize); 00181 enum { 00182 SANITIZE_ALL = 0xffffffff, 00183 SANITIZE_TAB = (1 << 9), 00184 SANITIZE_LF = (1 << 10), 00185 SANITIZE_CR = (1 << 13), 00186 }; 00187 00188 #define SHA1_RESULT_LEN (5 * 4) 00189 typedef struct sha1_ctx_t { 00190 uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ 00191 /* for sha256: void (*process_block)(struct md5_ctx_t*); */ 00192 uint64_t total64; /* must be directly before hash[] */ 00193 uint32_t hash[8]; /* 4 elements for md5, 5 for sha1, 8 for sha256 */ 00194 } sha1_ctx_t; 00195 #define sha1_begin libreport_sha1_begin 00196 void sha1_begin(sha1_ctx_t *ctx); 00197 #define sha1_hash libreport_sha1_hash 00198 void sha1_hash(sha1_ctx_t *ctx, const void *buffer, size_t len); 00199 #define sha1_end libreport_sha1_end 00200 void sha1_end(sha1_ctx_t *ctx, void *resbuf); 00201 00202 00203 #define xatou libreport_xatou 00204 unsigned xatou(const char *numstr); 00205 #define xatoi libreport_xatoi 00206 int xatoi(const char *numstr); 00207 /* Using xatoi() instead of naive atoi() is not always convenient - 00208 * in many places people want *non-negative* values, but store them 00209 * in signed int. Therefore we need this one: 00210 * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc. 00211 * It should really be named xatoi_nonnegative (since it allows 0), 00212 * but that would be too long. 00213 */ 00214 #define xatoi_positive libreport_xatoi_positive 00215 int xatoi_positive(const char *numstr); 00216 00217 //unused for now 00218 //unsigned long long monotonic_ns(void); 00219 //unsigned long long monotonic_us(void); 00220 //unsigned monotonic_sec(void); 00221 00222 #define safe_waitpid libreport_safe_waitpid 00223 pid_t safe_waitpid(pid_t pid, int *wstat, int options); 00224 00225 enum { 00226 /* on return, pipefds[1] is fd to which parent may write 00227 * and deliver data to child's stdin: */ 00228 EXECFLG_INPUT = 1 << 0, 00229 /* on return, pipefds[0] is fd from which parent may read 00230 * child's stdout: */ 00231 EXECFLG_OUTPUT = 1 << 1, 00232 /* open child's stdin to /dev/null: */ 00233 EXECFLG_INPUT_NUL = 1 << 2, 00234 /* open child's stdout to /dev/null: */ 00235 EXECFLG_OUTPUT_NUL = 1 << 3, 00236 /* redirect child's stderr to stdout: */ 00237 EXECFLG_ERR2OUT = 1 << 4, 00238 /* open child's stderr to /dev/null: */ 00239 EXECFLG_ERR_NUL = 1 << 5, 00240 /* suppress perror_msg("Can't execute 'foo'") if exec fails */ 00241 EXECFLG_QUIET = 1 << 6, 00242 EXECFLG_SETGUID = 1 << 7, 00243 EXECFLG_SETSID = 1 << 8, 00244 EXECFLG_SETPGID = 1 << 9, 00245 }; 00246 /* 00247 * env_vec: list of variables to set in environment (if string has 00248 * "VAR=VAL" form) or unset in environment (if string has no '=' char). 00249 * 00250 * Returns pid. 00251 */ 00252 #define fork_execv_on_steroids libreport_fork_execv_on_steroids 00253 pid_t fork_execv_on_steroids(int flags, 00254 char **argv, 00255 int *pipefds, 00256 char **env_vec, 00257 const char *dir, 00258 uid_t uid); 00259 /* Returns malloc'ed string. NULs are retained, and extra one is appended 00260 * after the last byte (this NUL is not accounted for in *size_p) */ 00261 #define run_in_shell_and_save_output libreport_run_in_shell_and_save_output 00262 char *run_in_shell_and_save_output(int flags, 00263 const char *cmd, 00264 const char *dir, 00265 size_t *size_p); 00266 00267 /* Random utility functions */ 00268 00269 #define is_in_string_list libreport_is_in_string_list 00270 bool is_in_string_list(const char *name, char **v); 00271 00272 #define is_in_comma_separated_list libreport_is_in_comma_separated_list 00273 bool is_in_comma_separated_list(const char *value, const char *list); 00274 #define is_in_comma_separated_list_of_glob_patterns libreport_is_in_comma_separated_list_of_glob_patterns 00275 bool is_in_comma_separated_list_of_glob_patterns(const char *value, const char *list); 00276 00277 /* Frees every element'd data using free(), 00278 * then frees list itself using g_list_free(list): 00279 */ 00280 #define list_free_with_free libreport_list_free_with_free 00281 void list_free_with_free(GList *list); 00282 00283 #define get_dirsize libreport_get_dirsize 00284 double get_dirsize(const char *pPath); 00285 #define get_dirsize_find_largest_dir libreport_get_dirsize_find_largest_dir 00286 double get_dirsize_find_largest_dir( 00287 const char *pPath, 00288 char **worst_dir, /* can be NULL */ 00289 const char *excluded /* can be NULL */ 00290 ); 00291 00292 00293 #define ndelay_on libreport_ndelay_on 00294 int ndelay_on(int fd); 00295 #define ndelay_off libreport_ndelay_off 00296 int ndelay_off(int fd); 00297 #define close_on_exec_on libreport_close_on_exec_on 00298 int close_on_exec_on(int fd); 00299 00300 #define xmalloc libreport_xmalloc 00301 void* xmalloc(size_t size); 00302 #define xrealloc libreport_xrealloc 00303 void* xrealloc(void *ptr, size_t size); 00304 #define xzalloc libreport_xzalloc 00305 void* xzalloc(size_t size); 00306 #define xstrdup libreport_xstrdup 00307 char* xstrdup(const char *s); 00308 #define xstrndup libreport_xstrndup 00309 char* xstrndup(const char *s, int n); 00310 00311 #define xpipe libreport_xpipe 00312 void xpipe(int filedes[2]); 00313 #define xdup libreport_xdup 00314 int xdup(int from); 00315 #define xdup2 libreport_xdup2 00316 void xdup2(int from, int to); 00317 #define xmove_fd libreport_xmove_fd 00318 void xmove_fd(int from, int to); 00319 00320 #define xwrite libreport_xwrite 00321 void xwrite(int fd, const void *buf, size_t count); 00322 #define xwrite_str libreport_xwrite_str 00323 void xwrite_str(int fd, const char *str); 00324 00325 #define xlseek libreport_xlseek 00326 off_t xlseek(int fd, off_t offset, int whence); 00327 00328 #define xchdir libreport_xchdir 00329 void xchdir(const char *path); 00330 00331 #define xvasprintf libreport_xvasprintf 00332 char* xvasprintf(const char *format, va_list p); 00333 #define xasprintf libreport_xasprintf 00334 char* xasprintf(const char *format, ...); 00335 00336 #define xsetenv libreport_xsetenv 00337 void xsetenv(const char *key, const char *value); 00338 /* 00339 * Utility function to unsetenv a string which was possibly putenv'ed. 00340 * The problem here is that "natural" optimization: 00341 * strchrnul(var_val, '=')[0] = '\0'; 00342 * unsetenv(var_val); 00343 * is BUGGY: if string was put into environment via putenv, 00344 * its modification (s/=/NUL/) is illegal, and unsetenv will fail to unset it. 00345 * Of course, saving/restoring the char wouldn't work either. 00346 * This helper creates a copy up to '=', unsetenv's it, and frees: 00347 */ 00348 #define safe_unsetenv libreport_safe_unsetenv 00349 void safe_unsetenv(const char *var_val); 00350 00351 #define xsocket libreport_xsocket 00352 int xsocket(int domain, int type, int protocol); 00353 #define xbind libreport_xbind 00354 void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); 00355 #define xlisten libreport_xlisten 00356 void xlisten(int s, int backlog); 00357 #define xsendto libreport_xsendto 00358 ssize_t xsendto(int s, const void *buf, size_t len, 00359 const struct sockaddr *to, socklen_t tolen); 00360 00361 #define xstat libreport_xstat 00362 void xstat(const char *name, struct stat *stat_buf); 00363 #define fstat_st_size_or_die libreport_fstat_st_size_or_die 00364 off_t fstat_st_size_or_die(int fd); 00365 #define stat_st_size_or_die libreport_stat_st_size_or_die 00366 off_t stat_st_size_or_die(const char *filename); 00367 00368 #define xopen3 libreport_xopen3 00369 int xopen3(const char *pathname, int flags, int mode); 00370 #define xopen libreport_xopen 00371 int xopen(const char *pathname, int flags); 00372 #define xunlink libreport_xunlink 00373 void xunlink(const char *pathname); 00374 00375 /* Just testing dent->d_type == DT_REG is wrong: some filesystems 00376 * do not report the type, they report DT_UNKNOWN for every dirent 00377 * (and this is not a bug in filesystem, this is allowed by standards). 00378 * This function handles this case. Note: it returns 0 on symlinks 00379 * even if they point to regular files. 00380 */ 00381 #define is_regular_file libreport_is_regular_file 00382 int is_regular_file(struct dirent *dent, const char *dirname); 00383 00384 #define dot_or_dotdot libreport_dot_or_dotdot 00385 bool dot_or_dotdot(const char *filename); 00386 #define last_char_is libreport_last_char_is 00387 char *last_char_is(const char *s, int c); 00388 00389 #define string_to_bool libreport_string_to_bool 00390 bool string_to_bool(const char *s); 00391 00392 #define xseteuid libreport_xseteuid 00393 void xseteuid(uid_t euid); 00394 #define xsetegid libreport_xsetegid 00395 void xsetegid(gid_t egid); 00396 #define xsetreuid libreport_xsetreuid 00397 void xsetreuid(uid_t ruid, uid_t euid); 00398 #define xsetregid libreport_xsetregid 00399 void xsetregid(gid_t rgid, gid_t egid); 00400 00401 00402 /* Emit a string of hex representation of bytes */ 00403 #define bin2hex libreport_bin2hex 00404 char* bin2hex(char *dst, const char *str, int count); 00405 /* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */ 00406 #define hex2bin libreport_hex2bin 00407 char* hex2bin(char *dst, const char *str, int count); 00408 00409 00410 enum { 00411 LOGMODE_NONE = 0, 00412 LOGMODE_STDIO = (1 << 0), 00413 LOGMODE_SYSLOG = (1 << 1), 00414 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, 00415 LOGMODE_CUSTOM = (1 << 2), 00416 }; 00417 00418 #define g_custom_logger libreport_g_custom_logger 00419 extern void (*g_custom_logger)(const char*); 00420 #define msg_prefix libreport_msg_prefix 00421 extern const char *msg_prefix; 00422 #define msg_eol libreport_msg_eol 00423 extern const char *msg_eol; 00424 #define logmode libreport_logmode 00425 extern int logmode; 00426 #define xfunc_error_retval libreport_xfunc_error_retval 00427 extern int xfunc_error_retval; 00428 00429 /* Verbosity level */ 00430 #define g_verbose libreport_g_verbose 00431 extern int g_verbose; 00432 /* VERB1 log("what you sometimes want to see, even on a production box") */ 00433 #define VERB1 if (g_verbose >= 1) 00434 /* VERB2 log("debug message, not going into insanely small details") */ 00435 #define VERB2 if (g_verbose >= 2) 00436 /* VERB3 log("lots and lots of details") */ 00437 #define VERB3 if (g_verbose >= 3) 00438 /* there is no level > 3 */ 00439 00440 #define libreport_ 00441 #define xfunc_die libreport_xfunc_die 00442 void xfunc_die(void) NORETURN; 00443 #define log_msg libreport_log_msg 00444 void log_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 00445 /* It's a macro, not function, since it collides with log() from math.h */ 00446 #undef log 00447 #define log(...) log_msg(__VA_ARGS__) 00448 /* error_msg family will use g_custom_logger. log_msg does not. */ 00449 #define error_msg libreport_error_msg 00450 void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 00451 #define error_msg_and_die libreport_error_msg_and_die 00452 void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 00453 /* Reports error message with libc's errno error description attached. */ 00454 #define perror_msg libreport_perror_msg 00455 void perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 00456 #define perror_msg_and_die libreport_perror_msg_and_die 00457 void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 00458 #define die_out_of_memory libreport_die_out_of_memory 00459 void die_out_of_memory(void) NORETURN; 00460 00461 00462 struct strbuf 00463 { 00464 /* Size of the allocated buffer. Always > 0. */ 00465 int alloc; 00466 /* Length of the string, without the ending \0. */ 00467 int len; 00468 char *buf; 00469 }; 00470 00477 #define strbuf_new libreport_strbuf_new 00478 struct strbuf *strbuf_new(void); 00479 00485 #define strbuf_free libreport_strbuf_free 00486 void strbuf_free(struct strbuf *strbuf); 00487 00493 #define strbuf_free_nobuf libreport_strbuf_free_nobuf 00494 char* strbuf_free_nobuf(struct strbuf *strbuf); 00495 00500 #define strbuf_clear libreport_strbuf_clear 00501 void strbuf_clear(struct strbuf *strbuf); 00502 00507 #define strbuf_append_char libreport_strbuf_append_char 00508 struct strbuf *strbuf_append_char(struct strbuf *strbuf, char c); 00509 00514 #define strbuf_append_str libreport_strbuf_append_str 00515 struct strbuf *strbuf_append_str(struct strbuf *strbuf, 00516 const char *str); 00517 00522 #define strbuf_prepend_str libreport_strbuf_prepend_str 00523 struct strbuf *strbuf_prepend_str(struct strbuf *strbuf, 00524 const char *str); 00525 00530 #define strbuf_append_strf libreport_strbuf_append_strf 00531 struct strbuf *strbuf_append_strf(struct strbuf *strbuf, 00532 const char *format, ...); 00533 00538 #define strbuf_append_strfv libreport_strbuf_append_strfv 00539 struct strbuf *strbuf_append_strfv(struct strbuf *strbuf, 00540 const char *format, va_list p); 00541 00547 #define strbuf_prepend_strf libreport_strbuf_prepend_strf 00548 struct strbuf *strbuf_prepend_strf(struct strbuf *strbuf, 00549 const char *format, ...); 00550 00555 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv 00556 struct strbuf *strbuf_prepend_strfv(struct strbuf *strbuf, 00557 const char *format, va_list p); 00558 00559 00560 /* TODO: rename to map_string_t */ 00561 typedef GHashTable map_string_h; 00562 #define new_map_string libreport_new_map_string 00563 map_string_h *new_map_string(void); 00564 #define free_map_string libreport_free_map_string 00565 void free_map_string(map_string_h *ms); 00566 #define get_map_string_item_or_empty libreport_get_map_string_item_or_empty 00567 const char *get_map_string_item_or_empty(map_string_h *ms, const char *key); 00568 static inline 00569 const char *get_map_string_item_or_NULL(map_string_h *ms, const char *key) 00570 { 00571 return (const char*)g_hash_table_lookup(ms, key); 00572 } 00573 00574 00575 /* Returns command line of running program. 00576 * Caller is responsible to free() the returned value. 00577 * If the pid is not valid or command line can not be obtained, 00578 * empty string is returned. 00579 */ 00580 #define get_cmdline libreport_get_cmdline 00581 char* get_cmdline(pid_t pid); 00582 #define get_environ libreport_get_environ 00583 char* get_environ(pid_t pid); 00584 00585 /* Takes ptr to time_t, or NULL if you want to use current time. 00586 * Returns "YYYY-MM-DD-hh:mm:ss" string. 00587 */ 00588 #define iso_date_string libreport_iso_date_string 00589 char *iso_date_string(const time_t *pt); 00590 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss" 00591 00592 enum { 00593 MAKEDESC_SHOW_FILES = (1 << 0), 00594 MAKEDESC_SHOW_MULTILINE = (1 << 1), 00595 MAKEDESC_SHOW_ONLY_LIST = (1 << 2), 00596 MAKEDESC_WHITELIST = (1 << 3), 00597 }; 00598 #define make_description libreport_make_description 00599 char *make_description(problem_data_t *problem_data, char **names_to_skip, unsigned max_text_size, unsigned desc_flags); 00600 #define make_description_bz libreport_make_description_bz 00601 char* make_description_bz(problem_data_t *problem_data, unsigned max_text_size); 00602 #define make_description_logger libreport_make_description_logger 00603 char* make_description_logger(problem_data_t *problem_data, unsigned max_text_size); 00604 //UNUSED 00605 //#define make_description_mailx libreport_make_description_mailx 00606 //char* make_description_mailx(problem_data_t *problem_data); 00607 00608 #define parse_release_for_bz libreport_parse_release_for_bz 00609 void parse_release_for_bz(const char *pRelease, char **product, char **version); 00610 #define parse_release_for_rhts libreport_parse_release_for_rhts 00611 void parse_release_for_rhts(const char *pRelease, char **product, char **version); 00612 00627 #define load_conf_file libreport_load_conf_file 00628 bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue); 00629 00630 #define save_conf_file libreport_save_conf_file 00631 bool save_conf_file(const char *path, map_string_h *settings); 00632 #define save_user_settings libreport_save_user_settings 00633 bool save_user_settings(); 00634 #define load_user_settings libreport_load_user_settings 00635 bool load_user_settings(const char *application_name); 00636 #define set_user_setting libreport_set_user_setting 00637 void set_user_setting(const char *name, const char *value); 00638 #define get_user_setting libreport_get_user_setting 00639 const char *get_user_setting(const char *name); 00640 #define load_forbidden_words libreport_load_forbidden_words 00641 GList *load_forbidden_words(); 00642 #define get_file_list libreport_get_file_list 00643 GList *get_file_list(const char *path, const char *ext); 00644 #define free_file_list libreport_free_file_list 00645 void free_file_list(GList *filelist); 00646 #define new_file_obj libreport_new_file_obj 00647 file_obj_t *new_file_obj(const char* fullpath, const char* filename); 00648 #define free_file_obj libreport_free_file_obj 00649 void free_file_obj(file_obj_t *f); 00650 #define load_workflow_config_data libreport_load_workflow_config_data 00651 GHashTable *load_workflow_config_data(const char* path); 00652 00653 /* Connect to abrtd over unix domain socket, issue DELETE command */ 00654 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name); 00655 00656 /* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename. 00657 * Returns NULL if copying failed. In this case, logs a message before returning. */ 00658 #define steal_directory libreport_steal_directory 00659 struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name); 00660 00661 /* Tries to open dump_dir_name with writing access. If function needs to steal 00662 * directory calls ask_continue(new base dir, dump dir) callback to ask user 00663 * for permission. If ask_continue param is NULL the function thinks that an 00664 * answer is positive and steals directory. 00665 * Returns NULL if opening failed or if stealing was dismissed. In this case, 00666 * logs a message before returning. */ 00667 #define open_directory_for_writing libreport_open_directory_for_writing 00668 struct dump_dir *open_directory_for_writing( 00669 const char *dump_dir_name, 00670 bool (*ask_continue)(const char *, const char *)); 00671 00672 // Files bigger than this are never considered to be text. 00673 // 00674 // Started at 64k limit. But _some_ limit is necessary: 00675 // fields declared "text" may end up in editing fields and such. 00676 // We don't want to accidentally end up with 100meg text in a textbox! 00677 // So, don't remove this. If you really need to, raise the limit. 00678 // 00679 // Bumped up to 200k: saw 124740 byte /proc/PID/smaps file 00680 // Bumped up to 500k: saw 375252 byte anaconda traceback file 00681 // Bumped up to 1M: bugzilla.redhat.com/show_bug.cgi?id=746727 00682 // mentions 853646 byte anaconda-tb-* file. 00683 // 00684 #define CD_MAX_TEXT_SIZE (1024*1024) 00685 00686 // Text bigger than this usually is attached, not added inline 00687 // was 2k, 20kb is too much, let's try 4kb 00688 // 00689 // For bug databases 00690 #define CD_TEXT_ATT_SIZE_BZ (4*1024) 00691 // For dumping problem data into a text file, email, etc 00692 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE) 00693 00694 // Filenames in problem directory: 00695 // filled by a hook: 00696 #define FILENAME_TIME "time" /* mandatory */ 00697 #define FILENAME_REASON "reason" /* mandatory? */ 00698 #define FILENAME_UID "uid" /* mandatory? */ 00699 /* 00700 * "analyzer" is to be gradually changed to "type": 00701 * For now, we fetch and look at "analyzer" element, 00702 * but we always save both "analyzer" and "type" (with same contents). 00703 * By 2013, we switch to looking at "type". Then we will stop generating 00704 * "analyzer" element. 00705 */ 00706 #define FILENAME_ANALYZER "analyzer" 00707 #define FILENAME_TYPE "type" 00708 #define FILENAME_EXECUTABLE "executable" 00709 #define FILENAME_PID "pid" 00710 #define FILENAME_PWD "pwd" 00711 #define FILENAME_ROOTDIR "rootdir" 00712 #define FILENAME_BINARY "binary" 00713 #define FILENAME_CMDLINE "cmdline" 00714 #define FILENAME_COREDUMP "coredump" 00715 #define FILENAME_CGROUP "cgroup" 00716 #define FILENAME_BACKTRACE "backtrace" 00717 #define FILENAME_MAPS "maps" 00718 #define FILENAME_SMAPS "smaps" 00719 #define FILENAME_PROC_PID_STATUS "proc_pid_status" 00720 #define FILENAME_ENVIRON "environ" 00721 #define FILENAME_LIMITS "limits" 00722 #define FILENAME_OPEN_FDS "open_fds" 00723 00724 /* Global problem identifier which is usually generated by some "analyze_*" 00725 * event because it may take a lot of time to obtain strong problem 00726 * identification */ 00727 #define FILENAME_DUPHASH "duphash" 00728 00729 // Name of the function where the application crashed. 00730 // Optional. 00731 #define FILENAME_CRASH_FUNCTION "crash_function" 00732 #define FILENAME_ARCHITECTURE "architecture" 00733 #define FILENAME_KERNEL "kernel" 00734 // From /etc/system-release or /etc/redhat-release 00735 #define FILENAME_OS_RELEASE "os_release" 00736 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir" 00737 // Filled by <what?> 00738 #define FILENAME_PACKAGE "package" 00739 #define FILENAME_COMPONENT "component" 00740 #define FILENAME_COMMENT "comment" 00741 #define FILENAME_RATING "backtrace_rating" 00742 #define FILENAME_HOSTNAME "hostname" 00743 // Optional. Set to "1" by abrt-handle-upload for every unpacked dump 00744 #define FILENAME_REMOTE "remote" 00745 #define FILENAME_TAINTED "kernel_tainted" 00746 #define FILENAME_TAINTED_SHORT "kernel_tainted_short" 00747 #define FILENAME_TAINTED_LONG "kernel_tainted_long" 00748 #define FILENAME_VMCORE "vmcore" 00749 #define FILENAME_KERNEL_LOG "kernel_log" 00750 // File created by createAlertSignature() from libreport's python module 00751 // The file should contain a description of an alert 00752 #define FILENAME_DESCRIPTION "description" 00753 00754 /* Local problem identifier (weaker than global identifier) designed for fast 00755 * local for fast local duplicate identification. This file is usually provided 00756 * by crashed application (problem creator). 00757 */ 00758 #define FILENAME_UUID "uuid" 00759 00760 #define FILENAME_COUNT "count" 00761 /* Multi-line list of places problem was reported. 00762 * Recommended line format: 00763 * "Reporter: VAR=VAL VAR=VAL" 00764 * Use add_reported_to(dd, "line_without_newline"): it adds line 00765 * only if it is not already there. 00766 */ 00767 #define FILENAME_REPORTED_TO "reported_to" 00768 #define FILENAME_EVENT_LOG "event_log" 00769 /* 00770 * If exists, should contain a full sentence (with trailing period) 00771 * which describes why this problem should not be reported. 00772 * Example: "Your laptop firmware 1.9a is buggy, version 1.10 contains the fix." 00773 */ 00774 #define FILENAME_NOT_REPORTABLE "not-reportable" 00775 #define FILENAME_CORE_BACKTRACE "core_backtrace" 00776 #define FILENAME_REMOTE_RESULT "remote_result" 00777 #define FILENAME_PKG_EPOCH "pkg_epoch" 00778 #define FILENAME_PKG_NAME "pkg_name" 00779 #define FILENAME_PKG_VERSION "pkg_version" 00780 #define FILENAME_PKG_RELEASE "pkg_release" 00781 #define FILENAME_PKG_ARCH "pkg_arch" 00782 #define FILENAME_USERNAME "username" 00783 #define FILENAME_ABRT_VERSION "abrt_version" 00784 00785 // Not stored as files, added "on the fly": 00786 #define CD_DUMPDIR "Directory" 00787 00788 #define cmp_problem_data libreport_cmp_problem_data 00789 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename); 00790 00791 //UNUSED: 00794 //#define CD_EVENTS "Events" 00795 00796 /* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK 00797 * when it reaches HIGH_WATERMARK size 00798 */ 00799 enum { 00800 EVENT_LOG_HIGH_WATERMARK = 30 * 1024, 00801 EVENT_LOG_LOW_WATERMARK = 20 * 1024, 00802 }; 00803 00804 #define log_problem_data libreport_log_problem_data 00805 void log_problem_data(problem_data_t *problem_data, const char *pfx); 00806 00807 00808 const char *abrt_init(char **argv); 00809 #define export_abrt_envvars libreport_export_abrt_envvars 00810 void export_abrt_envvars(int pfx); 00811 #define g_progname libreport_g_progname 00812 extern const char *g_progname; 00813 00814 enum parse_opt_type { 00815 OPTION_BOOL, 00816 OPTION_GROUP, 00817 OPTION_STRING, 00818 OPTION_INTEGER, 00819 OPTION_OPTSTRING, 00820 OPTION_LIST, 00821 OPTION_END, 00822 }; 00823 00824 struct options { 00825 enum parse_opt_type type; 00826 int short_name; 00827 const char *long_name; 00828 void *value; 00829 const char *argh; 00830 const char *help; 00831 }; 00832 00833 /* 00834 * s - short_name 00835 * l - long_name 00836 * v - value 00837 * a - option parameter name (for help text) 00838 * h - help 00839 */ 00840 #define OPT_END() { OPTION_END } 00841 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } 00842 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) } 00843 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) } 00844 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) } 00845 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) } 00846 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) } 00847 00848 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose")) 00849 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory")) 00850 00851 #define parse_opts libreport_parse_opts 00852 unsigned parse_opts(int argc, char **argv, const struct options *opt, 00853 const char *usage); 00854 00855 #define show_usage_and_die libreport_show_usage_and_die 00856 void show_usage_and_die(const char *usage, const struct options *opt) NORETURN; 00857 00858 /* Can't include "abrt_curl.h", it's not a public API. 00859 * Resorting to just forward-declaring the struct we need. 00860 */ 00861 struct abrt_post_state; 00862 00863 #ifdef __cplusplus 00864 } 00865 #endif 00866 00867 #endif