libreport  2.12.0
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 <syslog.h>
37 #include <sys/poll.h>
38 #include <sys/mman.h>
39 #include <sys/socket.h>
40 #include <sys/stat.h>
41 #include <sys/time.h>
42 #include <sys/types.h>
43 #include <sys/wait.h>
44 #include <arpa/inet.h> /* sockaddr_in, sockaddr_in6 etc */
45 #include <termios.h>
46 #include <time.h>
47 #include <unistd.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 
57 #ifdef HAVE_CONFIG_H
58 # include "config.h"
59 #endif
60 
61 /* Must be after #include "config.h" */
62 #ifdef ENABLE_NLS
63 # include <libintl.h>
64 # define _(S) dgettext(PACKAGE, S)
65 #else
66 # define _(S) (S)
67 #endif
68 
69 #ifdef HAVE_LOCALE_H
70 # include <locale.h>
71 #endif /* HAVE_LOCALE_H */
72 
73 /* Some libc's forget to declare these, do it ourself */
74 extern char **environ;
75 #if defined(__GLIBC__) && __GLIBC__ < 2
76 int vdprintf(int d, const char *format, va_list ap);
77 #endif
78 
79 #undef NORETURN
80 #define NORETURN __attribute__ ((noreturn))
81 
82 #undef ERR_PTR
83 #define ERR_PTR ((void*)(uintptr_t)1)
84 
85 #undef ARRAY_SIZE
86 #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
87 
88 /* consts used across whole libreport */
89 #define CREATE_PRIVATE_TICKET "ABRT_CREATE_PRIVATE_TICKET"
90 #define STOP_ON_NOT_REPORTABLE "ABRT_STOP_ON_NOT_REPORTABLE"
91 
92 /* path of user's local config, path is relative to user's home */
93 #define USER_HOME_CONFIG_PATH "/.config/libreport"
94 
95 /* Pull in entire public libreport API */
96 #include "global_configuration.h"
97 #include "dump_dir.h"
98 #include "event_config.h"
99 #include "problem_data.h"
100 #include "report.h"
101 #include "run_event.h"
102 #include "workflow.h"
103 #include "file_obj.h"
104 #include "libreport_types.h"
105 #include "reporters.h"
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110 
111 #define prefixcmp libreport_prefixcmp
112 int prefixcmp(const char *str, const char *prefix);
113 #define suffixcmp libreport_suffixcmp
114 int suffixcmp(const char *str, const char *suffix);
115 #define trim_all_whitespace libreport_trim_all_whitespace
116 char *trim_all_whitespace(const char *str);
117 #define shorten_string_to_length libreport_shorten_string_to_length
118 char *shorten_string_to_length(const char *str, unsigned length);
119 #define strtrim libreport_strtrim
120 char *strtrim(char *str);
121 #define strtrimch libreport_strtrimch
122 char *strtrimch(char *str, int ch);
123 #define strremovech libreport_strremovech
124 char *strremovech(char *str, int ch);
125 #define append_to_malloced_string libreport_append_to_malloced_string
126 char *append_to_malloced_string(char *mstr, const char *append);
127 #define skip_blank libreport_skip_blank
128 char* skip_blank(const char *s);
129 #define skip_whitespace libreport_skip_whitespace
130 char* skip_whitespace(const char *s);
131 #define skip_non_whitespace libreport_skip_non_whitespace
132 char* skip_non_whitespace(const char *s);
133 /* Like strcpy but can copy overlapping strings. */
134 #define overlapping_strcpy libreport_overlapping_strcpy
135 void overlapping_strcpy(char *dst, const char *src);
136 
137 #define concat_path_file libreport_concat_path_file
138 char *concat_path_file(const char *path, const char *filename);
139 /*
140  * Used to construct a name in a different directory with the basename
141  * similar to the old name, if possible.
142  */
143 #define concat_path_basename libreport_concat_path_basename
144 char *concat_path_basename(const char *path, const char *filename);
145 
146 /* Allows all printable characters except '/',
147  * the string must not exceed 64 characters of length
148  * and must not equal neither "." nor ".." (these strings may appear in the string) */
149 #define str_is_correct_filename libreport_str_is_correct_filename
150 bool str_is_correct_filename(const char *str);
151 
152 /* A-la fgets, but malloced and of unlimited size */
153 #define xmalloc_fgets libreport_xmalloc_fgets
154 char *xmalloc_fgets(FILE *file);
155 /* Similar, but removes trailing \n */
156 #define xmalloc_fgetline libreport_xmalloc_fgetline
157 char *xmalloc_fgetline(FILE *file);
158 /* Useful for easy reading of various /proc files */
159 #define xmalloc_fopen_fgetline_fclose libreport_xmalloc_fopen_fgetline_fclose
160 char *xmalloc_fopen_fgetline_fclose(const char *filename);
161 
162 
163 typedef enum {
164  COPYFD_SPARSE = 1 << 0,
165 } libreport_copyfd_flags;
166 
167 /* Writes up to 'size' Bytes from a file descriptor to a file in a directory
168  *
169  * If you need to write all Bytes of the file descriptor, pass 0 as the size.
170  *
171  * @param src The source file descriptor
172  * @param dir_fd A file descriptor for the parent directory of the destination file
173  * @param name The destination file name
174  * @param mode The destination file open mode
175  * @param uid The destination file's uid
176  * @param gid The destination file's gid
177  * @param open_flags The destination file open flags
178  * @param copy_flags libreport_copyfd_flags
179  * @param size The upper limit for written bytes (0 for no limit).
180  * @return Number of read Bytes on success. On errors, return -1 and prints out
181  * reasonable good error messages.
182  */
183 #define copyfd_ext_at libreport_copyfd_ext_at
184 off_t copyfd_ext_at(int src, int dir_fd, const char *name, int mode,
185  uid_t uid, gid_t gid, int open_flags, int copy_flags, off_t size);
186 
187 /* On error, copyfd_XX prints error messages and returns -1 */
188 #define copyfd_eof libreport_copyfd_eof
189 off_t copyfd_eof(int src_fd, int dst_fd, int flags);
190 #define copyfd_size libreport_copyfd_size
191 off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags);
192 #define copyfd_exact_size libreport_copyfd_exact_size
193 void copyfd_exact_size(int src_fd, int dst_fd, off_t size);
194 #define copy_file_ext_2at libreport_copy_file_ext_2at
195 off_t copy_file_ext_2at(int src_dir_fd, const char *src_name, int dir_fd, const char *name, int mode, uid_t uid, gid_t gid, int src_flags, int dst_flags);
196 #define copy_file_ext_at libreport_copy_file_ext_at
197 off_t copy_file_ext_at(const char *src_name, int dir_fd, const char *name, int mode, uid_t uid, gid_t gid, int src_flags, int dst_flags);
198 #define copy_file_ext(src_name, dst_name, mode, uid, gid, src_flags, dst_flags) \
199  copy_file_ext_at(src_name, AT_FDCWD, dst_name, mode, uid, gid, src_flags, dst_flags)
200 #define copy_file libreport_copy_file
201 off_t copy_file(const char *src_name, const char *dst_name, int mode);
202 #define copy_file_at libreport_copy_file_at
203 off_t copy_file_at(const char *src_name, int dir_fd, const char *name, int mode);
204 #define copy_file_recursive libreport_copy_file_recursive
205 int copy_file_recursive(const char *source, const char *dest);
206 
207 #define decompress_fd libreport_decompress_fd
208 int decompress_fd(int fdi, int fdo);
209 #define decompress_file libreport_decompress_file
210 int decompress_file(const char *path_in, const char *path_out, mode_t mode_out);
211 #define decompress_file_ext_at libreport_decompress_file_ext_at
212 int decompress_file_ext_at(const char *path_in, int dir_fd, const char *path_out,
213  mode_t mode_out, uid_t uid, gid_t gid, int src_flags, int dst_flags);
214 
215 // NB: will return short read on error, not -1,
216 // if some data was read before error occurred
217 #define xread libreport_xread
218 void xread(int fd, void *buf, size_t count);
219 #define safe_read libreport_safe_read
220 ssize_t safe_read(int fd, void *buf, size_t count);
221 #define safe_write libreport_safe_write
222 ssize_t safe_write(int fd, const void *buf, size_t count);
223 #define full_read libreport_full_read
224 ssize_t full_read(int fd, void *buf, size_t count);
225 #define full_write libreport_full_write
226 ssize_t full_write(int fd, const void *buf, size_t count);
227 #define full_write_str libreport_full_write_str
228 ssize_t full_write_str(int fd, const char *buf);
229 #define xmalloc_read libreport_xmalloc_read
230 void* xmalloc_read(int fd, size_t *maxsz_p);
231 #define xmalloc_open_read_close libreport_xmalloc_open_read_close
232 void* xmalloc_open_read_close(const char *filename, size_t *maxsz_p);
233 #define xmalloc_xopen_read_close libreport_xmalloc_xopen_read_close
234 void* xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p);
235 #define malloc_readlink libreport_malloc_readlink
236 char* malloc_readlink(const char *linkname);
237 #define malloc_readlinkat libreport_malloc_readlinkat
238 char* malloc_readlinkat(int dir_fd, const char *linkname);
239 
240 
241 /* Returns malloc'ed block */
242 #define encode_base64 libreport_encode_base64
243 char *encode_base64(const void *src, int length);
244 
245 /* Returns NULL if the string needs no sanitizing.
246  * control_chars_to_sanitize is a bit mask.
247  * If Nth bit is set, Nth control char will be sanitized (replaced by [XX]).
248  */
249 #define sanitize_utf8 libreport_sanitize_utf8
250 char *sanitize_utf8(const char *src, uint32_t control_chars_to_sanitize);
251 enum {
252  SANITIZE_ALL = 0xffffffff,
253  SANITIZE_TAB = (1 << 9),
254  SANITIZE_LF = (1 << 10),
255  SANITIZE_CR = (1 << 13),
256 };
257 
258 #define try_atou libreport_try_atou
259 int try_atou(const char *numstr, unsigned *value);
260 #define xatou libreport_xatou
261 unsigned xatou(const char *numstr);
262 #define try_atoi libreport_try_atoi
263 int try_atoi(const char *numstr, int *value);
264 #define xatoi libreport_xatoi
265 int xatoi(const char *numstr);
266 /* Using xatoi() instead of naive atoi() is not always convenient -
267  * in many places people want *non-negative* values, but store them
268  * in signed int. Therefore we need this one:
269  * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc.
270  * It should really be named xatoi_nonnegative (since it allows 0),
271  * but that would be too long.
272  */
273 #define try_atoi_positive libreport_try_atoi_positive
274 int try_atoi_positive(const char *numstr, int *value);
275 #define xatoi_positive libreport_xatoi_positive
276 int xatoi_positive(const char *numstr);
277 
278 //unused for now
279 //unsigned long long monotonic_ns(void);
280 //unsigned long long monotonic_us(void);
281 //unsigned monotonic_sec(void);
282 
283 #define safe_waitpid libreport_safe_waitpid
284 pid_t safe_waitpid(pid_t pid, int *wstat, int options);
285 
286 enum {
287  /* on return, pipefds[1] is fd to which parent may write
288  * and deliver data to child's stdin: */
289  EXECFLG_INPUT = 1 << 0,
290  /* on return, pipefds[0] is fd from which parent may read
291  * child's stdout: */
292  EXECFLG_OUTPUT = 1 << 1,
293  /* open child's stdin to /dev/null: */
294  EXECFLG_INPUT_NUL = 1 << 2,
295  /* open child's stdout to /dev/null: */
296  EXECFLG_OUTPUT_NUL = 1 << 3,
297  /* redirect child's stderr to stdout: */
298  EXECFLG_ERR2OUT = 1 << 4,
299  /* open child's stderr to /dev/null: */
300  EXECFLG_ERR_NUL = 1 << 5,
301  /* suppress perror_msg("Can't execute 'foo'") if exec fails */
302  EXECFLG_QUIET = 1 << 6,
303  EXECFLG_SETGUID = 1 << 7,
304  EXECFLG_SETSID = 1 << 8,
305  EXECFLG_SETPGID = 1 << 9,
306 };
307 /*
308  * env_vec: list of variables to set in environment (if string has
309  * "VAR=VAL" form) or unset in environment (if string has no '=' char).
310  *
311  * Returns pid.
312  */
313 #define fork_execv_on_steroids libreport_fork_execv_on_steroids
314 pid_t fork_execv_on_steroids(int flags,
315  char **argv,
316  int *pipefds,
317  char **env_vec,
318  const char *dir,
319  uid_t uid);
320 /* Returns malloc'ed string. NULs are retained, and extra one is appended
321  * after the last byte (this NUL is not accounted for in *size_p) */
322 #define run_in_shell_and_save_output libreport_run_in_shell_and_save_output
323 char *run_in_shell_and_save_output(int flags,
324  const char *cmd,
325  const char *dir,
326  size_t *size_p);
327 
328 /* Random utility functions */
329 
330 #define is_in_string_list libreport_is_in_string_list
331 bool is_in_string_list(const char *name, const char *const *v);
332 
333 #define index_of_string_in_list libreport_index_of_string_in_list
334 int index_of_string_in_list(const char *name, const char *const *v);
335 
336 #define is_in_comma_separated_list libreport_is_in_comma_separated_list
337 bool is_in_comma_separated_list(const char *value, const char *list);
338 #define is_in_comma_separated_list_of_glob_patterns libreport_is_in_comma_separated_list_of_glob_patterns
339 bool is_in_comma_separated_list_of_glob_patterns(const char *value, const char *list);
340 
341 /* Calls GLib version appropriate initialization function.
342  */
343 #define glib_init libreport_glib_init
344 void glib_init(void);
345 
346 /* Frees every element'd data using free(),
347  * then frees list itself using g_list_free(list):
348  */
349 #define list_free_with_free libreport_list_free_with_free
350 void list_free_with_free(GList *list);
351 
352 #define get_dirsize libreport_get_dirsize
353 double get_dirsize(const char *pPath);
354 #define get_dirsize_find_largest_dir libreport_get_dirsize_find_largest_dir
355 double get_dirsize_find_largest_dir(
356  const char *pPath,
357  char **worst_dir, /* can be NULL */
358  const char *excluded /* can be NULL */
359 );
360 
361 #define ndelay_on libreport_ndelay_on
362 int ndelay_on(int fd);
363 #define ndelay_off libreport_ndelay_off
364 int ndelay_off(int fd);
365 #define close_on_exec_on libreport_close_on_exec_on
366 int close_on_exec_on(int fd);
367 
368 #define xmalloc libreport_xmalloc
369 void* xmalloc(size_t size);
370 #define xrealloc libreport_xrealloc
371 void* xrealloc(void *ptr, size_t size);
372 #define xzalloc libreport_xzalloc
373 void* xzalloc(size_t size);
374 #define xstrdup libreport_xstrdup
375 char* xstrdup(const char *s);
376 #define xstrndup libreport_xstrndup
377 char* xstrndup(const char *s, int n);
378 #define xstrdup_between libreport_xstrdup_between
379 char* xstrdup_between(const char *s, const char *open, const char *close);
380 
381 #define xpipe libreport_xpipe
382 void xpipe(int filedes[2]);
383 #define xdup libreport_xdup
384 int xdup(int from);
385 #define xdup2 libreport_xdup2
386 void xdup2(int from, int to);
387 #define xmove_fd libreport_xmove_fd
388 void xmove_fd(int from, int to);
389 
390 #define xwrite libreport_xwrite
391 void xwrite(int fd, const void *buf, size_t count);
392 #define xwrite_str libreport_xwrite_str
393 void xwrite_str(int fd, const char *str);
394 
395 #define xlseek libreport_xlseek
396 off_t xlseek(int fd, off_t offset, int whence);
397 
398 #define xchdir libreport_xchdir
399 void xchdir(const char *path);
400 
401 #define xvasprintf libreport_xvasprintf
402 char* xvasprintf(const char *format, va_list p);
403 #define xasprintf libreport_xasprintf
404 char* xasprintf(const char *format, ...);
405 
406 #define xsetenv libreport_xsetenv
407 void xsetenv(const char *key, const char *value);
408 /*
409  * Utility function to unsetenv a string which was possibly putenv'ed.
410  * The problem here is that "natural" optimization:
411  * strchrnul(var_val, '=')[0] = '\0';
412  * unsetenv(var_val);
413  * is BUGGY: if string was put into environment via putenv,
414  * its modification (s/=/NUL/) is illegal, and unsetenv will fail to unset it.
415  * Of course, saving/restoring the char wouldn't work either.
416  * This helper creates a copy up to '=', unsetenv's it, and frees:
417  */
418 #define safe_unsetenv libreport_safe_unsetenv
419 void safe_unsetenv(const char *var_val);
420 
421 #define xsocket libreport_xsocket
422 int xsocket(int domain, int type, int protocol);
423 #define xbind libreport_xbind
424 void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
425 #define xlisten libreport_xlisten
426 void xlisten(int s, int backlog);
427 #define xsendto libreport_xsendto
428 ssize_t xsendto(int s, const void *buf, size_t len,
429  const struct sockaddr *to, socklen_t tolen);
430 
431 #define xstat libreport_xstat
432 void xstat(const char *name, struct stat *stat_buf);
433 #define fstat_st_size_or_die libreport_fstat_st_size_or_die
434 off_t fstat_st_size_or_die(int fd);
435 #define stat_st_size_or_die libreport_stat_st_size_or_die
436 off_t stat_st_size_or_die(const char *filename);
437 
438 #define xopen3 libreport_xopen3
439 int xopen3(const char *pathname, int flags, int mode);
440 #define xopen libreport_xopen
441 int xopen(const char *pathname, int flags);
442 #define xunlink libreport_xunlink
443 void xunlink(const char *pathname);
444 #define xunlinkat libreport_xunlinkat
445 void xunlinkat(int dir_fd, const char *pathname, int flags);
446 
447 /* Just testing dent->d_type == DT_REG is wrong: some filesystems
448  * do not report the type, they report DT_UNKNOWN for every dirent
449  * (and this is not a bug in filesystem, this is allowed by standards).
450  * This function handles this case. Note: it returns 0 on symlinks
451  * even if they point to regular files.
452  */
453 #define is_regular_file libreport_is_regular_file
454 int is_regular_file(struct dirent *dent, const char *dirname);
455 #define is_regular_file_at libreport_is_regular_file_at
456 int is_regular_file_at(struct dirent *dent, int dir_fd);
457 
458 #define dot_or_dotdot libreport_dot_or_dotdot
459 bool dot_or_dotdot(const char *filename);
460 #define last_char_is libreport_last_char_is
461 char *last_char_is(const char *s, int c);
462 
463 #define string_to_bool libreport_string_to_bool
464 bool string_to_bool(const char *s);
465 
466 #define xseteuid libreport_xseteuid
467 void xseteuid(uid_t euid);
468 #define xsetegid libreport_xsetegid
469 void xsetegid(gid_t egid);
470 #define xsetreuid libreport_xsetreuid
471 void xsetreuid(uid_t ruid, uid_t euid);
472 #define xsetregid libreport_xsetregid
473 void xsetregid(gid_t rgid, gid_t egid);
474 
475 #define xfdopen libreport_xfdopen
476 FILE *xfdopen(int fd, const char *mode);
477 
478 /* Emit a string of hex representation of bytes */
479 #define bin2hex libreport_bin2hex
480 char* bin2hex(char *dst, const char *str, int count);
481 /* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */
482 #define hex2bin libreport_hex2bin
483 char* hex2bin(char *dst, const char *str, int count);
484 
485 
486 enum {
487  LOGMODE_NONE = 0,
488  LOGMODE_STDIO = (1 << 0),
489  LOGMODE_SYSLOG = (1 << 1),
490  LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
491  LOGMODE_CUSTOM = (1 << 2),
492  LOGMODE_JOURNAL = (1 << 3),
493 };
494 
495 enum libreport_diemode {
496  DIEMODE_EXIT = 0,
497  DIEMODE_ABORT = 1,
498 };
499 
500 #define g_custom_logger libreport_g_custom_logger
501 extern void (*g_custom_logger)(const char*);
502 #define msg_prefix libreport_msg_prefix
503 extern const char *msg_prefix;
504 #define msg_eol libreport_msg_eol
505 extern const char *msg_eol;
506 #define logmode libreport_logmode
507 extern int logmode;
508 #define xfunc_error_retval libreport_xfunc_error_retval
509 extern int xfunc_error_retval;
510 
511 /* A few magic exit codes */
512 #define EXIT_CANCEL_BY_USER 69
513 #define EXIT_STOP_EVENT_RUN 70
514 
515 #define set_xfunc_error_retval libreport_set_xfunc_error_retval
516 void set_xfunc_error_retval(int retval);
517 
518 #define set_xfunc_diemode libreport_set_xfunc_diemode
519 void set_xfunc_diemode(enum libreport_diemode mode);
520 
521 /* Verbosity level */
522 #define g_verbose libreport_g_verbose
523 extern int g_verbose;
524 /* VERB1 log_warning("what you sometimes want to see, even on a production box") */
525 #define VERB1 if (g_verbose >= 1)
526 /* VERB2 log_warning("debug message, not going into insanely small details") */
527 #define VERB2 if (g_verbose >= 2)
528 /* VERB3 log_warning("lots and lots of details") */
529 #define VERB3 if (g_verbose >= 3)
530 /* there is no level > 3 */
531 
532 #define libreport_
533 #define xfunc_die libreport_xfunc_die
534 void xfunc_die(void) NORETURN;
535 
536 #define die_out_of_memory libreport_die_out_of_memory
537 void die_out_of_memory(void) NORETURN;
538 
539 /* It's a macro, not function, since it collides with log_warning() from math.h */
540 #undef log
541 #define log_warning(...) log_standard(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
542 #define log_debug(...) log_standard(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
543 #define log_info(...) log_standard(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
544 #define log_notice(...) log_standard(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
545 #define log_warning(...) log_standard(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
546 #define log_error(...) log_standard(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__)
547 
548 // specific subsystem debugging
549 #define log_parser(...) if(0) log_debug(__VA_ARGS__)
550 
551 #define log_standard(level, file, line, func, ...) log_wrapper(level, __FILE__, __LINE__, __func__, false, false, __VA_ARGS__)
552 
553 // level, file, line, func, perror, custom logger, format & args
554 #define log_error_and_die(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, false,__VA_ARGS__)
555 #define log_perror(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, false, __VA_ARGS__)
556 #define log_perror_and_die(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, false, __VA_ARGS__)
557 
558 #define error_msg(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
559 #define perror_msg(...) log_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
560 #define warn_msg(...) log_wrapper(LOG_WARNING, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
561 #define pwarn_msg(...) log_wrapper(LOG_WARNING, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
562 #define notice_msg(...) log_wrapper(LOG_NOTICE, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
563 #define pnotice_msg(...) log_wrapper(LOG_NOTICE, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
564 #define error_msg_and_die(...) log_and_die_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, false, true, __VA_ARGS__)
565 #define perror_msg_and_die(...) log_and_die_wrapper(LOG_ERR, __FILE__, __LINE__, __func__, true, true, __VA_ARGS__)
566 
567 
568 void log_wrapper(int level,
569  const char *file,
570  int line,
571  const char *func,
572  bool process_perror,
573  bool use_custom_logger,
574  const char *format, ...) __attribute__ ((format (printf, 7,8)));
575 
576 void log_and_die_wrapper(int level,
577  const char *file,
578  int line,
579  const char *func,
580  bool process_perror,
581  bool use_custom_logger,
582  const char *format, ...) __attribute__ ((noreturn, format (printf, 7,8)));
583 
584 struct strbuf
585 {
586  /* Size of the allocated buffer. Always > 0. */
587  int alloc;
588  /* Length of the string, without the ending \0. */
589  int len;
590  char *buf;
591 };
592 
599 #define strbuf_new libreport_strbuf_new
600 struct strbuf *strbuf_new(void);
601 
607 #define strbuf_free libreport_strbuf_free
608 void strbuf_free(struct strbuf *strbuf);
609 
615 #define strbuf_free_nobuf libreport_strbuf_free_nobuf
616 char* strbuf_free_nobuf(struct strbuf *strbuf);
617 
622 #define strbuf_clear libreport_strbuf_clear
623 void strbuf_clear(struct strbuf *strbuf);
624 
629 #define strbuf_append_char libreport_strbuf_append_char
630 struct strbuf *strbuf_append_char(struct strbuf *strbuf, char c);
631 
636 #define strbuf_append_str libreport_strbuf_append_str
637 struct strbuf *strbuf_append_str(struct strbuf *strbuf,
638  const char *str);
639 
644 #define strbuf_prepend_str libreport_strbuf_prepend_str
645 struct strbuf *strbuf_prepend_str(struct strbuf *strbuf,
646  const char *str);
647 
652 #define strbuf_append_strf libreport_strbuf_append_strf
653 struct strbuf *strbuf_append_strf(struct strbuf *strbuf,
654  const char *format, ...);
655 
660 #define strbuf_append_strfv libreport_strbuf_append_strfv
661 struct strbuf *strbuf_append_strfv(struct strbuf *strbuf,
662  const char *format, va_list p);
663 
669 #define strbuf_prepend_strf libreport_strbuf_prepend_strf
670 struct strbuf *strbuf_prepend_strf(struct strbuf *strbuf,
671  const char *format, ...);
672 
677 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv
678 struct strbuf *strbuf_prepend_strfv(struct strbuf *strbuf,
679  const char *format, va_list p);
680 
681 /* Returns command line of running program.
682  * Caller is responsible to free() the returned value.
683  * If the pid is not valid or command line can not be obtained,
684  * empty string is returned.
685  */
686 #define open_proc_pid_dir libreport_open_proc_pid_dir
687 int open_proc_pid_dir(pid_t pid);
688 #define get_cmdline_at libreport_get_cmdline_at
689 char* get_cmdline_at(pid_t pid);
690 #define get_cmdline libreport_get_cmdline
691 char* get_cmdline(pid_t pid);
692 #define get_environ_at libreport_get_environ_at
693 char* get_environ_at(pid_t pid);
694 #define get_environ libreport_get_environ
695 char* get_environ(pid_t pid);
696 #define get_executable_at libreport_get_executable_at
697 char *get_executable_at(pid_t pid);
698 #define get_executable libreport_get_executable
699 char *get_executable(pid_t pid);
700 #define get_cwd_at libreport_get_cwd_at
701 char* get_cwd_at(pid_t pid);
702 #define get_cwd libreport_get_cwd
703 char* get_cwd(pid_t pid);
704 #define get_rootdir_at libreport_get_rootdir_at
705 char* get_rootdir_at(pid_t pid);
706 #define get_rootdir libreport_get_rootdir
707 char* get_rootdir(pid_t pid);
708 
709 #define get_fsuid libreport_get_fsuid
710 int get_fsuid(const char *proc_pid_status);
711 #define get_fsgid libreport_get_fsgid
712 int get_fsgid(const char *proc_pid_status);
713 #define dump_fd_info_at libreport_dump_fd_info_at
714 int dump_fd_info_at(int pid_proc_fd, FILE *dest);
715 #define dump_fd_info_ext libreport_dump_fd_info_ext
716 int dump_fd_info_ext(const char *dest_filename, const char *proc_pid_fd_path, uid_t uid, gid_t gid);
717 #define dump_fd_info libreport_dump_fd_info
718 int dump_fd_info(const char *dest_filename, const char *proc_pid_fd_path);
719 #define get_env_variable_ext libreport_get_env_variable_ext
720 int get_env_variable_ext(int fd, char delim, const char *name, char **value);
721 #define get_env_variable libreport_get_env_variable
722 int get_env_variable(pid_t pid, const char *name, char **value);
723 
724 #define PROC_NS_UNSUPPORTED ((ino_t)-1)
725 #define PROC_NS_ID_IPC 0
726 #define PROC_NS_ID_MNT 1
727 #define PROC_NS_ID_NET 2
728 #define PROC_NS_ID_PID 3
729 #define PROC_NS_ID_USER 4
730 #define PROC_NS_ID_UTS 5
731 #define PROC_NS_ID_CGROUP 6
732 static const char * libreport_proc_namespaces[] = { "ipc", "mnt", "net", "pid", "uts", "user", "cgroup", "pid_for_children" };
733 
734 struct ns_ids {
735  ino_t nsi_ids[ARRAY_SIZE(libreport_proc_namespaces)];
736 };
737 
738 #define get_ns_ids_at libreport_get_ns_ids_at
739 int get_ns_ids_at(int pid_proc_fd, struct ns_ids *ids);
740 #define get_ns_ids libreport_get_ns_ids
741 int get_ns_ids(pid_t pid, struct ns_ids *ids);
742 
743 /* These functions require a privileged user and does not work correctly in
744  * processes running in own PID namespace
745  */
746 #define process_has_own_root_at libreport_process_has_own_root_at
747 int process_has_own_root_at(int proc_pid_fd);
748 #define process_has_own_root libreport_process_has_own_root
749 int process_has_own_root(pid_t pid);
750 
751 #define get_pid_of_container_at libreport_get_pid_of_container_at
752 int get_pid_of_container_at(int pid_proc_fd, pid_t *init_pid);
753 #define get_pid_of_container libreport_get_pid_of_container
754 int get_pid_of_container(pid_t pid, pid_t *init_pid);
755 #define dump_namespace_diff_at libreport_dump_namespace_diff_at
756 int dump_namespace_diff_at(int base_pid_proc_fd, int tested_pid_proc_fd, FILE *dest);
757 #define dump_namespace_diff_ext libreport_dump_namespace_diff_ext
758 int dump_namespace_diff_ext(const char *dest_filename, pid_t base_pid, pid_t tested_pid, uid_t uid, gid_t gid);
759 #define dump_namespace_diff libreport_dump_namespace_diff
760 int dump_namespace_diff(const char *dest_filename, pid_t base_pid, pid_t tested_pid);
761 
762 enum
763 {
764  MOUNTINFO_INDEX_MOUNT_ID,
765  MOUNTINFO_INDEX_PARENT_ID,
766  MOUNTINFO_INDEX_MAJOR_MINOR,
767  MOUNTINFO_INDEX_ROOT,
768  MOUNTINFO_INDEX_MOUNT_POINT,
769  MOUNTINFO_INDEX_MOUNT_OPTIONS,
770  MOUNTINFO_INDEX_OPTIONAL_FIELDS,
771  MOUNTINFO_INDEX_FS_TYPE,
772  MOUNTINFO_INDEX_MOUNT_SOURCE,
773  MOUNTINFO_INDEX_SUPER_OPITONS,
774  _MOUNTINFO_INDEX_MAX,
775 };
776 
777 #define MOUNTINFO_ROOT(val) (val.mntnf_items[MOUNTINFO_INDEX_ROOT])
778 #define MOUNTINFO_MOUNT_POINT(val) (val.mntnf_items[MOUNTINFO_INDEX_MOUNT_POINT])
779 #define MOUNTINFO_MOUNT_SOURCE(val) (val.mntnf_items[MOUNTINFO_INDEX_MOUNT_SOURCE])
780 
781 struct mountinfo
782 {
783  /* 4 : root of the mount within the filesystem */
784  /* 5 : mount point relative to the process's root */
785  /* 10 : mount source: filesystem specific information or "none" */
786  /* but it mount source is preceded by 0 or more optional fields */
787  /* so the effective value is 9 */
788  char *mntnf_items[_MOUNTINFO_INDEX_MAX];
789 };
790 #define mountinfo_destroy libreport_mountinfo_destroy
791 void mountinfo_destroy(struct mountinfo *mntnf);
792 #define get_mountinfo_for_mount_point libreport_get_mountinfo_for_mount_point
793 int get_mountinfo_for_mount_point(FILE *fin, struct mountinfo *mntnf, const char *mnt_point);
794 
795 /* Takes ptr to time_t, or NULL if you want to use current time.
796  * Returns "YYYY-MM-DD-hh:mm:ss" string.
797  */
798 #define iso_date_string libreport_iso_date_string
799 char *iso_date_string(const time_t *pt);
800 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
801 #define LIBREPORT_ISO_DATE_STRING_FORMAT "%Y-%m-%d-%H:%M:%S"
802 
803 /* Parses date into integer UNIX time stamp
804  *
805  * @param date The parsed date string
806  * @param pt Return value
807  * @return 0 on success; otherwise non-0 number. -EINVAL if the parameter date
808  * does not match LIBREPORT_ISO_DATE_STRING_FORMAT
809  */
810 #define iso_date_string_parse libreport_iso_date_string_parse
811 int iso_date_string_parse(const char *date, time_t *pt);
812 
813 enum {
814  MAKEDESC_SHOW_FILES = (1 << 0),
815  MAKEDESC_SHOW_MULTILINE = (1 << 1),
816  MAKEDESC_SHOW_ONLY_LIST = (1 << 2),
817  MAKEDESC_WHITELIST = (1 << 3),
818  /* Include all URLs from FILENAME_REPORTED_TO element in the description text */
819  MAKEDESC_SHOW_URLS = (1 << 4),
820 };
821 #define make_description libreport_make_description
822 char *make_description(problem_data_t *problem_data, char **names_to_skip, unsigned max_text_size, unsigned desc_flags);
823 #define make_description_logger libreport_make_description_logger
824 char* make_description_logger(problem_data_t *problem_data, unsigned max_text_size);
825 
826 /* See man os-release(5) for details */
827 #define OSINFO_ID "ID"
828 #define OSINFO_NAME "NAME"
829 #define OSINFO_VERSION_ID "VERSION_ID"
830 #define OSINFO_PRETTY_NAME "PRETTY_NAME"
831 
832 /* @brief Loads a text in format of os-release(5) in to a map
833  *
834  * Function doesn't check for format errors much. It just tries to avoid
835  * program errors. In case of error the function prints out a log message and
836  * continues in parsing.
837  *
838  * @param osinfo_bytes Non-NULL pointer to osinfo bytes.
839  * @param osinfo The map where result is stored
840  */
841 #define parse_osinfo libreport_parse_osinfo
842 void parse_osinfo(const char *osinfo_bytes, map_string_t *osinfo);
843 
844 /* @brief Builds product string and product's version string for Bugzilla
845  *
846  * At first tries to get strings from the os specific variables
847  * (REDHAT_BUGZILLA_PRODUCT, REDHAT_BUGZILLA_PRODUCT_VERSION) if no such
848  * variables are found, uses NAME key for the product and VERSION_ID key for
849  * the product's version. If neither NAME nor VERSION_ID are provided fallbacks
850  * to parsing of os_release which should be stored under PRETTY_NAME key.
851  *
852  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
853  *
854  * @param osinfo Input data from which the values are built
855  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
856  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
857  */
858 #define parse_osinfo_for_bz libreport_parse_osinfo_for_bz
859 void parse_osinfo_for_bz(map_string_t *osinfo, char **product, char **version);
860 
861 /* @brief Extract BUG_REPORT_URL from os-release
862  *
863  * A default location for bug reports can be stored in os-release.
864  * This extracts the value if present and stores it in url.
865  * If unset, url will become NULL
866  *
867  * https://github.com/abrt/libreport/issues/459
868  *
869  * @param osinfo Input data from which the values are built
870  * @param url Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
871  */
872 #define parse_osinfo_for_bug_url libreport_parse_osinfo_for_bug_url
873 void parse_osinfo_for_bug_url(map_string_t *osinfo, char** url);
874 
875 /* @brief Builds product string and product's version string for Red Hat Support
876  *
877  * At first tries to get strings from the os specific variables
878  * (REDHAT_SUPPORT_PRODUCT, REDHAT_SUPPORT_PRODUCT_VERSION) if no such
879  * variables are found, uses NAME key for the product and VERSION_ID key for
880  * the product's version. If no NAME nor VERSION_ID are provided fallbacks to
881  * parsing of os_release which should be stored under PRETTY_NAME key.
882  *
883  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
884  *
885  * @param osinfo Input data from which the values are built
886  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
887  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
888  */
889 #define parse_osinfo_for_rhts libreport_parse_osinfo_for_rhts
890 void parse_osinfo_for_rhts(map_string_t *osinfo, char **product, char **version);
891 
892 #define parse_release_for_bz libreport_parse_release_for_bz
893 void parse_release_for_bz(const char *pRelease, char **product, char **version);
894 #define parse_release_for_rhts libreport_parse_release_for_rhts
895 void parse_release_for_rhts(const char *pRelease, char **product, char **version);
896 
911 #define load_conf_file libreport_load_conf_file
912 bool load_conf_file(const char *pPath, map_string_t *settings, bool skipKeysWithoutValue);
913 #define load_plugin_conf_file libreport_load_plugin_conf_file
914 bool load_plugin_conf_file(const char *name, map_string_t *settings, bool skipKeysWithoutValue);
915 
916 #define get_user_conf_base_dir libreport_get_user_conf_base_dir
917 const char *get_user_conf_base_dir(void);
918 
919 #define load_conf_file_from_dirs libreport_load_conf_file_from_dirs
920 bool load_conf_file_from_dirs(const char *base_name, const char *const *directories, map_string_t *settings, bool skipKeysWithoutValue);
921 
922 enum {
923  CONF_DIR_FLAG_NONE = 0,
924  CONF_DIR_FLAG_OPTIONAL = 1,
925 };
926 
927 #define load_conf_file_from_dirs_ext libreport_load_conf_file_from_dirs_ext
928 bool load_conf_file_from_dirs_ext(const char *base_name, const char *const *directories,
929  const int * dir_flags, map_string_t *settings,
930  bool skipKeysWithoutValue);
931 
932 #define save_conf_file libreport_save_conf_file
933 bool save_conf_file(const char *path, map_string_t *settings);
934 #define save_plugin_conf_file libreport_save_plugin_conf_file
935 bool save_plugin_conf_file(const char *name, map_string_t *settings);
936 
937 #define save_app_conf_file libreport_save_app_conf_file
938 bool save_app_conf_file(const char* application_name, map_string_t *settings);
939 #define load_app_conf_file libreport_load_app_conf_file
940 bool load_app_conf_file(const char *application_name, map_string_t *settings);
941 #define set_app_user_setting libreport_set_app_user_setting
942 void set_app_user_setting(map_string_t *settings, const char *name, const char *value);
943 #define get_app_user_setting libreport_get_app_user_setting
944 const char *get_app_user_setting(map_string_t *settings, const char *name);
945 
946 #define save_user_settings libreport_save_user_settings
947 bool save_user_settings(void);
948 #define load_user_settings libreport_load_user_settings
949 bool load_user_settings(const char *application_name);
950 #define set_user_setting libreport_set_user_setting
951 void set_user_setting(const char *name, const char *value);
952 #define get_user_setting libreport_get_user_setting
953 const char *get_user_setting(const char *name);
954 
955 /* filename is expected to exist in CONF_DIR
956  * usually /etc/libreport
957  */
958 #define load_forbidden_words libreport_load_forbidden_words
959 GList *load_words_from_file(const char *filename);
960 #define get_file_list libreport_get_file_list
961 GList *get_file_list(const char *path, const char *ext);
962 #define free_file_list libreport_free_file_list
963 void free_file_list(GList *filelist);
964 #define new_file_obj libreport_new_file_obj
965 file_obj_t *new_file_obj(const char* fullpath, const char* filename);
966 #define free_file_obj libreport_free_file_obj
967 void free_file_obj(file_obj_t *f);
968 #define parse_delimited_list libreport_parse_delimited_list
969 GList *parse_delimited_list(const char *string, const char *delimiter);
970 
971 /* Connect to abrtd over unix domain socket, issue DELETE command */
972 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
973 
974 /* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename.
975  * Returns NULL if copying failed. In this case, logs a message before returning. */
976 #define steal_directory libreport_steal_directory
977 struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name);
978 
979 /* Resolves if the given user is in given group
980  *
981  * @param uid user ID
982  * @param gid group ID
983  * @returns TRUE in case the user is in the group otherwise returns FALSE
984  */
985 #define uid_in_group libreport_uid_in_group
986 bool uid_in_group(uid_t uid, gid_t gid);
987 
988 /* Tries to open dump_dir_name with writing access. If function needs to steal
989  * directory calls ask_continue(new base dir, dump dir) callback to ask user
990  * for permission. If ask_continue param is NULL the function thinks that an
991  * answer is positive and steals directory.
992  * Returns NULL if opening failed or if stealing was dismissed. In this case,
993  * logs a message before returning. */
994 #define open_directory_for_writing libreport_open_directory_for_writing
995 struct dump_dir *open_directory_for_writing(
996  const char *dump_dir_name,
997  bool (*ask_continue)(const char *, const char *));
998 
999 // Files bigger than this are never considered to be text.
1000 //
1001 // Started at 64k limit. But _some_ limit is necessary:
1002 // fields declared "text" may end up in editing fields and such.
1003 // We don't want to accidentally end up with 100meg text in a textbox!
1004 // So, don't remove this. If you really need to, raise the limit.
1005 //
1006 // Bumped up to 200k: saw 124740 byte /proc/PID/smaps file
1007 // Bumped up to 500k: saw 375252 byte anaconda traceback file
1008 // Bumped up to 1M: bugzilla.redhat.com/show_bug.cgi?id=746727
1009 // mentions 853646 byte anaconda-tb-* file.
1010 // Bumped up to 8M: bugzilla.redhat.com/show_bug.cgi?id=887570
1011 // (anaconda-tb file of 1.38 MBytes)
1012 //
1013 #define CD_MAX_TEXT_SIZE (8*1024*1024)
1014 
1015 // Text bigger than this usually is attached, not added inline
1016 // was 2k, 20kb is too much, let's try 4kb
1017 //
1018 // For bug databases
1019 #define CD_TEXT_ATT_SIZE_BZ (4*1024)
1020 // For dumping problem data into a text file, email, etc
1021 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE)
1022 
1023 // Filenames in problem directory:
1024 // filled by a hook:
1025 #define FILENAME_TIME "time" /* mandatory */
1026 #define FILENAME_LAST_OCCURRENCE "last_occurrence" /* optional */
1027 #define FILENAME_REASON "reason" /* mandatory? */
1028 #define FILENAME_UID "uid" /* mandatory? */
1029 
1030 /*
1031  * "analyzer" is to be gradually changed to "type":
1032  * For now, we fetch and look at "analyzer" element,
1033  * but we always save both "analyzer" and "type" (with same contents).
1034  * By 2013, we switch to looking at "type". Then we will stop generating
1035  * "analyzer" element.
1036  * ----
1037  * Update 2015: based on the recent changes where we have introduced several
1038  * tools generating one problem type, we have decided to retain 'analyzer'
1039  * file, but it shall contain string identifier of a tool that created the
1040  * problem.
1041  */
1042 #define FILENAME_ANALYZER "analyzer"
1043 #define FILENAME_TYPE "type"
1044 #define FILENAME_EXECUTABLE "executable"
1045 #define FILENAME_PID "pid"
1046 #define FILENAME_TID "tid"
1047 #define FILENAME_GLOBAL_PID "global_pid"
1048 #define FILENAME_PWD "pwd"
1049 #define FILENAME_ROOTDIR "rootdir"
1050 #define FILENAME_BINARY "binary"
1051 #define FILENAME_CMDLINE "cmdline"
1052 #define FILENAME_COREDUMP "coredump"
1053 #define FILENAME_CGROUP "cgroup"
1054 #define FILENAME_BACKTRACE "backtrace"
1055 #define FILENAME_MAPS "maps"
1056 #define FILENAME_SMAPS "smaps"
1057 #define FILENAME_PROC_PID_STATUS "proc_pid_status"
1058 #define FILENAME_ENVIRON "environ"
1059 #define FILENAME_LIMITS "limits"
1060 #define FILENAME_OPEN_FDS "open_fds"
1061 #define FILENAME_MOUNTINFO "mountinfo"
1062 #define FILENAME_NAMESPACES "namespaces"
1063 #define FILENAME_CPUINFO "cpuinfo"
1064 
1065 /* Global problem identifier which is usually generated by some "analyze_*"
1066  * event because it may take a lot of time to obtain strong problem
1067  * identification */
1068 #define FILENAME_DUPHASH "duphash"
1069 
1070 // Name of the function where the application crashed.
1071 // Optional.
1072 #define FILENAME_CRASH_FUNCTION "crash_function"
1073 #define FILENAME_ARCHITECTURE "architecture"
1074 #define FILENAME_KERNEL "kernel"
1075 /*
1076  * From /etc/os-release
1077  * os_release filename name is alredy occupied by /etc/redhat-release (see
1078  * below) in sake of backward compatibility /etc/os-release is stored in
1079  * os_info file
1080  */
1081 #define FILENAME_OS_INFO "os_info"
1082 #define FILENAME_OS_INFO_IN_ROOTDIR "os_info_in_rootdir"
1083 // From /etc/system-release or /etc/redhat-release
1084 #define FILENAME_OS_RELEASE "os_release"
1085 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir"
1086 // Filled by <what?>
1087 #define FILENAME_PACKAGE "package"
1088 #define FILENAME_COMPONENT "component"
1089 #define FILENAME_COMMENT "comment"
1090 #define FILENAME_RATING "backtrace_rating"
1091 #define FILENAME_HOSTNAME "hostname"
1092 // Optional. Set to "1" by abrt-handle-upload for every unpacked dump
1093 #define FILENAME_REMOTE "remote"
1094 #define FILENAME_TAINTED "kernel_tainted"
1095 #define FILENAME_TAINTED_SHORT "kernel_tainted_short"
1096 #define FILENAME_TAINTED_LONG "kernel_tainted_long"
1097 #define FILENAME_VMCORE "vmcore"
1098 #define FILENAME_KERNEL_LOG "kernel_log"
1099 // File created by createAlertSignature() from libreport's python module
1100 // The file should contain a description of an alert
1101 #define FILENAME_DESCRIPTION "description"
1102 
1103 /* Local problem identifier (weaker than global identifier) designed for fast
1104  * local for fast local duplicate identification. This file is usually provided
1105  * by crashed application (problem creator).
1106  */
1107 #define FILENAME_UUID "uuid"
1108 
1109 #define FILENAME_COUNT "count"
1110 /* Multi-line list of places problem was reported.
1111  * Recommended line format:
1112  * "Reporter: VAR=VAL VAR=VAL"
1113  * Use add_reported_to(dd, "line_without_newline"): it adds line
1114  * only if it is not already there.
1115  */
1116 #define FILENAME_REPORTED_TO "reported_to"
1117 #define FILENAME_EVENT_LOG "event_log"
1118 /*
1119  * If exists, should contain a full sentence (with trailing period)
1120  * which describes why this problem should not be reported.
1121  * Example: "Your laptop firmware 1.9a is buggy, version 1.10 contains the fix."
1122  */
1123 #define FILENAME_NOT_REPORTABLE "not-reportable"
1124 #define FILENAME_CORE_BACKTRACE "core_backtrace"
1125 #define FILENAME_REMOTE_RESULT "remote_result"
1126 #define FILENAME_PKG_EPOCH "pkg_epoch"
1127 #define FILENAME_PKG_NAME "pkg_name"
1128 #define FILENAME_PKG_VERSION "pkg_version"
1129 #define FILENAME_PKG_RELEASE "pkg_release"
1130 #define FILENAME_PKG_ARCH "pkg_arch"
1131 
1132 /* RHEL packages - Red Hat, Inc. */
1133 #define FILENAME_PKG_VENDOR "pkg_vendor"
1134 /* RHEL keys - https://access.redhat.com/security/team/key */
1135 #define FILENAME_PKG_FINGERPRINT "pkg_fingerprint"
1136 
1137 #define FILENAME_USERNAME "username"
1138 #define FILENAME_ABRT_VERSION "abrt_version"
1139 #define FILENAME_EXPLOITABLE "exploitable"
1140 
1141 /* reproducible element is used by functions from problem_data.h */
1142 #define FILENAME_REPRODUCIBLE "reproducible"
1143 #define FILENAME_REPRODUCER "reproducer"
1144 
1145 /* File names related to Anaconda problems
1146  */
1147 #define FILENAME_KICKSTART_CFG "ks.cfg"
1148 #define FILENAME_ANACONDA_TB "anaconda-tb"
1149 
1150 /* Containers
1151  */
1152 #define FILENAME_CONTAINER "container"
1153 #define FILENAME_CONTAINER_ID "container_id"
1154 #define FILENAME_CONTAINER_UUID "container_uuid"
1155 #define FILENAME_CONTAINER_IMAGE "container_image"
1156 #define FILENAME_CONTAINER_CMDLINE "container_cmdline"
1157 /* Container root file-system directory as seen from the host. */
1158 #define FILENAME_CONTAINER_ROOTFS "container_rootfs"
1159 #define FILENAME_DOCKER_INSPECT "docker_inspect"
1160 
1161 /* Type of catched exception
1162  * Optional.
1163  */
1164 #define FILENAME_EXCEPTION_TYPE "exception_type"
1165 
1166 // Not stored as files, added "on the fly":
1167 #define CD_DUMPDIR "Directory"
1168 
1169 #define cmp_problem_data libreport_cmp_problem_data
1170 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename);
1171 
1172 //UNUSED:
1175 //#define CD_EVENTS "Events"
1176 
1177 /* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK
1178  * when it reaches HIGH_WATERMARK size
1179  */
1180 enum {
1181  EVENT_LOG_HIGH_WATERMARK = 30 * 1024,
1182  EVENT_LOG_LOW_WATERMARK = 20 * 1024,
1183 };
1184 
1185 #define log_problem_data libreport_log_problem_data
1186 void log_problem_data(problem_data_t *problem_data, const char *pfx);
1187 
1188 extern int g_libreport_inited;
1189 void libreport_init(void);
1190 
1191 #define INITIALIZE_LIBREPORT() \
1192  do \
1193  { \
1194  if (!g_libreport_inited) \
1195  { \
1196  g_libreport_inited = 1; \
1197  libreport_init(); \
1198  } \
1199  } \
1200  while (0)
1201 
1202 const char *abrt_init(char **argv);
1203 #define export_abrt_envvars libreport_export_abrt_envvars
1204 void export_abrt_envvars(int pfx);
1205 #define g_progname libreport_g_progname
1206 extern const char *g_progname;
1207 
1208 enum parse_opt_type {
1209  OPTION_BOOL,
1210  OPTION_GROUP,
1211  OPTION_STRING,
1212  OPTION_INTEGER,
1213  OPTION_OPTSTRING,
1214  OPTION_LIST,
1215  OPTION_END,
1216 };
1217 
1218 struct options {
1219  enum parse_opt_type type;
1220  int short_name;
1221  const char *long_name;
1222  void *value;
1223  const char *argh;
1224  const char *help;
1225 };
1226 
1227 /*
1228  * s - short_name
1229  * l - long_name
1230  * v - value
1231  * a - option parameter name (for help text)
1232  * h - help
1233  */
1234 #define OPT_END() { OPTION_END }
1235 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
1236 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) }
1237 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) }
1238 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) }
1239 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) }
1240 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) }
1241 
1242 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose"))
1243 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
1244 
1245 #define parse_opts libreport_parse_opts
1246 unsigned parse_opts(int argc, char **argv, const struct options *opt,
1247  const char *usage);
1248 
1249 #define show_usage_and_die libreport_show_usage_and_die
1250 void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
1251 
1252 /* Can't include "abrt_curl.h", it's not a public API.
1253  * Resorting to just forward-declaring the struct we need.
1254  */
1255 struct abrt_post_state;
1256 
1257 /* Decomposes uri to its base elements, removes userinfo out of the hostname and
1258  * composes a new uri without userinfo.
1259  *
1260  * The function does not validate the url.
1261  *
1262  * @param uri The uri that might contain userinfo
1263  * @param result The userinfo free uri will be store here. Cannot be null. Must
1264  * be de-allocated by free.
1265  * @param scheme Scheme of the uri. Can be NULL. Result can be NULL. Result
1266  * must be de-allocated by free.
1267  * @param hostname Hostname of the uri. Can be NULL. Result can be NULL. Result
1268  * must be de-allocated by free.
1269  * @param username Username of the uri. Can be NULL. Result can be NULL. Result
1270  * must be de-allocated by free.
1271  * @param password Password of the uri. Can be NULL. Result can be NULL. Result
1272  * must be de-allocated by free.
1273  * @param location Location of the uri. Can be NULL. Result is never NULL. Result
1274  * must be de-allocated by free.
1275  */
1276 #define uri_userinfo_remove libreport_uri_userinfo_remove
1277 int uri_userinfo_remove(const char *uri, char **result, char **scheme, char **hostname, char **username, char **password, char **location);
1278 
1279 #ifdef __cplusplus
1280 }
1281 #endif
1282 
1283 #endif