aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2021-04-04 11:53:53 -0400
committerLukas Fleischer <lfleischer@calcurse.org>2021-04-04 12:15:31 -0400
commit5398f3a24e988da4836f78fba62acf2ead1030b0 (patch)
treea580b9b1ad611eaab723c8b62172bbe801578a1a /src/utils.c
parent193ad3415a0e76bf046bfcc3f03dd65742f18589 (diff)
downloadcalcurse-5398f3a24e988da4836f78fba62acf2ead1030b0.tar.gz
calcurse-5398f3a24e988da4836f78fba62acf2ead1030b0.zip
Call setsid() for hook/notification commands
We do not want hook or notification commands to interact with the terminal in any way. Create a new session for them. Addresses GitHub issue #326. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c
index 146d733..1a480df 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1319,9 +1319,11 @@ void psleep(unsigned secs)
*
* If pfdin/pfdout/pfderr point to a valid address, a pipe is created and the
* appropriate file descriptors are written to pfdin/pfdout/pfderr.
+ *
+ * If new_session is non-zero, setsid() is called after forking.
*/
-int fork_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
- const char *const *arg)
+int fork_exec(int *pfdin, int *pfdout, int *pfderr, int new_session,
+ const char *path, const char *const *arg)
{
int pin[2], pout[2], perr[2];
int pid;
@@ -1355,6 +1357,11 @@ int fork_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
close(pin[1]);
}
+ if (new_session) {
+ if ((setsid() < 0))
+ _exit(127);
+ }
+
execvp(path, (char *const *)arg);
_exit(127);
} else {
@@ -1393,8 +1400,8 @@ int fork_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
/* Execute an external program in a shell. */
int
-shell_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
- const char *const *arg)
+shell_exec(int *pfdin, int *pfdout, int *pfderr, int new_session,
+ const char *path, const char *const *arg)
{
int argc, i;
const char **narg;
@@ -1423,7 +1430,7 @@ shell_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
narg[3] = NULL;
}
- ret = fork_exec(pfdin, pfdout, pfderr, *narg, narg);
+ ret = fork_exec(pfdin, pfdout, pfderr, new_session, *narg, narg);
if (arg0)
mem_free(arg0);