else do
send_cred h (password cfg)
_ <- recv_line h -- "The Sports Network"
+ report_info $ "Logged in as " ++ (username cfg) ++ "."
return ()
where
username_prompt = "Username: "
getUserEntryForName,
installHandler,
removeLink,
+ setFileCreationMask,
setGroupID,
setUserID,
sigTERM )
-- finally do the daemonization dance.
--
full_daemonize :: Configuration -> IO () -> IO ()
-full_daemonize cfg program =
+full_daemonize cfg program = do
+ -- The call to 'daemonize' will set the umask to zero, but we want
+ -- to retain it. So, we set the umask to zero before 'daemonize'
+ -- can, so that we can record the previous umask value (returned by
+ -- setFileCreationMask).
+ orig_umask <- setFileCreationMask 0
-- This is the 'daemonize' from System.Posix.Daemonize.
- daemonize program'
+ daemonize (program' orig_umask)
where
-- We need to do all this stuff *after* we daemonize.
- program' = do
+ program' orig_umask = do
-- First write the PID file which probably requires root.
pid <- getProcessID
+
+ -- The PID file needs to be read-only for anyone but its
+ -- owner. Hopefully the umask accomplishes this!
+ _ <- setFileCreationMask orig_umask
writeFile (pidfile cfg) (show pid)
-- We need to pass the thread ID to the signal handler so it