Hi, On Tue, Jan 19, 2016 at 09:29:58AM +0100, Sebastien Marie wrote: > Just a question, as I am unsure by just reading the code.
[...] > > +pledge :: String -> [FilePath] -> IO () > > Shouldn't be: > > pledge :: String -> Maybe [FilePath] -> IO () > > in order to differenciate passing not second argument, and an empty > array ? Yes. Thanks for pointing me to it. On Tue, Jan 19, 2016 at 08:24:06AM -0700, Aaron Bieber wrote: > > Comments (and tests) are welcome. > > I believe there is a patch missing to copy files/Process.hs into > libraries/unix/dist-install/build/System/OpenBSD/Process.hs Oops. Below is a hopefully correct and more complete diff. Again without bump because I'll also merge -main and -doc. I've loosely tested this with 1. pledge "stdio" Nothing 2. pledge "stdio" Nothing pledge "stdio dns" Nothing (which fails with EPERM) 3. pledge "stdio" (Just []) (fails with EINVAL) 4. pledge "stdio" (Just ["/tmp"]) (also fails with EINVAL) I also used ktrace to ensure that the correct system calls happen. Index: Makefile =================================================================== RCS file: /cvs/ports/lang/ghc/Makefile,v retrieving revision 1.131 diff -u -p -r1.131 Makefile --- Makefile 28 Dec 2015 19:18:52 -0000 1.131 +++ Makefile 19 Jan 2016 19:10:33 -0000 @@ -157,6 +157,11 @@ PORTHOME = ${WRKDIR} TEST_DEPENDS = print/ghostscript/gnu +post-extract: + cd ${WRKSRC}/libraries/unix && \ + mkdir -p System/OpenBSD && \ + install -m 644 ${FILESDIR}/Process.hsc System/OpenBSD + post-patch: # - Install a precompiled binary. cd ${WRKDIR}/ghc-${BIN_VER} && \ 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 19:10:33 -0000 @@ -0,0 +1,26 @@ +{-# LANGUAGE Safe #-} + +module System.OpenBSD.Process ( pledge ) where + +import Foreign +import Foreign.C +import System.Posix.Internals ( withFilePath ) + +pledge :: String -> Maybe [FilePath] -> IO () + +pledge promises paths = + withCString promises $ \cproms -> + withPaths2Array0 paths $ \paths_arr -> + throwErrnoIfMinus1_ "pledge" (c_pledge cproms paths_arr) + +withPaths2Array0 :: Maybe [FilePath] -> (Ptr (Ptr CChar) -> IO a) -> IO a + +withPaths2Array0 Nothing f = f nullPtr + +withPaths2Array0 (Just 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 19:10:33 -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