libreport  2.1.3
A tool to inform users about various problems on the running system
internal_libreport.h
1 /*
2  Copyright (C) 2010 ABRT team
3  Copyright (C) 2010 RedHat Inc
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef LIBREPORT_INTERNAL_H_
21 #define LIBREPORT_INTERNAL_H_
22 
23 #include <assert.h>
24 #include <ctype.h>
25 #include <dirent.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <inttypes.h>
29 #include <setjmp.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include <stddef.h>
35 #include <string.h>
36 #include <sys/poll.h>
37 #include <sys/mman.h>
38 #include <sys/socket.h>
39 #include <sys/stat.h>
40 #include <sys/time.h>
41 #include <sys/types.h>
42 #include <sys/wait.h>
43 #include <arpa/inet.h> /* sockaddr_in, sockaddr_in6 etc */
44 #include <termios.h>
45 #include <time.h>
46 #include <unistd.h>
47 #include <stdbool.h>
48 /* Try to pull in PATH_MAX */
49 #include <limits.h>
50 #include <sys/param.h>
51 #ifndef PATH_MAX
52 # define PATH_MAX 256
53 #endif
54 #include <pwd.h>
55 #include <grp.h>
56 #include <glib.h>
57 
58 #ifdef HAVE_CONFIG_H
59 # include "config.h"
60 #endif
61 
62 /* Must be after #include "config.h" */
63 #if ENABLE_NLS
64 # include <libintl.h>
65 # define _(S) gettext(S)
66 #else
67 # define _(S) (S)
68 #endif
69 
70 #if HAVE_LOCALE_H
71 # include <locale.h>
72 #endif /* HAVE_LOCALE_H */
73 
74 /* Some libc's forget to declare these, do it ourself */
75 extern char **environ;
76 #if defined(__GLIBC__) && __GLIBC__ < 2
77 int vdprintf(int d, const char *format, va_list ap);
78 #endif
79 
80 #undef NORETURN
81 #define NORETURN __attribute__ ((noreturn))
82 
83 #undef ERR_PTR
84 #define ERR_PTR ((void*)(uintptr_t)1)
85 
86 #undef ARRAY_SIZE
87 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
88 
89 
90 /* Pull in entire public libreport API */
91 #include "dump_dir.h"
92 #include "event_config.h"
93 #include "problem_data.h"
94 #include "report.h"
95 #include "run_event.h"
96 #include "workflow.h"
97 #include "file_obj.h"
98 
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102 
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);
119 /* Like strcpy but can copy overlapping strings. */
120 #define overlapping_strcpy libreport_overlapping_strcpy
121 void overlapping_strcpy(char *dst, const char *src);
122 
123 /* A-la fgets, but malloced and of unlimited size */
124 #define xmalloc_fgets libreport_xmalloc_fgets
125 char *xmalloc_fgets(FILE *file);
126 /* Similar, but removes trailing \n */
127 #define xmalloc_fgetline libreport_xmalloc_fgetline
128 char *xmalloc_fgetline(FILE *file);
129 /* Useful for easy reading of various /proc files */
130 #define xmalloc_fopen_fgetline_fclose libreport_xmalloc_fopen_fgetline_fclose
131 char *xmalloc_fopen_fgetline_fclose(const char *filename);
132 
133 
134 /* On error, copyfd_XX prints error messages and returns -1 */
135 enum {
136  COPYFD_SPARSE = 1 << 0,
137 };
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);
148 
149 // NB: will return short read on error, not -1,
150 // if some data was read before error occurred
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);
169 
170 
171 /* Returns malloc'ed block */
172 #define encode_base64 libreport_encode_base64
173 char *encode_base64(const void *src, int length);
174 
175 /* Returns NULL if the string needs no sanitizing.
176  * control_chars_to_sanitize is a bit mask.
177  * If Nth bit is set, Nth control char will be sanitized (replaced by [XX]).
178  */
179 #define sanitize_utf8 libreport_sanitize_utf8
180 char *sanitize_utf8(const char *src, uint32_t control_chars_to_sanitize);
181 enum {
182  SANITIZE_ALL = 0xffffffff,
183  SANITIZE_TAB = (1 << 9),
184  SANITIZE_LF = (1 << 10),
185  SANITIZE_CR = (1 << 13),
186 };
187 
188 #define SHA1_RESULT_LEN (5 * 4)
189 typedef struct sha1_ctx_t {
190  uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
191  /* for sha256: void (*process_block)(struct md5_ctx_t*); */
192  uint64_t total64; /* must be directly before hash[] */
193  uint32_t hash[8]; /* 4 elements for md5, 5 for sha1, 8 for sha256 */
194 } sha1_ctx_t;
195 #define sha1_begin libreport_sha1_begin
196 void sha1_begin(sha1_ctx_t *ctx);
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
200 void sha1_end(sha1_ctx_t *ctx, void *resbuf);
201 
202 
203 #define xatou libreport_xatou
204 unsigned xatou(const char *numstr);
205 #define xatoi libreport_xatoi
206 int xatoi(const char *numstr);
207 /* Using xatoi() instead of naive atoi() is not always convenient -
208  * in many places people want *non-negative* values, but store them
209  * in signed int. Therefore we need this one:
210  * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc.
211  * It should really be named xatoi_nonnegative (since it allows 0),
212  * but that would be too long.
213  */
214 #define xatoi_positive libreport_xatoi_positive
215 int xatoi_positive(const char *numstr);
216 
217 //unused for now
218 //unsigned long long monotonic_ns(void);
219 //unsigned long long monotonic_us(void);
220 //unsigned monotonic_sec(void);
221 
222 #define safe_waitpid libreport_safe_waitpid
223 pid_t safe_waitpid(pid_t pid, int *wstat, int options);
224 
225 enum {
226  /* on return, pipefds[1] is fd to which parent may write
227  * and deliver data to child's stdin: */
228  EXECFLG_INPUT = 1 << 0,
229  /* on return, pipefds[0] is fd from which parent may read
230  * child's stdout: */
231  EXECFLG_OUTPUT = 1 << 1,
232  /* open child's stdin to /dev/null: */
233  EXECFLG_INPUT_NUL = 1 << 2,
234  /* open child's stdout to /dev/null: */
235  EXECFLG_OUTPUT_NUL = 1 << 3,
236  /* redirect child's stderr to stdout: */
237  EXECFLG_ERR2OUT = 1 << 4,
238  /* open child's stderr to /dev/null: */
239  EXECFLG_ERR_NUL = 1 << 5,
240  /* suppress perror_msg("Can't execute 'foo'") if exec fails */
241  EXECFLG_QUIET = 1 << 6,
242  EXECFLG_SETGUID = 1 << 7,
243  EXECFLG_SETSID = 1 << 8,
244  EXECFLG_SETPGID = 1 << 9,
245 };
246 /*
247  * env_vec: list of variables to set in environment (if string has
248  * "VAR=VAL" form) or unset in environment (if string has no '=' char).
249  *
250  * Returns pid.
251  */
252 #define fork_execv_on_steroids libreport_fork_execv_on_steroids
253 pid_t fork_execv_on_steroids(int flags,
254  char **argv,
255  int *pipefds,
256  char **env_vec,
257  const char *dir,
258  uid_t uid);
259 /* Returns malloc'ed string. NULs are retained, and extra one is appended
260  * after the last byte (this NUL is not accounted for in *size_p) */
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,
263  const char *cmd,
264  const char *dir,
265  size_t *size_p);
266 
267 /* Random utility functions */
268 
269 #define is_in_string_list libreport_is_in_string_list
270 bool is_in_string_list(const char *name, char **v);
271 
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);
276 
277 /* Frees every element'd data using free(),
278  * then frees list itself using g_list_free(list):
279  */
280 #define list_free_with_free libreport_list_free_with_free
281 void list_free_with_free(GList *list);
282 
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(
287  const char *pPath,
288  char **worst_dir, /* can be NULL */
289  const char *excluded /* can be NULL */
290 );
291 
292 
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);
299 
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);
310 
311 #define xpipe libreport_xpipe
312 void xpipe(int filedes[2]);
313 #define xdup libreport_xdup
314 int xdup(int from);
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);
319 
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);
324 
325 #define xlseek libreport_xlseek
326 off_t xlseek(int fd, off_t offset, int whence);
327 
328 #define xchdir libreport_xchdir
329 void xchdir(const char *path);
330 
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, ...);
335 
336 #define xsetenv libreport_xsetenv
337 void xsetenv(const char *key, const char *value);
338 /*
339  * Utility function to unsetenv a string which was possibly putenv'ed.
340  * The problem here is that "natural" optimization:
341  * strchrnul(var_val, '=')[0] = '\0';
342  * unsetenv(var_val);
343  * is BUGGY: if string was put into environment via putenv,
344  * its modification (s/=/NUL/) is illegal, and unsetenv will fail to unset it.
345  * Of course, saving/restoring the char wouldn't work either.
346  * This helper creates a copy up to '=', unsetenv's it, and frees:
347  */
348 #define safe_unsetenv libreport_safe_unsetenv
349 void safe_unsetenv(const char *var_val);
350 
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);
360 
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);
365 #define stat_st_size_or_die libreport_stat_st_size_or_die
366 off_t stat_st_size_or_die(const char *filename);
367 
368 #define xopen3 libreport_xopen3
369 int xopen3(const char *pathname, int flags, int mode);
370 #define xopen libreport_xopen
371 int xopen(const char *pathname, int flags);
372 #define xunlink libreport_xunlink
373 void xunlink(const char *pathname);
374 
375 /* Just testing dent->d_type == DT_REG is wrong: some filesystems
376  * do not report the type, they report DT_UNKNOWN for every dirent
377  * (and this is not a bug in filesystem, this is allowed by standards).
378  * This function handles this case. Note: it returns 0 on symlinks
379  * even if they point to regular files.
380  */
381 #define is_regular_file libreport_is_regular_file
382 int is_regular_file(struct dirent *dent, const char *dirname);
383 
384 #define dot_or_dotdot libreport_dot_or_dotdot
385 bool dot_or_dotdot(const char *filename);
386 #define last_char_is libreport_last_char_is
387 char *last_char_is(const char *s, int c);
388 
389 #define string_to_bool libreport_string_to_bool
390 bool string_to_bool(const char *s);
391 
392 #define xseteuid libreport_xseteuid
393 void xseteuid(uid_t euid);
394 #define xsetegid libreport_xsetegid
395 void xsetegid(gid_t egid);
396 #define xsetreuid libreport_xsetreuid
397 void xsetreuid(uid_t ruid, uid_t euid);
398 #define xsetregid libreport_xsetregid
399 void xsetregid(gid_t rgid, gid_t egid);
400 
401 
402 /* Emit a string of hex representation of bytes */
403 #define bin2hex libreport_bin2hex
404 char* bin2hex(char *dst, const char *str, int count);
405 /* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */
406 #define hex2bin libreport_hex2bin
407 char* hex2bin(char *dst, const char *str, int count);
408 
409 
410 enum {
411  LOGMODE_NONE = 0,
412  LOGMODE_STDIO = (1 << 0),
413  LOGMODE_SYSLOG = (1 << 1),
414  LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
415  LOGMODE_CUSTOM = (1 << 2),
416 };
417 
418 #define g_custom_logger libreport_g_custom_logger
419 extern void (*g_custom_logger)(const char*);
420 #define msg_prefix libreport_msg_prefix
421 extern const char *msg_prefix;
422 #define msg_eol libreport_msg_eol
423 extern const char *msg_eol;
424 #define logmode libreport_logmode
425 extern int logmode;
426 #define xfunc_error_retval libreport_xfunc_error_retval
427 extern int xfunc_error_retval;
428 
429 /* Verbosity level */
430 #define g_verbose libreport_g_verbose
431 extern int g_verbose;
432 /* VERB1 log("what you sometimes want to see, even on a production box") */
433 #define VERB1 if (g_verbose >= 1)
434 /* VERB2 log("debug message, not going into insanely small details") */
435 #define VERB2 if (g_verbose >= 2)
436 /* VERB3 log("lots and lots of details") */
437 #define VERB3 if (g_verbose >= 3)
438 /* there is no level > 3 */
439 
440 #define libreport_
441 #define xfunc_die libreport_xfunc_die
442 void xfunc_die(void) NORETURN;
443 #define log_msg libreport_log_msg
444 void log_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
445 /* It's a macro, not function, since it collides with log() from math.h */
446 #undef log
447 #define log(...) log_msg(__VA_ARGS__)
448 /* error_msg family will use g_custom_logger. log_msg does not. */
449 #define error_msg libreport_error_msg
450 void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
451 #define error_msg_and_die libreport_error_msg_and_die
452 void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
453 /* Reports error message with libc's errno error description attached. */
454 #define perror_msg libreport_perror_msg
455 void perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
456 #define perror_msg_and_die libreport_perror_msg_and_die
457 void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
458 #define die_out_of_memory libreport_die_out_of_memory
459 void die_out_of_memory(void) NORETURN;
460 
461 
462 struct strbuf
463 {
464  /* Size of the allocated buffer. Always > 0. */
465  int alloc;
466  /* Length of the string, without the ending \0. */
467  int len;
468  char *buf;
469 };
470 
477 #define strbuf_new libreport_strbuf_new
478 struct strbuf *strbuf_new(void);
479 
485 #define strbuf_free libreport_strbuf_free
486 void strbuf_free(struct strbuf *strbuf);
487 
493 #define strbuf_free_nobuf libreport_strbuf_free_nobuf
494 char* strbuf_free_nobuf(struct strbuf *strbuf);
495 
500 #define strbuf_clear libreport_strbuf_clear
501 void strbuf_clear(struct strbuf *strbuf);
502 
507 #define strbuf_append_char libreport_strbuf_append_char
508 struct strbuf *strbuf_append_char(struct strbuf *strbuf, char c);
509 
514 #define strbuf_append_str libreport_strbuf_append_str
515 struct strbuf *strbuf_append_str(struct strbuf *strbuf,
516  const char *str);
517 
522 #define strbuf_prepend_str libreport_strbuf_prepend_str
523 struct strbuf *strbuf_prepend_str(struct strbuf *strbuf,
524  const char *str);
525 
530 #define strbuf_append_strf libreport_strbuf_append_strf
531 struct strbuf *strbuf_append_strf(struct strbuf *strbuf,
532  const char *format, ...);
533 
538 #define strbuf_append_strfv libreport_strbuf_append_strfv
539 struct strbuf *strbuf_append_strfv(struct strbuf *strbuf,
540  const char *format, va_list p);
541 
547 #define strbuf_prepend_strf libreport_strbuf_prepend_strf
548 struct strbuf *strbuf_prepend_strf(struct strbuf *strbuf,
549  const char *format, ...);
550 
555 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv
556 struct strbuf *strbuf_prepend_strfv(struct strbuf *strbuf,
557  const char *format, va_list p);
558 
559 
560 /* TODO: rename to map_string_t */
561 typedef GHashTable map_string_h;
562 #define new_map_string libreport_new_map_string
563 map_string_h *new_map_string(void);
564 #define free_map_string libreport_free_map_string
565 void free_map_string(map_string_h *ms);
566 #define get_map_string_item_or_empty libreport_get_map_string_item_or_empty
567 const char *get_map_string_item_or_empty(map_string_h *ms, const char *key);
568 static inline
569 const char *get_map_string_item_or_NULL(map_string_h *ms, const char *key)
570 {
571  return (const char*)g_hash_table_lookup(ms, key);
572 }
573 
574 
575 /* Returns command line of running program.
576  * Caller is responsible to free() the returned value.
577  * If the pid is not valid or command line can not be obtained,
578  * empty string is returned.
579  */
580 #define get_cmdline libreport_get_cmdline
581 char* get_cmdline(pid_t pid);
582 #define get_environ libreport_get_environ
583 char* get_environ(pid_t pid);
584 
585 /* Takes ptr to time_t, or NULL if you want to use current time.
586  * Returns "YYYY-MM-DD-hh:mm:ss" string.
587  */
588 #define iso_date_string libreport_iso_date_string
589 char *iso_date_string(const time_t *pt);
590 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
591 
592 enum {
593  MAKEDESC_SHOW_FILES = (1 << 0),
594  MAKEDESC_SHOW_MULTILINE = (1 << 1),
595  MAKEDESC_SHOW_ONLY_LIST = (1 << 2),
596  MAKEDESC_WHITELIST = (1 << 3),
597 };
598 #define make_description libreport_make_description
599 char *make_description(problem_data_t *problem_data, char **names_to_skip, unsigned max_text_size, unsigned desc_flags);
600 #define make_description_bz libreport_make_description_bz
601 char* make_description_bz(problem_data_t *problem_data, unsigned max_text_size);
602 #define make_description_logger libreport_make_description_logger
603 char* make_description_logger(problem_data_t *problem_data, unsigned max_text_size);
604 //UNUSED
605 //#define make_description_mailx libreport_make_description_mailx
606 //char* make_description_mailx(problem_data_t *problem_data);
607 
608 #define parse_release_for_bz libreport_parse_release_for_bz
609 void parse_release_for_bz(const char *pRelease, char **product, char **version);
610 #define parse_release_for_rhts libreport_parse_release_for_rhts
611 void parse_release_for_rhts(const char *pRelease, char **product, char **version);
612 
627 #define load_conf_file libreport_load_conf_file
628 bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue);
629 
630 #define save_conf_file libreport_save_conf_file
631 bool save_conf_file(const char *path, map_string_h *settings);
632 #define save_user_settings libreport_save_user_settings
633 bool save_user_settings();
634 #define load_user_settings libreport_load_user_settings
635 bool load_user_settings(const char *application_name);
636 #define set_user_setting libreport_set_user_setting
637 void set_user_setting(const char *name, const char *value);
638 #define get_user_setting libreport_get_user_setting
639 const char *get_user_setting(const char *name);
640 #define load_forbidden_words libreport_load_forbidden_words
641 GList *load_forbidden_words();
642 #define get_file_list libreport_get_file_list
643 GList *get_file_list(const char *path, const char *ext);
644 #define free_file_list libreport_free_file_list
645 void free_file_list(GList *filelist);
646 #define new_file_obj libreport_new_file_obj
647 file_obj_t *new_file_obj(const char* fullpath, const char* filename);
648 #define free_file_obj libreport_free_file_obj
649 void free_file_obj(file_obj_t *f);
650 #define load_workflow_config_data libreport_load_workflow_config_data
651 GHashTable *load_workflow_config_data(const char* path);
652 
653 /* Connect to abrtd over unix domain socket, issue DELETE command */
654 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
655 
656 /* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename.
657  * Returns NULL if copying failed. In this case, logs a message before returning. */
658 #define steal_directory libreport_steal_directory
659 struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name);
660 
661 /* Tries to open dump_dir_name with writing access. If function needs to steal
662  * directory calls ask_continue(new base dir, dump dir) callback to ask user
663  * for permission. If ask_continue param is NULL the function thinks that an
664  * answer is positive and steals directory.
665  * Returns NULL if opening failed or if stealing was dismissed. In this case,
666  * logs a message before returning. */
667 #define open_directory_for_writing libreport_open_directory_for_writing
668 struct dump_dir *open_directory_for_writing(
669  const char *dump_dir_name,
670  bool (*ask_continue)(const char *, const char *));
671 
672 // Files bigger than this are never considered to be text.
673 //
674 // Started at 64k limit. But _some_ limit is necessary:
675 // fields declared "text" may end up in editing fields and such.
676 // We don't want to accidentally end up with 100meg text in a textbox!
677 // So, don't remove this. If you really need to, raise the limit.
678 //
679 // Bumped up to 200k: saw 124740 byte /proc/PID/smaps file
680 // Bumped up to 500k: saw 375252 byte anaconda traceback file
681 // Bumped up to 1M: bugzilla.redhat.com/show_bug.cgi?id=746727
682 // mentions 853646 byte anaconda-tb-* file.
683 //
684 #define CD_MAX_TEXT_SIZE (1024*1024)
685 
686 // Text bigger than this usually is attached, not added inline
687 // was 2k, 20kb is too much, let's try 4kb
688 //
689 // For bug databases
690 #define CD_TEXT_ATT_SIZE_BZ (4*1024)
691 // For dumping problem data into a text file, email, etc
692 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE)
693 
694 // Filenames in problem directory:
695 // filled by a hook:
696 #define FILENAME_TIME "time" /* mandatory */
697 #define FILENAME_REASON "reason" /* mandatory? */
698 #define FILENAME_UID "uid" /* mandatory? */
699 /*
700  * "analyzer" is to be gradually changed to "type":
701  * For now, we fetch and look at "analyzer" element,
702  * but we always save both "analyzer" and "type" (with same contents).
703  * By 2013, we switch to looking at "type". Then we will stop generating
704  * "analyzer" element.
705  */
706 #define FILENAME_ANALYZER "analyzer"
707 #define FILENAME_TYPE "type"
708 #define FILENAME_EXECUTABLE "executable"
709 #define FILENAME_PID "pid"
710 #define FILENAME_PWD "pwd"
711 #define FILENAME_ROOTDIR "rootdir"
712 #define FILENAME_BINARY "binary"
713 #define FILENAME_CMDLINE "cmdline"
714 #define FILENAME_COREDUMP "coredump"
715 #define FILENAME_CGROUP "cgroup"
716 #define FILENAME_BACKTRACE "backtrace"
717 #define FILENAME_MAPS "maps"
718 #define FILENAME_SMAPS "smaps"
719 #define FILENAME_PROC_PID_STATUS "proc_pid_status"
720 #define FILENAME_ENVIRON "environ"
721 #define FILENAME_LIMITS "limits"
722 #define FILENAME_OPEN_FDS "open_fds"
723 
724 /* Global problem identifier which is usually generated by some "analyze_*"
725  * event because it may take a lot of time to obtain strong problem
726  * identification */
727 #define FILENAME_DUPHASH "duphash"
728 
729 // Name of the function where the application crashed.
730 // Optional.
731 #define FILENAME_CRASH_FUNCTION "crash_function"
732 #define FILENAME_ARCHITECTURE "architecture"
733 #define FILENAME_KERNEL "kernel"
734 // From /etc/system-release or /etc/redhat-release
735 #define FILENAME_OS_RELEASE "os_release"
736 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir"
737 // Filled by <what?>
738 #define FILENAME_PACKAGE "package"
739 #define FILENAME_COMPONENT "component"
740 #define FILENAME_COMMENT "comment"
741 #define FILENAME_RATING "backtrace_rating"
742 #define FILENAME_HOSTNAME "hostname"
743 // Optional. Set to "1" by abrt-handle-upload for every unpacked dump
744 #define FILENAME_REMOTE "remote"
745 #define FILENAME_TAINTED "kernel_tainted"
746 #define FILENAME_TAINTED_SHORT "kernel_tainted_short"
747 #define FILENAME_TAINTED_LONG "kernel_tainted_long"
748 #define FILENAME_VMCORE "vmcore"
749 #define FILENAME_KERNEL_LOG "kernel_log"
750 // File created by createAlertSignature() from libreport's python module
751 // The file should contain a description of an alert
752 #define FILENAME_DESCRIPTION "description"
753 
754 /* Local problem identifier (weaker than global identifier) designed for fast
755  * local for fast local duplicate identification. This file is usually provided
756  * by crashed application (problem creator).
757  */
758 #define FILENAME_UUID "uuid"
759 
760 #define FILENAME_COUNT "count"
761 /* Multi-line list of places problem was reported.
762  * Recommended line format:
763  * "Reporter: VAR=VAL VAR=VAL"
764  * Use add_reported_to(dd, "line_without_newline"): it adds line
765  * only if it is not already there.
766  */
767 #define FILENAME_REPORTED_TO "reported_to"
768 #define FILENAME_EVENT_LOG "event_log"
769 /*
770  * If exists, should contain a full sentence (with trailing period)
771  * which describes why this problem should not be reported.
772  * Example: "Your laptop firmware 1.9a is buggy, version 1.10 contains the fix."
773  */
774 #define FILENAME_NOT_REPORTABLE "not-reportable"
775 #define FILENAME_CORE_BACKTRACE "core_backtrace"
776 #define FILENAME_REMOTE_RESULT "remote_result"
777 #define FILENAME_PKG_EPOCH "pkg_epoch"
778 #define FILENAME_PKG_NAME "pkg_name"
779 #define FILENAME_PKG_VERSION "pkg_version"
780 #define FILENAME_PKG_RELEASE "pkg_release"
781 #define FILENAME_PKG_ARCH "pkg_arch"
782 #define FILENAME_USERNAME "username"
783 #define FILENAME_ABRT_VERSION "abrt_version"
784 
785 // Not stored as files, added "on the fly":
786 #define CD_DUMPDIR "Directory"
787 
788 #define cmp_problem_data libreport_cmp_problem_data
789 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename);
790 
791 //UNUSED:
794 //#define CD_EVENTS "Events"
795 
796 /* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK
797  * when it reaches HIGH_WATERMARK size
798  */
799 enum {
800  EVENT_LOG_HIGH_WATERMARK = 30 * 1024,
801  EVENT_LOG_LOW_WATERMARK = 20 * 1024,
802 };
803 
804 #define log_problem_data libreport_log_problem_data
805 void log_problem_data(problem_data_t *problem_data, const char *pfx);
806 
807 
808 const char *abrt_init(char **argv);
809 #define export_abrt_envvars libreport_export_abrt_envvars
810 void export_abrt_envvars(int pfx);
811 #define g_progname libreport_g_progname
812 extern const char *g_progname;
813 
814 enum parse_opt_type {
815  OPTION_BOOL,
816  OPTION_GROUP,
817  OPTION_STRING,
818  OPTION_INTEGER,
819  OPTION_OPTSTRING,
820  OPTION_LIST,
821  OPTION_END,
822 };
823 
824 struct options {
825  enum parse_opt_type type;
826  int short_name;
827  const char *long_name;
828  void *value;
829  const char *argh;
830  const char *help;
831 };
832 
833 /*
834  * s - short_name
835  * l - long_name
836  * v - value
837  * a - option parameter name (for help text)
838  * h - help
839  */
840 #define OPT_END() { OPTION_END }
841 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
842 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) }
843 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) }
844 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) }
845 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) }
846 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) }
847 
848 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose"))
849 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
850 
851 #define parse_opts libreport_parse_opts
852 unsigned parse_opts(int argc, char **argv, const struct options *opt,
853  const char *usage);
854 
855 #define show_usage_and_die libreport_show_usage_and_die
856 void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
857 
858 /* Can't include "abrt_curl.h", it's not a public API.
859  * Resorting to just forward-declaring the struct we need.
860  */
861 struct abrt_post_state;
862 
863 #ifdef __cplusplus
864 }
865 #endif
866 
867 #endif