setsid when running webapp in foreground too

This avoids ssh prompting for passwords on stdin, ever.

It may also change other behavior of other programs, as there is no
controlling terminal now. However, setsid was already done when running the
assistant in daemon mode, so any behavior changes should not be really new.
This commit is contained in:
Joey Hess 2014-05-14 14:26:28 -04:00
parent db8590791f
commit e391224516
2 changed files with 10 additions and 3 deletions

View file

@ -84,9 +84,7 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser =
fdToHandle =<< dup stdError fdToHandle =<< dup stdError
let undaemonize a = do let undaemonize a = do
debugM desc $ "logging to " ++ logfile debugM desc $ "logging to " ++ logfile
Utility.Daemon.lockPidFile pidfile Utility.Daemon.foreground logfd (Just pidfile) a
Utility.LogFile.redirLog logfd
a
start undaemonize $ start undaemonize $
case startbrowser of case startbrowser of
Nothing -> Nothing Nothing -> Nothing

View file

@ -56,6 +56,15 @@ daemonize logfd pidfile changedirectory a = do
out = exitImmediately ExitSuccess out = exitImmediately ExitSuccess
#endif #endif
{- To run an action that is normally daemonized in the forground. -}
foreground :: Fd -> Maybe FilePath -> IO () -> IO ()
foreground logfd pidfile a = do
maybe noop lockPidFile pidfile
_ <- createSession
redirLog logfd
a
exitImmediately ExitSuccess
{- Locks the pid file, with an exclusive, non-blocking lock, {- Locks the pid file, with an exclusive, non-blocking lock,
- and leaves it locked on return. - and leaves it locked on return.
- -