skeleton C library for calling kqueue
This commit is contained in:
parent
0ecc7dc892
commit
3c8a9043b6
6 changed files with 75 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,7 +11,7 @@ html
|
||||||
*.tix
|
*.tix
|
||||||
.hpc
|
.hpc
|
||||||
Utility/Touch.hs
|
Utility/Touch.hs
|
||||||
Utility/libdiskfree.o
|
Utility/*.o
|
||||||
dist
|
dist
|
||||||
# Sandboxed builds
|
# Sandboxed builds
|
||||||
cabal-dev
|
cabal-dev
|
||||||
|
|
|
@ -33,12 +33,15 @@ import qualified Data.ByteString.Lazy as L
|
||||||
import Utility.Inotify
|
import Utility.Inotify
|
||||||
import System.INotify
|
import System.INotify
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WITH_KQUEUE
|
||||||
|
import Utility.Kqueue
|
||||||
|
#endif
|
||||||
|
|
||||||
type Handler = FilePath -> Maybe FileStatus -> DaemonStatusHandle -> Annex (Maybe Change)
|
type Handler = FilePath -> Maybe FileStatus -> DaemonStatusHandle -> Annex (Maybe Change)
|
||||||
|
|
||||||
checkCanWatch :: Annex ()
|
checkCanWatch :: Annex ()
|
||||||
checkCanWatch = do
|
checkCanWatch = do
|
||||||
#ifdef WITH_INOTIFY
|
#if (WITH_INOTIFY || WITH_KQUEUE)
|
||||||
unlessM (liftIO (inPath "lsof") <||> Annex.getState Annex.force) $
|
unlessM (liftIO (inPath "lsof") <||> Annex.getState Annex.force) $
|
||||||
needLsof
|
needLsof
|
||||||
#else
|
#else
|
||||||
|
@ -82,8 +85,13 @@ watchThread st dstatus changechan = withINotify $ \i -> do
|
||||||
, errHook = hook onErr
|
, errHook = hook onErr
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#ifdef WITH_KQUEUE
|
||||||
|
watchThread st dstatus changechan = do
|
||||||
|
print =<< waitChange [stdError, stdOutput]
|
||||||
|
#else
|
||||||
watchThread = undefined
|
watchThread = undefined
|
||||||
#endif
|
#endif /* WITH_KQUEUE */
|
||||||
|
#endif /* WITH_INOTIFY */
|
||||||
|
|
||||||
ignored :: FilePath -> Bool
|
ignored :: FilePath -> Bool
|
||||||
ignored ".git" = True
|
ignored ".git" = True
|
||||||
|
|
18
Makefile
18
Makefile
|
@ -1,13 +1,22 @@
|
||||||
OS:=$(shell uname | sed 's/[-_].*//')
|
bins=git-annex
|
||||||
|
mans=git-annex.1 git-annex-shell.1
|
||||||
|
sources=Build/SysConfig.hs Utility/Touch.hs
|
||||||
|
all=$(bins) $(mans) docs
|
||||||
|
|
||||||
|
OS:=$(shell uname | sed 's/[-_].*//')
|
||||||
ifeq ($(OS),Linux)
|
ifeq ($(OS),Linux)
|
||||||
BASEFLAGS_OPTS+=-DWITH_INOTIFY
|
BASEFLAGS_OPTS+=-DWITH_INOTIFY
|
||||||
|
clibs=Utility/libdiskfree.o
|
||||||
|
else
|
||||||
|
BASEFLAGS_OPTS+=-DWITH_KQUEUE
|
||||||
|
clibs=Utility/libdiskfree.o Utility/libkqueue.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
PREFIX=/usr
|
PREFIX=/usr
|
||||||
IGNORE=-ignore-package monads-fd -ignore-package monads-tf
|
IGNORE=-ignore-package monads-fd -ignore-package monads-tf
|
||||||
BASEFLAGS=-Wall $(IGNORE) -outputdir tmp -IUtility -DWITH_S3 $(BASEFLAGS_OPTS)
|
BASEFLAGS=-Wall $(IGNORE) -outputdir tmp -IUtility -DWITH_S3 $(BASEFLAGS_OPTS)
|
||||||
GHCFLAGS=-O2 $(BASEFLAGS)
|
GHCFLAGS=-O2 $(BASEFLAGS)
|
||||||
|
CFLAGS=-Wall
|
||||||
|
|
||||||
ifdef PROFILE
|
ifdef PROFILE
|
||||||
GHCFLAGS=-prof -auto-all -rtsopts -caf-all -fforce-recomp $(BASEFLAGS)
|
GHCFLAGS=-prof -auto-all -rtsopts -caf-all -fforce-recomp $(BASEFLAGS)
|
||||||
|
@ -15,13 +24,6 @@ endif
|
||||||
|
|
||||||
GHCMAKE=ghc $(GHCFLAGS) --make
|
GHCMAKE=ghc $(GHCFLAGS) --make
|
||||||
|
|
||||||
bins=git-annex
|
|
||||||
mans=git-annex.1 git-annex-shell.1
|
|
||||||
sources=Build/SysConfig.hs Utility/Touch.hs
|
|
||||||
clibs=Utility/libdiskfree.o
|
|
||||||
|
|
||||||
all=$(bins) $(mans) docs
|
|
||||||
|
|
||||||
# Am I typing :make in vim? Do a fast build.
|
# Am I typing :make in vim? Do a fast build.
|
||||||
ifdef VIM
|
ifdef VIM
|
||||||
all=fast
|
all=fast
|
||||||
|
|
31
Utility/Kqueue.hs
Normal file
31
Utility/Kqueue.hs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
{- BSD kqueue file modification notification interface
|
||||||
|
-
|
||||||
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||||
|
-
|
||||||
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||||
|
|
||||||
|
module Utility.Kqueue ( waitChange ) where
|
||||||
|
|
||||||
|
import Common
|
||||||
|
|
||||||
|
import System.Posix.Types
|
||||||
|
import Foreign.C.Types
|
||||||
|
import Foreign.C.Error
|
||||||
|
import Foreign.Ptr
|
||||||
|
import Foreign.Marshal
|
||||||
|
|
||||||
|
foreign import ccall unsafe "libkqueue.h waitchange" c_waitchange
|
||||||
|
:: Ptr Fd -> IO Fd
|
||||||
|
|
||||||
|
waitChange :: [Fd] -> IO (Maybe Fd)
|
||||||
|
waitChange fds = withArray fds $ \c_fds -> do
|
||||||
|
ret <- c_waitchange c_fds
|
||||||
|
ifM (safeErrno <$> getErrno)
|
||||||
|
( return $ Just ret
|
||||||
|
, return Nothing
|
||||||
|
)
|
||||||
|
where
|
||||||
|
safeErrno (Errno v) = v == 0
|
22
Utility/libkqueue.c
Normal file
22
Utility/libkqueue.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* kqueue interface, C mini-library
|
||||||
|
*
|
||||||
|
* Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||||
|
*
|
||||||
|
* Licensed under the GNU GPL version 3 or higher.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Waits for a change event on one of the array of directory fds,
|
||||||
|
* and returns the one that changed. */
|
||||||
|
int waitchange(const int *fds) {
|
||||||
|
// if (kqueue(blah, &fds) != 0)
|
||||||
|
// return 0; /* errno is set */
|
||||||
|
// else
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
printf("in waitchange!, %i %i\n", fds[0], fds[1]);
|
||||||
|
|
||||||
|
return fds[0];
|
||||||
|
}
|
1
Utility/libkqueue.h
Normal file
1
Utility/libkqueue.h
Normal file
|
@ -0,0 +1 @@
|
||||||
|
int waitchange(const int *fds);
|
Loading…
Reference in a new issue