Add a binding to pledge(2) to package 'unix'.
To use it:
- run ghc with -package unix
- import System.OpenBSD.Process ( pledge )
- call the pledge function as needed. It returns an IO () computation,
which will throw an exception in case of an error.
Notes:
- I'll also merge the -main and -doc subpackages, so no bump yet.
- The module System.OpenBSD.Process may end in its own package in the
future, but for now it's probably to put it into the unix package.
Comments (and tests) are welcome.
Ciao,
Kili
Index: files/Process.hsc
===================================================================
RCS file: files/Process.hsc
diff -N files/Process.hsc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ files/Process.hsc 19 Jan 2016 07:58:19 -0000
@@ -0,0 +1,29 @@
+{-# LANGUAGE Safe #-}
+
+module System.OpenBSD.Process ( pledge ) where
+
+import Foreign
+import Foreign.C
+import System.Posix.Internals ( withFilePath )
+
+pledge :: String -> [FilePath] -> IO ()
+
+pledge promises paths =
+ withCString promises $ \cproms ->
+ withPaths2Array0 paths $ \paths_arr ->
+ throwErrnoIfMinus1_ "pledge" (c_pledge cproms paths_arr)
+
+withPaths2Array0 :: [FilePath] -> (Ptr (Ptr CChar) -> IO a) -> IO a
+
+-- If paths is the empty list, just pass a nullPtr instead of an
+-- array containing only a nullPtr. This avoids EINVAL while the
+-- paths feature of pledge(2) is still disabled.
+withPaths2Array0 [] f = f nullPtr
+
+withPaths2Array0 paths f =
+ withMany withFilePath paths $ \cstrs ->
+ withArray0 nullPtr cstrs $ \paths_arr ->
+ f paths_arr
+
+foreign import ccall unsafe "unistd.h pledge"
+ c_pledge :: CString -> Ptr CString -> IO CInt
Index: patches/patch-libraries_unix_unix_cabal
===================================================================
RCS file: patches/patch-libraries_unix_unix_cabal
diff -N patches/patch-libraries_unix_unix_cabal
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libraries_unix_unix_cabal 19 Jan 2016 07:58:19 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- libraries/unix/unix.cabal.orig Sun Jan 4 23:56:26 2015
++++ libraries/unix/unix.cabal Tue Jan 19 00:42:33 2016
+@@ -109,6 +109,8 @@ library
+ System.Posix.Terminal
+ System.Posix.Terminal.ByteString
+
++ System.OpenBSD.Process
++
+ other-modules:
+ System.Posix.Directory.Common
+ System.Posix.DynamicLinker.Common