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);
|
int parse_datetime(const char *, time_t *, time_t);
|
||||||
void file_close(FILE *, const char *);
|
void file_close(FILE *, const char *);
|
||||||
void psleep(unsigned);
|
void psleep(unsigned);
|
||||||
int fork_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 *, const char *, const char *const *);
|
int shell_exec(int *, int *, int *, int, const char *, const char *const *);
|
||||||
int child_wait(int *, int *, int *, int);
|
int child_wait(int *, int *, int *, int);
|
||||||
void press_any_key(void);
|
void press_any_key(void);
|
||||||
void print_apoint(const char *, time_t, struct apoint *);
|
void print_apoint(const char *, time_t, struct apoint *);
|
||||||
|
@ -51,7 +51,7 @@ int run_hook(const char *name)
|
|||||||
arg[0] = hook_path;
|
arg[0] = hook_path;
|
||||||
arg[1] = NULL;
|
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);
|
ret = child_wait(&pin, &pout, &perr, pid);
|
||||||
if (ret > 0 && WIFEXITED(ret)) {
|
if (ret > 0 && WIFEXITED(ret)) {
|
||||||
asprintf(&mesg, "%s hook: exit status %d",
|
asprintf(&mesg, "%s hook: exit status %d",
|
||||||
|
@ -221,7 +221,7 @@ unsigned notify_launch_cmd(void)
|
|||||||
|
|
||||||
notify_app.state |= APOINT_NOTIFIED;
|
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(pin);
|
||||||
close(pout);
|
close(pout);
|
||||||
close(perr);
|
close(perr);
|
||||||
|
@ -1067,7 +1067,7 @@ void ui_day_item_pipe(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wins_prepare_external();
|
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");
|
fpout = fdopen(pout, "w");
|
||||||
|
|
||||||
switch (p->type) {
|
switch (p->type) {
|
||||||
|
@ -158,7 +158,7 @@ void ui_todo_pipe(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wins_prepare_external();
|
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");
|
fpout = fdopen(pout, "w");
|
||||||
todo_write(item, fpout);
|
todo_write(item, fpout);
|
||||||
fclose(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
|
* If pfdin/pfdout/pfderr point to a valid address, a pipe is created and the
|
||||||
* appropriate file descriptors are written to pfdin/pfdout/pfderr.
|
* 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,
|
int fork_exec(int *pfdin, int *pfdout, int *pfderr, int new_session,
|
||||||
const char *const *arg)
|
const char *path, const char *const *arg)
|
||||||
{
|
{
|
||||||
int pin[2], pout[2], perr[2];
|
int pin[2], pout[2], perr[2];
|
||||||
int pid;
|
int pid;
|
||||||
@ -1355,6 +1357,11 @@ int fork_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
|
|||||||
close(pin[1]);
|
close(pin[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (new_session) {
|
||||||
|
if ((setsid() < 0))
|
||||||
|
_exit(127);
|
||||||
|
}
|
||||||
|
|
||||||
execvp(path, (char *const *)arg);
|
execvp(path, (char *const *)arg);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
} else {
|
} else {
|
||||||
@ -1393,8 +1400,8 @@ int fork_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
|
|||||||
|
|
||||||
/* Execute an external program in a shell. */
|
/* Execute an external program in a shell. */
|
||||||
int
|
int
|
||||||
shell_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
|
shell_exec(int *pfdin, int *pfdout, int *pfderr, int new_session,
|
||||||
const char *const *arg)
|
const char *path, const char *const *arg)
|
||||||
{
|
{
|
||||||
int argc, i;
|
int argc, i;
|
||||||
const char **narg;
|
const char **narg;
|
||||||
@ -1423,7 +1430,7 @@ shell_exec(int *pfdin, int *pfdout, int *pfderr, const char *path,
|
|||||||
narg[3] = NULL;
|
narg[3] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = fork_exec(pfdin, pfdout, pfderr, *narg, narg);
|
ret = fork_exec(pfdin, pfdout, pfderr, new_session, *narg, narg);
|
||||||
|
|
||||||
if (arg0)
|
if (arg0)
|
||||||
mem_free(arg0);
|
mem_free(arg0);
|
||||||
|
@ -624,7 +624,7 @@ void wins_launch_external(const char *arg[])
|
|||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
wins_prepare_external();
|
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);
|
child_wait(NULL, NULL, NULL, pid);
|
||||||
wins_unprepare_external();
|
wins_unprepare_external();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user