process 1.3.0.0 → 1.4.0.0
raw patch · 6 files changed
+70/−9 lines, 6 filesdep ~base
Dependency ranges changed: base
Files
- System/Process.hsc +9/−4
- System/Process/Internals.hs +28/−2
- cbits/runProcess.c +24/−0
- changelog.md +5/−1
- include/runProcess.h +2/−0
- process.cabal +2/−2
System/Process.hsc view
@@ -126,7 +126,9 @@ delegate_ctlc = False, detach_console = False, create_new_console = False,- new_session = False }+ new_session = False,+ child_group = Nothing,+ child_user = Nothing } -- | Construct a 'CreateProcess' record for passing to 'createProcess', -- representing a command to be passed to the shell.@@ -142,7 +144,9 @@ delegate_ctlc = False, detach_console = False, create_new_console = False,- new_session = False }+ new_session = False,+ child_group = Nothing,+ child_user = Nothing } {- | This is the most general way to spawn an external process. The@@ -298,7 +302,7 @@ -- exit code, an exception is raised. -- -- If an asynchronous exception is thrown to the thread executing--- @callProcess@. The forked process will be terminated and+-- @callProcess@, the forked process will be terminated and -- @callProcess@ will wait (block) until the process has been -- terminated. --@@ -316,7 +320,7 @@ -- command returns a non-zero exit code, an exception is raised. -- -- If an asynchronous exception is thrown to the thread executing--- @callCommand@. The forked process will be terminated and+-- @callCommand@, the forked process will be terminated and -- @callCommand@ will wait (block) until the process has been -- terminated. --@@ -430,6 +434,7 @@ -- -- Note that @Handle@s provided for @std_in@ or @std_out@ via the CreateProcess -- record will be ignored.+-- -- @since 1.2.3.0 readCreateProcess
System/Process/Internals.hs view
@@ -59,6 +59,8 @@ import System.IO import System.Posix.Process.Internals ( pPrPr_disableITimers, c_execvpe ) import System.Posix.Types+#else+import Data.Word (Word32) #endif #ifdef __GLASGOW_HASKELL__@@ -99,6 +101,13 @@ # endif #endif +#if defined(mingw32_HOST_OS) || defined(__MINGW32__)+-- Define some missing types for Windows compatibility+newtype CGid = CGid Word32+type GroupID = CGid+type UserID = CGid+#endif+ -- ---------------------------------------------------------------------------- -- ProcessHandle type @@ -190,9 +199,19 @@ -- Default: @False@ -- -- @since 1.3.0.0- new_session :: Bool -- ^ Use posix setsid to start the new process in a new session; does nothing on other platforms.+ new_session :: Bool, -- ^ Use posix setsid to start the new process in a new session; does nothing on other platforms. -- -- @since 1.3.0.0+ child_group :: Maybe GroupID, -- ^ Use posix setgid to set child process's group id; does nothing on other platforms.+ --+ -- Default: @Nothing@+ --+ -- @since 1.4.0.0+ child_user :: Maybe UserID -- ^ Use posix setuid to set child process's user id; does nothing on other platforms.+ --+ -- Default: @Nothing@+ --+ -- @since 1.4.0.0 } data CmdSpec@@ -273,7 +292,9 @@ delegate_ctlc = mb_delegate_ctlc, detach_console = mb_detach_console, create_new_console = mb_create_new_console,- new_session = mb_new_session }+ new_session = mb_new_session,+ child_group = mb_child_group,+ child_user = mb_child_user } = do let (cmd,args) = commandToProcess cmdsp withFilePathException cmd $@@ -283,6 +304,8 @@ alloca $ \ pFailedDoing -> maybeWith withCEnvironment mb_env $ \pEnv -> maybeWith withFilePath mb_cwd $ \pWorkDir ->+ maybeWith with mb_child_group $ \pChildGroup ->+ maybeWith with mb_child_user $ \pChildUser -> withMany withFilePath (cmd:args) $ \cstrs -> withArray0 nullPtr cstrs $ \pargs -> do @@ -301,6 +324,7 @@ c_runInteractiveProcess pargs pWorkDir pEnv fdin fdout fderr pfdStdInput pfdStdOutput pfdStdError+ pChildGroup pChildUser (if mb_delegate_ctlc then 1 else 0) ((if mb_close_fds then RUN_PROCESS_IN_CLOSE_FDS else 0) .|.(if mb_create_group then RUN_PROCESS_IN_NEW_GROUP else 0)@@ -414,6 +438,8 @@ -> Ptr FD -> Ptr FD -> Ptr FD+ -> Ptr CGid+ -> Ptr CUid -> CInt -- reset child's SIGINT & SIGQUIT handlers -> CInt -- flags -> Ptr CString
cbits/runProcess.c view
@@ -40,6 +40,10 @@ #define forkChdirFailed 126 #define forkExecFailed 127 +// These are arbitrarily chosen -- JP+#define forkSetgidFailed 124+#define forkSetuidFailed 125+ __attribute__((__noreturn__)) static void childFailed(int pipe, int failCode) { int err;@@ -57,6 +61,7 @@ char *workingDirectory, char **environment, int fdStdIn, int fdStdOut, int fdStdErr, int *pfdStdInput, int *pfdStdOutput, int *pfdStdError,+ gid_t *childGroup, uid_t *childUser, int reset_int_quit_handlers, int flags, char **failed_doing)@@ -144,7 +149,21 @@ if ((flags & RUN_PROCESS_IN_NEW_GROUP) != 0) { setpgid(0, 0); }+ + if ( childGroup) {+ if ( setgid( *childGroup) != 0) {+ // ERROR+ childFailed(forkCommunicationFds[1], forkSetgidFailed);+ }+ } + if ( childUser) {+ if ( setuid( *childUser) != 0) {+ // ERROR+ childFailed(forkCommunicationFds[1], forkSetuidFailed);+ }+ }+ unblockUserSignals(); if (workingDirectory) {@@ -281,6 +300,11 @@ case forkExecFailed: *failed_doing = "runInteractiveProcess: exec"; break;+ case forkSetgidFailed:+ *failed_doing = "runInteractiveProcess: setgid";+ break;+ case forkSetuidFailed:+ *failed_doing = "runInteractiveProcess: setuid"; default: *failed_doing = "runInteractiveProcess: unknown"; break;
changelog.md view
@@ -1,6 +1,10 @@ # Changelog for [`process` package](http://hackage.haskell.org/package/process) -## 1.3.0.0 (unreleased)+## 1.4.0.0 *November 2015*++* Added `child_user` and `child_group` to `CreateProcess` for unix. [#45](https://github.com/haskell/process/pull/45)++## 1.3.0.0 *August 2015* * Add `StdStream(NoStream)` to have standard handles closed. [#13](https://github.com/haskell/process/pull/13) * Support for Windows `DETACHED_PROCESS` and `setsid` [#32](https://github.com/haskell/process/issues/32)
include/runProcess.h view
@@ -62,6 +62,8 @@ int *pfdStdInput, int *pfdStdOutput, int *pfdStdError,+ gid_t *childGroup,+ uid_t *childUser, int reset_int_quit_handlers, int flags, char **failed_doing);
process.cabal view
@@ -1,5 +1,5 @@ name: process-version: 1.3.0.0+version: 1.4.0.0 -- NOTE: Don't forget to update ./changelog.md license: BSD3 license-file: LICENSE@@ -59,7 +59,7 @@ ghc-options: -Wall - build-depends: base >= 4.4 && < 4.9,+ build-depends: base >= 4.4 && < 4.10, directory >= 1.1 && < 1.3, filepath >= 1.2 && < 1.5, deepseq >= 1.1 && < 1.5