diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2020-07-12 23:30:45 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2020-07-26 10:31:31 -0400 |
commit | 2230525f4a14ae9e8a5e7a76ae205101904a7f7f (patch) | |
tree | 2c9c5f95d1ba2b62de6d4586acff3790cf98b328 | |
parent | f743eab5ac96314044fe748f0f1875a1ee78d3a9 (diff) | |
download | calcurse-2230525f4a14ae9e8a5e7a76ae205101904a7f7f.tar.gz calcurse-2230525f4a14ae9e8a5e7a76ae205101904a7f7f.zip |
Run hooks quietly
Hooks should not be run like external programs, but like load and save
operations that do not take possession of the terminal.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r-- | src/hooks.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/hooks.c b/src/hooks.c index 20aed69..8fda0da 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -35,36 +35,41 @@ */ #include <stddef.h> +#include <sys/wait.h> #include "calcurse.h" int run_hook(const char *name) { - char *hook_path = NULL; + char *hook_cmd = NULL, *mesg; char const *arg[2]; int pid, ret = -127; - int prepare_wins = (ui_mode == UI_CURSES); - asprintf(&hook_path, "%s/%s", path_hooks, name); - arg[0] = hook_path; - arg[1] = NULL; - - if (!io_file_exists(hook_path)) + asprintf(&hook_cmd, "%s/%s", path_hooks, name); + if (!io_file_exists(hook_cmd)) goto cleanup; - if (prepare_wins) - wins_prepare_external(); + asprintf(&hook_cmd, "%s <&- >&- 2>&-", hook_cmd); + arg[0] = hook_cmd; + arg[1] = NULL; if ((pid = shell_exec(NULL, NULL, *arg, arg))) { ret = child_wait(NULL, NULL, pid); - if (ret) - press_any_key(); + if (ret > 0 && WIFEXITED(ret)) { + asprintf(&mesg, "%s hook: exit status %d", + name, + WEXITSTATUS(ret)); + que_ins(mesg, now(), 3); + mem_free(mesg); + } else if (ret != 0) { + asprintf(&mesg, "%s hook: abnormal termination", + name); + que_ins(mesg, now(), 4); + mem_free(mesg); + } } - if (prepare_wins) - wins_unprepare_external(); - cleanup: - mem_free(hook_path); + mem_free(hook_cmd); return ret; } |