diff --git a/src/log.h b/src/log.h index 55140a7..1bfc921 100644 --- a/src/log.h +++ b/src/log.h @@ -14,6 +14,8 @@ #define LOG_I g_info #define LOG_D g_debug +#define DIE(...) do { LOG_C(__VA_ARGS__); exit(EXIT_FAILURE); } while (0) + void dunst_log_init(bool testing); #endif diff --git a/src/option_parser.c b/src/option_parser.c index 7641ccb..9f9d00d 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -8,6 +8,7 @@ #include #include +#include "log.h" #include "utils.h" typedef struct _entry_t { @@ -42,7 +43,7 @@ section_t *new_section(const char *name) { for (int i = 0; i < section_count; i++) { if (!strcmp(name, sections[i].name)) { - die("Duplicated section in dunstrc detected.\n", -1); + DIE("Duplicated section in dunstrc detected."); } } diff --git a/src/settings.c b/src/settings.c index 90fc321..f4eb88e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -13,6 +13,7 @@ #include "rules.h" // put before config.h to fix missing include #include "config.h" #include "dunst.h" +#include "log.h" #include "notification.h" #include "option_parser.h" #include "utils.h" @@ -85,10 +86,7 @@ void load_settings(char *cmdline_config_path) } if(!config_file) { - char *msg = g_strdup_printf( - "Cannot find config file: '%s'\n", - cmdline_config_path); - die(msg, 1); + DIE("Cannot find config file: '%s'", cmdline_config_path); } } if (config_file == NULL) { diff --git a/src/utils.c b/src/utils.c index eff2f78..6972a67 100644 --- a/src/utils.c +++ b/src/utils.c @@ -8,6 +8,8 @@ #include #include +#include "log.h" + char *string_replace_char(char needle, char replacement, char *haystack) { char *current = haystack; @@ -164,10 +166,4 @@ gint64 string_to_time(const char *string) return 0; } -void die(char *text, int exit_value) -{ - fputs(text, stderr); - exit(exit_value); -} - /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/utils.h b/src/utils.h index 18333d9..874bb49 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,9 +21,6 @@ char *string_append(char *a, const char *b, const char *sep); /* strip content between two delimiter characters (inplace) */ void string_strip_delimited(char *str, char a, char b); -/* exit with an error message */ -void die(char *msg, int exit_value); - /* replace tilde and path-specific values with its equivalents */ char *string_to_path(char *string); diff --git a/src/x11/x.c b/src/x11/x.c index 0f38487..b640902 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -26,6 +26,7 @@ #include "src/dbus.h" #include "src/dunst.h" +#include "src/log.h" #include "src/markup.h" #include "src/notification.h" #include "src/queues.h" @@ -996,7 +997,7 @@ void x_setup(void) if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); if (!(xctx.dpy = XOpenDisplay(NULL))) { - die("cannot open display\n", EXIT_FAILURE); + DIE("Cannot open X11 display."); } x_shortcut_init(&settings.close_ks);