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>
This commit is contained in:
Lukas Fleischer
2021-04-04 11:53:53 -04:00
parent 193ad3415a
commit 5398f3a24e
7 changed files with 19 additions and 12 deletions

View File

@@ -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);