X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FUnix.hs;fp=src%2FUnix.hs;h=9b0ddaac9d3bbc10dc532b87c233378be2dd19cb;hb=2a3c20fe95f2b695547bf0e14246e6c05e36f360;hp=a4389bee0e844ea7cd7024d608e3e126033bc926;hpb=431c2a85ca0fc6be25d6ef35447c6f4ccf54b34c;p=dead%2Fhtsn.git diff --git a/src/Unix.hs b/src/Unix.hs index a4389be..9b0ddaa 100644 --- a/src/Unix.hs +++ b/src/Unix.hs @@ -19,6 +19,7 @@ import System.Posix ( getUserEntryForName, installHandler, removeLink, + setFileCreationMask, setGroupID, setUserID, sigTERM ) @@ -62,14 +63,23 @@ graceful_shutdown cfg main_thread_id = do -- 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