diff options
Diffstat (limited to 'src/hooks.c')
-rw-r--r-- | src/hooks.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/hooks.c b/src/hooks.c index b34313c..f649076 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -1,7 +1,7 @@ /* * Calcurse - text-based organizer * - * Copyright (c) 2004-2017 calcurse Development Team <misc@calcurse.org> + * Copyright (c) 2004-2023 calcurse Development Team <misc@calcurse.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,35 +35,38 @@ */ #include <stddef.h> +#include <sys/wait.h> #include "calcurse.h" int run_hook(const char *name) { - char *hook_path = NULL; + char *hook_path = NULL, *mesg; + int pid, pin, pout, perr, ret = -127; 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)) goto cleanup; + arg[0] = hook_path; + arg[1] = NULL; - if (prepare_wins) - wins_prepare_external(); - - if ((pid = shell_exec(NULL, NULL, *arg, arg))) { - ret = child_wait(NULL, NULL, pid); - if (ret) - press_any_key(); + if ((pid = shell_exec(&pin, &pout, &perr, 1, *arg, arg))) { + ret = child_wait(&pin, &pout, &perr, pid); + 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); return ret; |