From 3cee18b208f1c8e3147b13148130ba12a7dcf6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Thu, 20 Feb 2014 14:04:58 +0100 Subject: Fall back to ioctl(TIOCNOTTY) to detach from the controlling terminal. * As with setpgid, only do this if setsid fails or is absent. --- configure.ac | 2 +- src/actions.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index cf84ef1..8e749b5 100644 --- a/configure.ac +++ b/configure.ac @@ -165,7 +165,7 @@ AS_IF([test "$with_electric_fence" = yes], dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([pwd.h]) +AC_CHECK_HEADERS([pwd.h sys/ioctl.h]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_TYPEOF diff --git a/src/actions.c b/src/actions.c index 79db068..8917b85 100644 --- a/src/actions.c +++ b/src/actions.c @@ -34,6 +34,10 @@ #ifdef HAVE_LIBXTST # include #endif + +#ifdef HAVE_SYS_IOCTL_H +# include +#endif #define ARG_STRING(elt) args[elt]->string @@ -2649,6 +2653,17 @@ spawn(char *cmd, int raw, rp_frame *frame) if (setsid() == -1) #endif { +#if defined (HAVE_SYS_IOCTL_H) && defined (TIOCNOTTY) + int ctty; + + ctty = open ("/dev/tty", O_RDONLY); + if (ctty != -1) + { + ioctl (ctty, TIOCNOTTY); + close (ctty); + } +#endif + #if defined (HAVE_SETPGID) setpgid (0, 0); #elif defined (HAVE_SETPGRP) -- cgit v1.2.3