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