diff --git a/src/notification.c b/src/notification.c index b2d70c7..b91a3d4 100644 --- a/src/notification.c +++ b/src/notification.c @@ -133,6 +133,26 @@ void notification_run_script(struct notification *n) if (pid2) { exit(0); } else { + // Set environment variables + gchar *n_id_str = g_strdup_printf("%i", n->id); + gchar *n_progress_str = g_strdup_printf("%i", n->progress); + gchar *n_timeout_str = g_strdup_printf("%li", n->timeout/1000); + gchar *n_timestamp_str = g_strdup_printf("%li", n->timestamp / 1000); + char* icon_path = get_path_from_icon_name(icon); + safe_setenv("DUNST_APP_NAME", appname); + safe_setenv("DUNST_SUMMARY", summary); + safe_setenv("DUNST_BODY", body); + safe_setenv("DUNST_ICON_PATH", icon_path); + safe_setenv("DUNST_URGENCY", urgency); + safe_setenv("DUNST_ID", n_id_str); + safe_setenv("DUNST_PROGRESS", n_progress_str); + safe_setenv("DUNST_CATEGORY", n->category); + safe_setenv("DUNST_STACK_TAG", n->stack_tag); + safe_setenv("DUNST_URLS", n->urls); + safe_setenv("DUNST_TIMEOUT", n_timeout_str); + safe_setenv("DUNST_TIMESTAMP", n_timestamp_str); + safe_setenv("DUNST_STACK_TAG", n->stack_tag); + int ret = execlp(script, script, appname, @@ -142,7 +162,7 @@ void notification_run_script(struct notification *n) urgency, (char *)NULL); if (ret != 0) { - LOG_W("Unable to run script: %s", strerror(errno)); + LOG_W("Unable to run script %s: %s", n->scripts[i], strerror(errno)); exit(EXIT_FAILURE); } } diff --git a/src/notification.h b/src/notification.h index 93ca749..7457460 100644 --- a/src/notification.h +++ b/src/notification.h @@ -55,9 +55,9 @@ struct notification { char *iconname; /**< plain icon information (may be a path or just a name) Use this to compare the icon name with rules.*/ - gint64 start; /**< begin of current display */ - gint64 timestamp; /**< arrival time */ - gint64 timeout; /**< time to display */ + gint64 start; /**< begin of current display (in milliseconds) */ + gint64 timestamp; /**< arrival time (in milliseconds) */ + gint64 timeout; /**< time to display (in milliseconds) */ int locked; /**< If non-zero the notification is locked **/ GHashTable *actions; diff --git a/src/utils.c b/src/utils.c index cc2770f..f59c968 100644 --- a/src/utils.c +++ b/src/utils.c @@ -247,4 +247,16 @@ const char *user_get_home(void) return home_directory; } +bool safe_setenv(const char* key, const char* value){ + if (!key) + return false; + + if (!value) + setenv(key, "", 1); + else + setenv(key, value, 1); + + return true; +} + /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/utils.h b/src/utils.h index c0368bd..5e7ba6d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,6 +4,7 @@ #include #include +#include //! Test if a string is NULL or empty #define STR_EMPTY(s) (!s || (*s == '\0')) @@ -137,5 +138,16 @@ gint64 time_monotonic_now(void); */ const char *user_get_home(void); +/** + * Try to set an environment variable safely. If an environment variable with + * name `key` exists, it will be overwritten. + * If `value` is null, `key` will be set to an empty string. + * + * @param key (nullable) The environment variable to change + * @param value (nullable) The value to change it to. + * @returns: A bool that is true when it succeeds + */ +bool safe_setenv(const char* key, const char* value); + #endif /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */