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:
parent
193ad3415a
commit
5398f3a24e
@ -1250,8 +1250,8 @@ int parse_date_increment(const char *, unsigned *, time_t);
|
||||
int parse_datetime(const char *, time_t *, time_t);
|
||||
void file_close(FILE *, const char *);
|
||||
void psleep(unsigned);
|
||||
int fork_exec(int *, int *, int *, const char *, const char *const *);
|
||||
int shell_exec(int *, int *, int *, const char *, const char *const *);
|
||||
int fork_exec(int *, int *, int *, int, const char *, const char *const *);
|
||||
int shell_exec(int *, int *, int *, int, const char *, const char *const *);
|
||||
int child_wait(int *, int *, int *, int);
|
||||
void press_any_key(void);
|
||||
void print_apoint(const char *, time_t, struct apoint *);
|
||||
|
@ -51,7 +51,7 @@ int run_hook(const char *name)
|
||||
arg[0] = hook_path;
|
||||
arg[1] = NULL;
|
||||
|
||||
if ((pid = shell_exec(&pin, &pout, &perr, *arg, arg))) {
|
||||
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",
|
||||
|
@ -221,7 +221,7 @@ unsigned notify_launch_cmd(void)
|
||||
|
||||
notify_app.state |= APOINT_NOTIFIED;
|
||||
|
||||
if ((pid = shell_exec(&pin, &pout, &perr, *arg, arg))) {
|
||||
if ((pid = shell_exec(&pin, &pout, &perr, 1, *arg, arg))) {
|
||||
close(pin);
|
||||
close(pout);
|
||||
close(perr);
|
||||
|
@ -1067,7 +1067,7 @@ void ui_day_item_pipe(void)
|
||||
return;
|
||||
|
||||
wins_prepare_external();
|
||||
if ((pid = shell_exec(NULL, &pout, NULL, *arg, arg))) {
|
||||
if ((pid = shell_exec(NULL, &pout, NULL, 0, *arg, arg))) {
|
||||
fpout = fdopen(pout, "w");
|
||||
|
||||
switch (p->type) {
|
||||
|
@ -158,7 +158,7 @@ void ui_todo_pipe(void)
|
||||
return;
|
||||
|
||||
wins_prepare_external();
|
||||
if ((pid = shell_exec(NULL, &pout, NULL, *arg, arg))) {
|
||||
if ((pid = shell_exec(NULL, &pout, NULL, 0, *arg, arg))) {
|
||||
fpout = fdopen(pout, "w");
|
||||
todo_write(item, fpout);
|
||||
fclose(fpout);
|
||||
|
17
src/utils.c
17
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);
|
||||
|
@ -624,7 +624,7 @@ void wins_launch_external(const char *arg[])
|
||||
int pid;
|
||||
|
||||
wins_prepare_external();
|
||||
if ((pid = shell_exec(NULL, NULL, NULL, *arg, arg)))
|
||||
if ((pid = shell_exec(NULL, NULL, NULL, 0, *arg, arg)))
|
||||
child_wait(NULL, NULL, NULL, pid);
|
||||
wins_unprepare_external();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user