aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
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);