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