diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2021-04-04 11:26:46 -0400 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2021-04-04 12:15:31 -0400 |
commit | 193ad3415a0e76bf046bfcc3f03dd65742f18589 (patch) | |
tree | 8886dda7957bf024a0404c7834fb6fb0d43ade11 /src/notify.c | |
parent | 5710a8bd7fc3d5a3e46f108c16199ed7553515f0 (diff) | |
download | calcurse-193ad3415a0e76bf046bfcc3f03dd65742f18589.tar.gz calcurse-193ad3415a0e76bf046bfcc3f03dd65742f18589.zip |
Redirect standard descriptors for hook/notify commands
Disconnect stdin, stdout and stderr when running an external hook or
notification command. The previous solution of appending "<&- >&- 2>&-"
to the shell command line does not work if the command includes pipes.
Use shell_exec() in notify_launch_cmd() instead of a custom (and
incomplete) reimplementation of that command.
Partially addresses GitHub issue #326.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/notify.c')
-rw-r--r-- | src/notify.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/notify.c b/src/notify.c index 036af0f..b73c369 100644 --- a/src/notify.c +++ b/src/notify.c @@ -137,9 +137,6 @@ void notify_init_vars(void) strncpy(nbar.cmd, cmd, BUFSIZ); nbar.cmd[BUFSIZ - 1] = '\0'; - if ((nbar.shell = getenv("SHELL")) == NULL) - nbar.shell = "/bin/sh"; - nbar.notify_all = 0; pthread_attr_init(&detached_thread_attr); @@ -216,26 +213,18 @@ void notify_reinit_bar(void) /* Launch user defined command as a notification. */ unsigned notify_launch_cmd(void) { - int pid; + char const *arg[2] = { nbar.cmd, NULL }; + int pid, pin, pout, perr; if (notify_app.state & APOINT_NOTIFIED) return 1; notify_app.state |= APOINT_NOTIFIED; - pid = fork(); - - if (pid < 0) { - ERROR_MSG(_("error while launching command: could not fork")); - return 0; - } else if (pid == 0) { - /* Child: launch user defined command */ - if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < - 0) { - ERROR_MSG(_("error while launching command")); - _exit(1); - } - _exit(0); + if ((pid = shell_exec(&pin, &pout, &perr, *arg, arg))) { + close(pin); + close(pout); + close(perr); } return 1; |