diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-06 09:55:27 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-06 09:55:27 +0100 |
commit | 4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a (patch) | |
tree | 6c137a20f95f0be71d11940c6acb77e11aee6377 /src/hooks.c | |
parent | Fix warning (diff) | |
download | redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.gz redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.bz2 redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.xz |
Style
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r-- | src/hooks.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/hooks.c b/src/hooks.c index 9a9f8ac..cc26c7c 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -42,14 +42,14 @@ open_hooks_dir(char *hp) struct passwd *pwd; #endif - if ((env = getenv("XDG_CONFIG_HOME")) != NULL && - env[0] != '\0') { + env = getenv("XDG_CONFIG_HOME"); + if (env && *env) { snprintf(hp, MAX_HOOK_PATH, "%s/redshift/hooks", env); return opendir(hp); } - if ((env = getenv("HOME")) != NULL && - env[0] != '\0') { + env = getenv("HOME"); + if (env && *env) { snprintf(hp, MAX_HOOK_PATH, "%s/.config/redshift/hooks", env); return opendir(hp); } @@ -75,15 +75,16 @@ hooks_signal_period_change(enum period prev_period, enum period period) int r; hooks_dir = open_hooks_dir(hooksdir_path); - if (hooks_dir == NULL) return; + if (!hooks_dir) + return; - while ((ent = readdir(hooks_dir)) != NULL) { + while ((ent = readdir(hooks_dir))) { /* Skip hidden and special files (., ..) */ - if (ent->d_name[0] == '\0' || ent->d_name[0] == '.') continue; + if (ent->d_name[0] == '\0' || ent->d_name[0] == '.') + continue; hook_name = ent->d_name; - snprintf(hook_path, sizeof(hook_path), "%s/%s", - hooksdir_path, hook_name); + snprintf(hook_path, sizeof(hook_path), "%s/%s", hooksdir_path, hook_name); #ifndef WINDOWS /* Fork and exec the hook. We close stdout @@ -97,10 +98,11 @@ hooks_signal_period_change(enum period prev_period, enum period period) close(STDOUT_FILENO); r = execl(hook_path, hook_name, - "period-changed", - period_names[prev_period], - period_names[period], NULL); - if (r < 0 && errno != EACCES) perror("execl"); + "period-changed", + period_names[prev_period], + period_names[period], NULL); + if (r < 0 && errno != EACCES) + weprintf("execl %s:", hook_path); /* Only reached on error */ _exit(EXIT_FAILURE); |