summaryrefslogtreecommitdiff
path: root/Utility/Daemon.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <id@joeyh.name>2013-05-11 15:03:00 -0500
committerGravatar Joey Hess <id@joeyh.name>2013-05-11 15:03:00 -0500
commitd0fa82fb721cdc85438287e29a94cb796b7bc464 (patch)
tree26a2486b8e715b5937ce41679eafd42c02f2310a /Utility/Daemon.hs
parent679eaf6077375c5d59501d12c79e0891cbdd904f (diff)
git-annex now builds on Windows (doesn't work)
Diffstat (limited to 'Utility/Daemon.hs')
-rwxr-xr-xUtility/Daemon.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/Utility/Daemon.hs b/Utility/Daemon.hs
index fb8c61f75..a01b078b8 100755
--- a/Utility/Daemon.hs
+++ b/Utility/Daemon.hs
@@ -12,9 +12,10 @@ module Utility.Daemon where
import Common
import Utility.LogFile
-#ifndef mingw32_HOST_OS
+#ifndef __WINDOWS__
import System.Posix
#endif
+import System.Posix.Types
{- Run an action as a daemon, with all output sent to a file descriptor.
-
@@ -23,6 +24,7 @@ import System.Posix
-
- When successful, does not return. -}
daemonize :: Fd -> Maybe FilePath -> Bool -> IO () -> IO ()
+#ifndef __WINDOWS__
daemonize logfd pidfile changedirectory a = do
maybe noop checkalreadyrunning pidfile
_ <- forkProcess child1
@@ -44,11 +46,15 @@ daemonize logfd pidfile changedirectory a = do
a
out
out = exitImmediately ExitSuccess
+#else
+daemonize = error "daemonize TODO"
+#endif
{- Locks the pid file, with an exclusive, non-blocking lock.
- Writes the pid to the file, fully atomically.
- Fails if the pid file is already locked by another process. -}
lockPidFile :: FilePath -> IO ()
+#ifndef __WINDOWS__
lockPidFile file = do
createDirectoryIfMissing True (parentDir file)
fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags
@@ -65,6 +71,9 @@ lockPidFile file = do
closeFd fd
where
newfile = file ++ ".new"
+#else
+lockPidFile = error "lockPidFile TODO"
+#endif
alreadyRunning :: IO ()
alreadyRunning = error "Daemon is already running."
@@ -74,6 +83,7 @@ alreadyRunning = error "Daemon is already running."
-
- If it's running, returns its pid. -}
checkDaemon :: FilePath -> IO (Maybe ProcessID)
+#ifndef __WINDOWS__
checkDaemon pidfile = do
v <- catchMaybeIO $
openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags
@@ -92,10 +102,17 @@ checkDaemon pidfile = do
"stale pid in " ++ pidfile ++
" (got " ++ show pid' ++
"; expected " ++ show pid ++ " )"
+#else
+checkDaemon = error "checkDaemon TODO"
+#endif
{- Stops the daemon, safely. -}
stopDaemon :: FilePath -> IO ()
+#ifndef __WINDOWS__
stopDaemon pidfile = go =<< checkDaemon pidfile
where
go Nothing = noop
go (Just pid) = signalProcess sigTERM pid
+#else
+stopDaemon = error "stopDaemon TODO"
+#endif