libreport  2.1.7.10.g9b7b
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 
57 #ifdef HAVE_CONFIG_H
58 # include "config.h"
59 #endif
60 
61 /* Must be after #include "config.h" */
62 #if ENABLE_NLS
63 # include <libintl.h>
64 # define _(S) gettext(S)
65 #else
66 # define _(S) (S)
67 #endif
68 
69 #if 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 
91 /* Pull in entire public libreport API */
92 #include "dump_dir.h"
93 #include "event_config.h"
94 #include "problem_data.h"
95 #include "report.h"
96 #include "run_event.h"
97 #include "workflow.h"
98 #include "file_obj.h"
99 #include "libreport_types.h"
100 
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104 
105 #define prefixcmp libreport_prefixcmp
106 int prefixcmp(const char *str, const char *prefix);
107 #define suffixcmp libreport_suffixcmp
108 int suffixcmp(const char *str, const char *suffix);
109 #define strtrim libreport_strtrim
110 char *strtrim(char *str);
111 #define strtrimch libreport_strtrimch
112 char *strtrimch(char *str, int ch);
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 #define concat_path_file libreport_concat_path_file
124 char *concat_path_file(const char *path, const char *filename);
125 /*
126  * Used to construct a name in a different directory with the basename
127  * similar to the old name, if possible.
128  */
129 #define concat_path_basename libreport_concat_path_basename
130 char *concat_path_basename(const char *path, const char *filename);
131 
132 /* A-la fgets, but malloced and of unlimited size */
133 #define xmalloc_fgets libreport_xmalloc_fgets
134 char *xmalloc_fgets(FILE *file);
135 /* Similar, but removes trailing \n */
136 #define xmalloc_fgetline libreport_xmalloc_fgetline
137 char *xmalloc_fgetline(FILE *file);
138 /* Useful for easy reading of various /proc files */
139 #define xmalloc_fopen_fgetline_fclose libreport_xmalloc_fopen_fgetline_fclose
140 char *xmalloc_fopen_fgetline_fclose(const char *filename);
141 
142 
143 /* On error, copyfd_XX prints error messages and returns -1 */
144 enum {
145  COPYFD_SPARSE = 1 << 0,
146 };
147 #define copyfd_eof libreport_copyfd_eof
148 off_t copyfd_eof(int src_fd, int dst_fd, int flags);
149 #define copyfd_size libreport_copyfd_size
150 off_t copyfd_size(int src_fd, int dst_fd, off_t size, int flags);
151 #define copyfd_exact_size libreport_copyfd_exact_size
152 void copyfd_exact_size(int src_fd, int dst_fd, off_t size);
153 #define copy_file libreport_copy_file
154 off_t copy_file(const char *src_name, const char *dst_name, int mode);
155 #define copy_file_recursive libreport_copy_file_recursive
156 int copy_file_recursive(const char *source, const char *dest);
157 
158 // NB: will return short read on error, not -1,
159 // if some data was read before error occurred
160 #define xread libreport_xread
161 void xread(int fd, void *buf, size_t count);
162 #define safe_read libreport_safe_read
163 ssize_t safe_read(int fd, void *buf, size_t count);
164 #define safe_write libreport_safe_write
165 ssize_t safe_write(int fd, const void *buf, size_t count);
166 #define full_read libreport_full_read
167 ssize_t full_read(int fd, void *buf, size_t count);
168 #define full_write libreport_full_write
169 ssize_t full_write(int fd, const void *buf, size_t count);
170 #define full_write_str libreport_full_write_str
171 ssize_t full_write_str(int fd, const char *buf);
172 #define xmalloc_read libreport_xmalloc_read
173 void* xmalloc_read(int fd, size_t *maxsz_p);
174 #define xmalloc_open_read_close libreport_xmalloc_open_read_close
175 void* xmalloc_open_read_close(const char *filename, size_t *maxsz_p);
176 #define xmalloc_xopen_read_close libreport_xmalloc_xopen_read_close
177 void* xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p);
178 
179 
180 /* Returns malloc'ed block */
181 #define encode_base64 libreport_encode_base64
182 char *encode_base64(const void *src, int length);
183 
184 /* Returns NULL if the string needs no sanitizing.
185  * control_chars_to_sanitize is a bit mask.
186  * If Nth bit is set, Nth control char will be sanitized (replaced by [XX]).
187  */
188 #define sanitize_utf8 libreport_sanitize_utf8
189 char *sanitize_utf8(const char *src, uint32_t control_chars_to_sanitize);
190 enum {
191  SANITIZE_ALL = 0xffffffff,
192  SANITIZE_TAB = (1 << 9),
193  SANITIZE_LF = (1 << 10),
194  SANITIZE_CR = (1 << 13),
195 };
196 
197 #define SHA1_RESULT_LEN (5 * 4)
198 typedef struct sha1_ctx_t {
199  uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
200  /* for sha256: void (*process_block)(struct md5_ctx_t*); */
201  uint64_t total64; /* must be directly before hash[] */
202  uint32_t hash[8]; /* 4 elements for md5, 5 for sha1, 8 for sha256 */
203 } sha1_ctx_t;
204 #define sha1_begin libreport_sha1_begin
205 void sha1_begin(sha1_ctx_t *ctx);
206 #define sha1_hash libreport_sha1_hash
207 void sha1_hash(sha1_ctx_t *ctx, const void *buffer, size_t len);
208 #define sha1_end libreport_sha1_end
209 void sha1_end(sha1_ctx_t *ctx, void *resbuf);
210 
211 /* Helpers to hash a string: */
212 #define str_to_sha1 libreport_str_to_sha1
213 const uint8_t *str_to_sha1(uint8_t result[SHA1_RESULT_LEN], const char *str);
214 #define str_to_sha1str libreport_str_to_sha1str
215 const char *str_to_sha1str(char result[SHA1_RESULT_LEN*2 + 1], const char *str);
216 
217 
218 #define xatou libreport_xatou
219 unsigned xatou(const char *numstr);
220 #define xatoi libreport_xatoi
221 int xatoi(const char *numstr);
222 /* Using xatoi() instead of naive atoi() is not always convenient -
223  * in many places people want *non-negative* values, but store them
224  * in signed int. Therefore we need this one:
225  * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc.
226  * It should really be named xatoi_nonnegative (since it allows 0),
227  * but that would be too long.
228  */
229 #define xatoi_positive libreport_xatoi_positive
230 int xatoi_positive(const char *numstr);
231 
232 //unused for now
233 //unsigned long long monotonic_ns(void);
234 //unsigned long long monotonic_us(void);
235 //unsigned monotonic_sec(void);
236 
237 #define safe_waitpid libreport_safe_waitpid
238 pid_t safe_waitpid(pid_t pid, int *wstat, int options);
239 
240 enum {
241  /* on return, pipefds[1] is fd to which parent may write
242  * and deliver data to child's stdin: */
243  EXECFLG_INPUT = 1 << 0,
244  /* on return, pipefds[0] is fd from which parent may read
245  * child's stdout: */
246  EXECFLG_OUTPUT = 1 << 1,
247  /* open child's stdin to /dev/null: */
248  EXECFLG_INPUT_NUL = 1 << 2,
249  /* open child's stdout to /dev/null: */
250  EXECFLG_OUTPUT_NUL = 1 << 3,
251  /* redirect child's stderr to stdout: */
252  EXECFLG_ERR2OUT = 1 << 4,
253  /* open child's stderr to /dev/null: */
254  EXECFLG_ERR_NUL = 1 << 5,
255  /* suppress perror_msg("Can't execute 'foo'") if exec fails */
256  EXECFLG_QUIET = 1 << 6,
257  EXECFLG_SETGUID = 1 << 7,
258  EXECFLG_SETSID = 1 << 8,
259  EXECFLG_SETPGID = 1 << 9,
260 };
261 /*
262  * env_vec: list of variables to set in environment (if string has
263  * "VAR=VAL" form) or unset in environment (if string has no '=' char).
264  *
265  * Returns pid.
266  */
267 #define fork_execv_on_steroids libreport_fork_execv_on_steroids
268 pid_t fork_execv_on_steroids(int flags,
269  char **argv,
270  int *pipefds,
271  char **env_vec,
272  const char *dir,
273  uid_t uid);
274 /* Returns malloc'ed string. NULs are retained, and extra one is appended
275  * after the last byte (this NUL is not accounted for in *size_p) */
276 #define run_in_shell_and_save_output libreport_run_in_shell_and_save_output
277 char *run_in_shell_and_save_output(int flags,
278  const char *cmd,
279  const char *dir,
280  size_t *size_p);
281 
282 /* Random utility functions */
283 
284 #define is_in_string_list libreport_is_in_string_list
285 bool is_in_string_list(const char *name, char **v);
286 
287 #define is_in_comma_separated_list libreport_is_in_comma_separated_list
288 bool is_in_comma_separated_list(const char *value, const char *list);
289 #define is_in_comma_separated_list_of_glob_patterns libreport_is_in_comma_separated_list_of_glob_patterns
290 bool is_in_comma_separated_list_of_glob_patterns(const char *value, const char *list);
291 
292 /* Calls GLib version appropriate initialization function.
293  */
294 #define glib_init libreport_glib_init
295 void glib_init(void);
296 
297 /* Frees every element'd data using free(),
298  * then frees list itself using g_list_free(list):
299  */
300 #define list_free_with_free libreport_list_free_with_free
301 void list_free_with_free(GList *list);
302 
303 #define get_dirsize libreport_get_dirsize
304 double get_dirsize(const char *pPath);
305 #define get_dirsize_find_largest_dir libreport_get_dirsize_find_largest_dir
306 double get_dirsize_find_largest_dir(
307  const char *pPath,
308  char **worst_dir, /* can be NULL */
309  const char *excluded /* can be NULL */
310 );
311 
312 #define ndelay_on libreport_ndelay_on
313 int ndelay_on(int fd);
314 #define ndelay_off libreport_ndelay_off
315 int ndelay_off(int fd);
316 #define close_on_exec_on libreport_close_on_exec_on
317 int close_on_exec_on(int fd);
318 
319 #define xmalloc libreport_xmalloc
320 void* xmalloc(size_t size);
321 #define xrealloc libreport_xrealloc
322 void* xrealloc(void *ptr, size_t size);
323 #define xzalloc libreport_xzalloc
324 void* xzalloc(size_t size);
325 #define xstrdup libreport_xstrdup
326 char* xstrdup(const char *s);
327 #define xstrndup libreport_xstrndup
328 char* xstrndup(const char *s, int n);
329 
330 #define xpipe libreport_xpipe
331 void xpipe(int filedes[2]);
332 #define xdup libreport_xdup
333 int xdup(int from);
334 #define xdup2 libreport_xdup2
335 void xdup2(int from, int to);
336 #define xmove_fd libreport_xmove_fd
337 void xmove_fd(int from, int to);
338 
339 #define xwrite libreport_xwrite
340 void xwrite(int fd, const void *buf, size_t count);
341 #define xwrite_str libreport_xwrite_str
342 void xwrite_str(int fd, const char *str);
343 
344 #define xlseek libreport_xlseek
345 off_t xlseek(int fd, off_t offset, int whence);
346 
347 #define xchdir libreport_xchdir
348 void xchdir(const char *path);
349 
350 #define xvasprintf libreport_xvasprintf
351 char* xvasprintf(const char *format, va_list p);
352 #define xasprintf libreport_xasprintf
353 char* xasprintf(const char *format, ...);
354 
355 #define xsetenv libreport_xsetenv
356 void xsetenv(const char *key, const char *value);
357 /*
358  * Utility function to unsetenv a string which was possibly putenv'ed.
359  * The problem here is that "natural" optimization:
360  * strchrnul(var_val, '=')[0] = '\0';
361  * unsetenv(var_val);
362  * is BUGGY: if string was put into environment via putenv,
363  * its modification (s/=/NUL/) is illegal, and unsetenv will fail to unset it.
364  * Of course, saving/restoring the char wouldn't work either.
365  * This helper creates a copy up to '=', unsetenv's it, and frees:
366  */
367 #define safe_unsetenv libreport_safe_unsetenv
368 void safe_unsetenv(const char *var_val);
369 
370 #define xsocket libreport_xsocket
371 int xsocket(int domain, int type, int protocol);
372 #define xbind libreport_xbind
373 void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
374 #define xlisten libreport_xlisten
375 void xlisten(int s, int backlog);
376 #define xsendto libreport_xsendto
377 ssize_t xsendto(int s, const void *buf, size_t len,
378  const struct sockaddr *to, socklen_t tolen);
379 
380 #define xstat libreport_xstat
381 void xstat(const char *name, struct stat *stat_buf);
382 #define fstat_st_size_or_die libreport_fstat_st_size_or_die
383 off_t fstat_st_size_or_die(int fd);
384 #define stat_st_size_or_die libreport_stat_st_size_or_die
385 off_t stat_st_size_or_die(const char *filename);
386 
387 #define xopen3 libreport_xopen3
388 int xopen3(const char *pathname, int flags, int mode);
389 #define xopen libreport_xopen
390 int xopen(const char *pathname, int flags);
391 #define xunlink libreport_xunlink
392 void xunlink(const char *pathname);
393 
394 /* Just testing dent->d_type == DT_REG is wrong: some filesystems
395  * do not report the type, they report DT_UNKNOWN for every dirent
396  * (and this is not a bug in filesystem, this is allowed by standards).
397  * This function handles this case. Note: it returns 0 on symlinks
398  * even if they point to regular files.
399  */
400 #define is_regular_file libreport_is_regular_file
401 int is_regular_file(struct dirent *dent, const char *dirname);
402 
403 #define dot_or_dotdot libreport_dot_or_dotdot
404 bool dot_or_dotdot(const char *filename);
405 #define last_char_is libreport_last_char_is
406 char *last_char_is(const char *s, int c);
407 
408 #define string_to_bool libreport_string_to_bool
409 bool string_to_bool(const char *s);
410 
411 #define xseteuid libreport_xseteuid
412 void xseteuid(uid_t euid);
413 #define xsetegid libreport_xsetegid
414 void xsetegid(gid_t egid);
415 #define xsetreuid libreport_xsetreuid
416 void xsetreuid(uid_t ruid, uid_t euid);
417 #define xsetregid libreport_xsetregid
418 void xsetregid(gid_t rgid, gid_t egid);
419 
420 
421 /* Emit a string of hex representation of bytes */
422 #define bin2hex libreport_bin2hex
423 char* bin2hex(char *dst, const char *str, int count);
424 /* Convert "xxxxxxxx" hex string to binary, no more than COUNT bytes */
425 #define hex2bin libreport_hex2bin
426 char* hex2bin(char *dst, const char *str, int count);
427 
428 
429 enum {
430  LOGMODE_NONE = 0,
431  LOGMODE_STDIO = (1 << 0),
432  LOGMODE_SYSLOG = (1 << 1),
433  LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
434  LOGMODE_CUSTOM = (1 << 2),
435 };
436 
437 #define g_custom_logger libreport_g_custom_logger
438 extern void (*g_custom_logger)(const char*);
439 #define msg_prefix libreport_msg_prefix
440 extern const char *msg_prefix;
441 #define msg_eol libreport_msg_eol
442 extern const char *msg_eol;
443 #define logmode libreport_logmode
444 extern int logmode;
445 #define xfunc_error_retval libreport_xfunc_error_retval
446 extern int xfunc_error_retval;
447 
448 /* A few magic exit codes */
449 #define EXIT_CANCEL_BY_USER 69
450 #define EXIT_STOP_EVENT_RUN 70
451 
452 #define set_xfunc_error_retval libreport_set_xfunc_error_retval
453 void set_xfunc_error_retval(int retval);
454 
455 /* Verbosity level */
456 #define g_verbose libreport_g_verbose
457 extern int g_verbose;
458 /* VERB1 log("what you sometimes want to see, even on a production box") */
459 #define VERB1 if (g_verbose >= 1)
460 /* VERB2 log("debug message, not going into insanely small details") */
461 #define VERB2 if (g_verbose >= 2)
462 /* VERB3 log("lots and lots of details") */
463 #define VERB3 if (g_verbose >= 3)
464 /* there is no level > 3 */
465 
466 #define libreport_
467 #define xfunc_die libreport_xfunc_die
468 void xfunc_die(void) NORETURN;
469 #define log_msg libreport_log_msg
470 void log_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
471 /* It's a macro, not function, since it collides with log() from math.h */
472 #undef log
473 #define log(...) log_msg(__VA_ARGS__)
474 /* error_msg family will use g_custom_logger. log_msg does not. */
475 #define error_msg libreport_error_msg
476 void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
477 #define error_msg_and_die libreport_error_msg_and_die
478 void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
479 /* Reports error message with libc's errno error description attached. */
480 #define perror_msg libreport_perror_msg
481 void perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
482 #define perror_msg_and_die libreport_perror_msg_and_die
483 void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
484 #define die_out_of_memory libreport_die_out_of_memory
485 void die_out_of_memory(void) NORETURN;
486 
487 
488 struct strbuf
489 {
490  /* Size of the allocated buffer. Always > 0. */
491  int alloc;
492  /* Length of the string, without the ending \0. */
493  int len;
494  char *buf;
495 };
496 
503 #define strbuf_new libreport_strbuf_new
504 struct strbuf *strbuf_new(void);
505 
511 #define strbuf_free libreport_strbuf_free
512 void strbuf_free(struct strbuf *strbuf);
513 
519 #define strbuf_free_nobuf libreport_strbuf_free_nobuf
520 char* strbuf_free_nobuf(struct strbuf *strbuf);
521 
526 #define strbuf_clear libreport_strbuf_clear
527 void strbuf_clear(struct strbuf *strbuf);
528 
533 #define strbuf_append_char libreport_strbuf_append_char
534 struct strbuf *strbuf_append_char(struct strbuf *strbuf, char c);
535 
540 #define strbuf_append_str libreport_strbuf_append_str
541 struct strbuf *strbuf_append_str(struct strbuf *strbuf,
542  const char *str);
543 
548 #define strbuf_prepend_str libreport_strbuf_prepend_str
549 struct strbuf *strbuf_prepend_str(struct strbuf *strbuf,
550  const char *str);
551 
556 #define strbuf_append_strf libreport_strbuf_append_strf
557 struct strbuf *strbuf_append_strf(struct strbuf *strbuf,
558  const char *format, ...);
559 
564 #define strbuf_append_strfv libreport_strbuf_append_strfv
565 struct strbuf *strbuf_append_strfv(struct strbuf *strbuf,
566  const char *format, va_list p);
567 
573 #define strbuf_prepend_strf libreport_strbuf_prepend_strf
574 struct strbuf *strbuf_prepend_strf(struct strbuf *strbuf,
575  const char *format, ...);
576 
581 #define strbuf_prepend_strfv libreport_strbuf_prepend_strfv
582 struct strbuf *strbuf_prepend_strfv(struct strbuf *strbuf,
583  const char *format, va_list p);
584 
585 /* Returns command line of running program.
586  * Caller is responsible to free() the returned value.
587  * If the pid is not valid or command line can not be obtained,
588  * empty string is returned.
589  */
590 #define get_cmdline libreport_get_cmdline
591 char* get_cmdline(pid_t pid);
592 #define get_environ libreport_get_environ
593 char* get_environ(pid_t pid);
594 
595 /* Takes ptr to time_t, or NULL if you want to use current time.
596  * Returns "YYYY-MM-DD-hh:mm:ss" string.
597  */
598 #define iso_date_string libreport_iso_date_string
599 char *iso_date_string(const time_t *pt);
600 #define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
601 
602 enum {
603  MAKEDESC_SHOW_FILES = (1 << 0),
604  MAKEDESC_SHOW_MULTILINE = (1 << 1),
605  MAKEDESC_SHOW_ONLY_LIST = (1 << 2),
606  MAKEDESC_WHITELIST = (1 << 3),
607 };
608 #define make_description libreport_make_description
609 char *make_description(problem_data_t *problem_data, char **names_to_skip, unsigned max_text_size, unsigned desc_flags);
610 #define make_description_bz libreport_make_description_bz
611 char* make_description_bz(problem_data_t *problem_data, unsigned max_text_size);
612 #define make_description_logger libreport_make_description_logger
613 char* make_description_logger(problem_data_t *problem_data, unsigned max_text_size);
614 //UNUSED
615 //#define make_description_mailx libreport_make_description_mailx
616 //char* make_description_mailx(problem_data_t *problem_data);
617 
618 /* See man os-release(5) for details */
619 #define OSINFO_ID "ID"
620 #define OSINFO_NAME "NAME"
621 #define OSINFO_VERSION_ID "VERSION_ID"
622 #define OSINFO_PRETTY_NAME "PRETTY_NAME"
623 
624 /* @brief Loads a text in format of os-release(5) in to a map
625  *
626  * Function doesn't check for format errors much. It just tries to avoid
627  * program errors. In case of error the function prints out a log message and
628  * continues in parsing.
629  *
630  * @param osinfo_bytes Non-NULL pointer to osinfo bytes.
631  * @param osinfo The map where result is stored
632  */
633 #define parse_osinfo libreport_parse_osinfo
634 void parse_osinfo(const char *osinfo_bytes, map_string_t *osinfo);
635 
636 /* @brief Builds product string and product's version string for Bugzilla
637  *
638  * At first tries to get strings from the os specific variables
639  * (REDHAT_BUGZILLA_PRODUCT, REDHAT_BUGZILLA_PRODUCT_VERSION) if no such
640  * variables are found, uses NAME key for the product and VERSION_ID key for
641  * the product's version. If neither NAME nor VERSION_ID are provided fallbacks
642  * to parsing of os_release which should be stored under PRETTY_NAME key.
643  *
644  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
645  *
646  * @param osinfo Input data from which the values are built
647  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
648  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
649  */
650 #define parse_osinfo_for_bz libreport_parse_osinfo_for_bz
651 void parse_osinfo_for_bz(map_string_t *osinfo, char **product, char **version);
652 
653 /* @brief Builds product string and product's version string for Red Hat Support
654  *
655  * At first tries to get strings from the os specific variables
656  * (REDHAT_SUPPORT_PRODUCT, REDHAT_SUPPORT_PRODUCT_VERSION) if no such
657  * variables are found, uses NAME key for the product and VERSION_ID key for
658  * the product's version. If no NAME nor VERSION_ID are provided fallbacks to
659  * parsing of os_release which should be stored under PRETTY_NAME key.
660  *
661  * https://bugzilla.redhat.com/show_bug.cgi?id=950373
662  *
663  * @param osinfo Input data from which the values are built
664  * @param produc Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
665  * @param version Non-NULL pointer where pointer to malloced string will be stored. Memory must be released by free()
666  */
667 #define parse_osinfo_for_rhts libreport_parse_osinfo_for_rhts
668 void parse_osinfo_for_rhts(map_string_t *osinfo, char **product, char **version);
669 
670 #define parse_release_for_bz libreport_parse_release_for_bz
671 void parse_release_for_bz(const char *pRelease, char **product, char **version);
672 #define parse_release_for_rhts libreport_parse_release_for_rhts
673 void parse_release_for_rhts(const char *pRelease, char **product, char **version);
674 
689 #define load_conf_file libreport_load_conf_file
690 bool load_conf_file(const char *pPath, map_string_t *settings, bool skipKeysWithoutValue);
691 
692 #define save_conf_file libreport_save_conf_file
693 bool save_conf_file(const char *path, map_string_t *settings);
694 
695 #define save_app_conf_file libreport_save_app_conf_file
696 bool save_app_conf_file(const char* application_name, map_string_t *settings);
697 #define load_app_conf_file libreport_load_app_conf_file
698 bool load_app_conf_file(const char *application_name, map_string_t *settings);
699 #define set_app_user_setting libreport_set_app_user_setting
700 void set_app_user_setting(map_string_t *settings, const char *name, const char *value);
701 #define get_app_user_setting libreport_get_app_user_setting
702 const char *get_app_user_setting(map_string_t *settings, const char *name);
703 
704 #define save_user_settings libreport_save_user_settings
705 bool save_user_settings();
706 #define load_user_settings libreport_load_user_settings
707 bool load_user_settings(const char *application_name);
708 #define set_user_setting libreport_set_user_setting
709 void set_user_setting(const char *name, const char *value);
710 #define get_user_setting libreport_get_user_setting
711 const char *get_user_setting(const char *name);
712 
713 /* filename is expected to exist in CONF_DIR
714  * usually /etc/libreport
715  */
716 #define load_forbidden_words libreport_load_forbidden_words
717 GList *load_words_from_file(const char *filename);
718 #define get_file_list libreport_get_file_list
719 GList *get_file_list(const char *path, const char *ext);
720 #define free_file_list libreport_free_file_list
721 void free_file_list(GList *filelist);
722 #define new_file_obj libreport_new_file_obj
723 file_obj_t *new_file_obj(const char* fullpath, const char* filename);
724 #define free_file_obj libreport_free_file_obj
725 void free_file_obj(file_obj_t *f);
726 #define load_workflow_config_data libreport_load_workflow_config_data
727 GHashTable *load_workflow_config_data(const char* path);
728 #define parse_list libreport_parse_list
729 GList *parse_list(const char* list);
730 
731 /* Connect to abrtd over unix domain socket, issue DELETE command */
732 int delete_dump_dir_possibly_using_abrtd(const char *dump_dir_name);
733 
734 /* Tries to create a copy of dump_dir_name in base_dir, with same or similar basename.
735  * Returns NULL if copying failed. In this case, logs a message before returning. */
736 #define steal_directory libreport_steal_directory
737 struct dump_dir *steal_directory(const char *base_dir, const char *dump_dir_name);
738 
739 /* Tries to open dump_dir_name with writing access. If function needs to steal
740  * directory calls ask_continue(new base dir, dump dir) callback to ask user
741  * for permission. If ask_continue param is NULL the function thinks that an
742  * answer is positive and steals directory.
743  * Returns NULL if opening failed or if stealing was dismissed. In this case,
744  * logs a message before returning. */
745 #define open_directory_for_writing libreport_open_directory_for_writing
746 struct dump_dir *open_directory_for_writing(
747  const char *dump_dir_name,
748  bool (*ask_continue)(const char *, const char *));
749 
750 // Files bigger than this are never considered to be text.
751 //
752 // Started at 64k limit. But _some_ limit is necessary:
753 // fields declared "text" may end up in editing fields and such.
754 // We don't want to accidentally end up with 100meg text in a textbox!
755 // So, don't remove this. If you really need to, raise the limit.
756 //
757 // Bumped up to 200k: saw 124740 byte /proc/PID/smaps file
758 // Bumped up to 500k: saw 375252 byte anaconda traceback file
759 // Bumped up to 1M: bugzilla.redhat.com/show_bug.cgi?id=746727
760 // mentions 853646 byte anaconda-tb-* file.
761 // Bumped up to 8M: bugzilla.redhat.com/show_bug.cgi?id=887570
762 // (anaconda-tb file of 1.38 MBytes)
763 //
764 #define CD_MAX_TEXT_SIZE (8*1024*1024)
765 
766 // Text bigger than this usually is attached, not added inline
767 // was 2k, 20kb is too much, let's try 4kb
768 //
769 // For bug databases
770 #define CD_TEXT_ATT_SIZE_BZ (4*1024)
771 // For dumping problem data into a text file, email, etc
772 #define CD_TEXT_ATT_SIZE_LOGGER (CD_MAX_TEXT_SIZE)
773 
774 // Filenames in problem directory:
775 // filled by a hook:
776 #define FILENAME_TIME "time" /* mandatory */
777 #define FILENAME_LAST_OCCURRENCE "last_occurrence" /* optional */
778 #define FILENAME_REASON "reason" /* mandatory? */
779 #define FILENAME_UID "uid" /* mandatory? */
780 /*
781  * "analyzer" is to be gradually changed to "type":
782  * For now, we fetch and look at "analyzer" element,
783  * but we always save both "analyzer" and "type" (with same contents).
784  * By 2013, we switch to looking at "type". Then we will stop generating
785  * "analyzer" element.
786  */
787 #define FILENAME_ANALYZER "analyzer"
788 #define FILENAME_TYPE "type"
789 #define FILENAME_EXECUTABLE "executable"
790 #define FILENAME_PID "pid"
791 #define FILENAME_PWD "pwd"
792 #define FILENAME_ROOTDIR "rootdir"
793 #define FILENAME_BINARY "binary"
794 #define FILENAME_CMDLINE "cmdline"
795 #define FILENAME_COREDUMP "coredump"
796 #define FILENAME_CGROUP "cgroup"
797 #define FILENAME_BACKTRACE "backtrace"
798 #define FILENAME_MAPS "maps"
799 #define FILENAME_SMAPS "smaps"
800 #define FILENAME_PROC_PID_STATUS "proc_pid_status"
801 #define FILENAME_ENVIRON "environ"
802 #define FILENAME_LIMITS "limits"
803 #define FILENAME_OPEN_FDS "open_fds"
804 
805 /* Global problem identifier which is usually generated by some "analyze_*"
806  * event because it may take a lot of time to obtain strong problem
807  * identification */
808 #define FILENAME_DUPHASH "duphash"
809 
810 // Name of the function where the application crashed.
811 // Optional.
812 #define FILENAME_CRASH_FUNCTION "crash_function"
813 #define FILENAME_ARCHITECTURE "architecture"
814 #define FILENAME_KERNEL "kernel"
815 /*
816  * From /etc/os-release
817  * os_release filename name is alredy occupied by /etc/redhat-release (see
818  * below) in sake of backward compatibility /etc/os-release is stored in
819  * os_info file
820  */
821 #define FILENAME_OS_INFO "os_info"
822 #define FILENAME_OS_INFO_IN_ROOTDIR "os_info_in_rootdir"
823 // From /etc/system-release or /etc/redhat-release
824 #define FILENAME_OS_RELEASE "os_release"
825 #define FILENAME_OS_RELEASE_IN_ROOTDIR "os_release_in_rootdir"
826 // Filled by <what?>
827 #define FILENAME_PACKAGE "package"
828 #define FILENAME_COMPONENT "component"
829 #define FILENAME_COMMENT "comment"
830 #define FILENAME_RATING "backtrace_rating"
831 #define FILENAME_HOSTNAME "hostname"
832 // Optional. Set to "1" by abrt-handle-upload for every unpacked dump
833 #define FILENAME_REMOTE "remote"
834 #define FILENAME_TAINTED "kernel_tainted"
835 #define FILENAME_TAINTED_SHORT "kernel_tainted_short"
836 #define FILENAME_TAINTED_LONG "kernel_tainted_long"
837 #define FILENAME_VMCORE "vmcore"
838 #define FILENAME_KERNEL_LOG "kernel_log"
839 // File created by createAlertSignature() from libreport's python module
840 // The file should contain a description of an alert
841 #define FILENAME_DESCRIPTION "description"
842 
843 /* Local problem identifier (weaker than global identifier) designed for fast
844  * local for fast local duplicate identification. This file is usually provided
845  * by crashed application (problem creator).
846  */
847 #define FILENAME_UUID "uuid"
848 
849 #define FILENAME_COUNT "count"
850 /* Multi-line list of places problem was reported.
851  * Recommended line format:
852  * "Reporter: VAR=VAL VAR=VAL"
853  * Use add_reported_to(dd, "line_without_newline"): it adds line
854  * only if it is not already there.
855  */
856 #define FILENAME_REPORTED_TO "reported_to"
857 #define FILENAME_EVENT_LOG "event_log"
858 /*
859  * If exists, should contain a full sentence (with trailing period)
860  * which describes why this problem should not be reported.
861  * Example: "Your laptop firmware 1.9a is buggy, version 1.10 contains the fix."
862  */
863 #define FILENAME_NOT_REPORTABLE "not-reportable"
864 #define FILENAME_CORE_BACKTRACE "core_backtrace"
865 #define FILENAME_REMOTE_RESULT "remote_result"
866 #define FILENAME_PKG_EPOCH "pkg_epoch"
867 #define FILENAME_PKG_NAME "pkg_name"
868 #define FILENAME_PKG_VERSION "pkg_version"
869 #define FILENAME_PKG_RELEASE "pkg_release"
870 #define FILENAME_PKG_ARCH "pkg_arch"
871 #define FILENAME_USERNAME "username"
872 #define FILENAME_ABRT_VERSION "abrt_version"
873 #define FILENAME_EXPLOITABLE "exploitable"
874 
875 // Not stored as files, added "on the fly":
876 #define CD_DUMPDIR "Directory"
877 
878 #define cmp_problem_data libreport_cmp_problem_data
879 gint cmp_problem_data(gconstpointer a, gconstpointer b, gpointer filename);
880 
881 //UNUSED:
884 //#define CD_EVENTS "Events"
885 
886 /* FILENAME_EVENT_LOG is trimmed to below LOW_WATERMARK
887  * when it reaches HIGH_WATERMARK size
888  */
889 enum {
890  EVENT_LOG_HIGH_WATERMARK = 30 * 1024,
891  EVENT_LOG_LOW_WATERMARK = 20 * 1024,
892 };
893 
894 #define log_problem_data libreport_log_problem_data
895 void log_problem_data(problem_data_t *problem_data, const char *pfx);
896 
897 
898 const char *abrt_init(char **argv);
899 #define export_abrt_envvars libreport_export_abrt_envvars
900 void export_abrt_envvars(int pfx);
901 #define g_progname libreport_g_progname
902 extern const char *g_progname;
903 
904 enum parse_opt_type {
905  OPTION_BOOL,
906  OPTION_GROUP,
907  OPTION_STRING,
908  OPTION_INTEGER,
909  OPTION_OPTSTRING,
910  OPTION_LIST,
911  OPTION_END,
912 };
913 
914 struct options {
915  enum parse_opt_type type;
916  int short_name;
917  const char *long_name;
918  void *value;
919  const char *argh;
920  const char *help;
921 };
922 
923 /*
924  * s - short_name
925  * l - long_name
926  * v - value
927  * a - option parameter name (for help text)
928  * h - help
929  */
930 #define OPT_END() { OPTION_END }
931 #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
932 #define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) }
933 #define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) }
934 #define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) }
935 #define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) }
936 #define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) }
937 
938 #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose"))
939 #define OPT__DUMP_DIR(v) OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
940 
941 #define parse_opts libreport_parse_opts
942 unsigned parse_opts(int argc, char **argv, const struct options *opt,
943  const char *usage);
944 
945 #define show_usage_and_die libreport_show_usage_and_die
946 void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
947 
948 /* Can't include "abrt_curl.h", it's not a public API.
949  * Resorting to just forward-declaring the struct we need.
950  */
951 struct abrt_post_state;
952 
953 #ifdef __cplusplus
954 }
955 #endif
956 
957 #endif