The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add process groups to unix backends

Co-authored-by: Thomas Leonard <talex5@gmail.com>

authored by

Patrick Ferris
Thomas Leonard
and committed by
Thomas Leonard
f6dac4a8 62b9714f

+50 -4
+21
lib_eio/unix/fork_action.c
··· 237 237 CAMLprim value eio_unix_fork_dups(value v_unit) { 238 238 return Val_fork_fn(action_dups); 239 239 } 240 + 241 + static void action_setpgid(int errors, value v_config) { 242 + #ifdef _WIN32 243 + eio_unix_fork_error(errors, "setpgid", "Unsupported operation on windows"); 244 + _exit(1); 245 + #else 246 + value vpid = Field(v_config, 1); 247 + value vpgid = Field(v_config, 2); 248 + 249 + int r; 250 + r = setpgid(Int_val(vpid), Int_val(vpgid)); 251 + if (r != 0) { 252 + eio_unix_fork_error(errors, "setpgid", strerror(errno)); 253 + _exit(1); 254 + } 255 + #endif 256 + } 257 + 258 + CAMLprim value eio_unix_fork_setpgid(value v_unit) { 259 + return Val_fork_fn(action_setpgid); 260 + }
+6
lib_eio/unix/fork_action.ml
··· 68 68 with_fds m @@ fun m -> 69 69 let plan : action list = Inherit_fds.plan m in 70 70 { run = fun k -> k (Obj.repr (action_dups, plan, blocking)) } 71 + 72 + external action_setpgid : unit -> fork_fn = "eio_unix_fork_setpgid" 73 + let action_setpgid = action_setpgid () 74 + 75 + let setpgid pgid = 76 + { run = fun k -> k (Obj.repr (action_setpgid, 0, pgid)) }
+6
lib_eio/unix/fork_action.mli
··· 58 58 A mapping from an FD to itself simply clears the close-on-exec flag. 59 59 60 60 After this, the new FDs may also be set as blocking or non-blocking, depending on [flags]. *) 61 + 62 + val setpgid : int -> t 63 + (** [setpgid pgid] sets the child's process group ID to [pgid]. 64 + 65 + If [pgid] is [0] the child's process ID will be used as the PGID, placing 66 + the child in a {e new} process group. *)
+4 -2
lib_eio/unix/process.ml
··· 83 83 t -> 84 84 sw:Switch.t -> 85 85 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 86 + ?pgid:int -> 86 87 env:string array -> 87 88 fds:(int * Fd.t * Fork_action.blocking) list -> 88 89 executable:string -> ··· 107 108 t -> 108 109 sw:Switch.t -> 109 110 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 111 + ?pgid:int -> 110 112 env:string array -> 111 113 fds:(int * Fd.t * Fork_action.blocking) list -> 112 114 executable:string -> ··· 138 140 let spawn_unix = X.spawn_unix 139 141 end 140 142 141 - let spawn_unix ~sw (Eio.Resource.T (v, ops)) ?cwd ~fds ?env ?executable args = 143 + let spawn_unix ~sw (Eio.Resource.T (v, ops)) ?cwd ?pgid ~fds ?env ?executable args = 142 144 let module X = (val (Eio.Resource.get ops Pi.Mgr_unix)) in 143 145 let executable = get_executable executable ~args in 144 146 let env = get_env env in 145 - X.spawn_unix v ~sw ?cwd ~fds ~env ~executable args 147 + X.spawn_unix v ~sw ?cwd ?pgid ~fds ~env ~executable args 146 148 147 149 let sigchld = Eio.Condition.create () 148 150
+3
lib_eio/unix/process.mli
··· 20 20 t -> 21 21 sw:Switch.t -> 22 22 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 23 + ?pgid:int -> 23 24 env:string array -> 24 25 fds:(int * Fd.t * Fork_action.blocking) list -> 25 26 executable:string -> ··· 42 43 t -> 43 44 sw:Switch.t -> 44 45 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 46 + ?pgid:int -> 45 47 env:string array -> 46 48 fds:(int * Fd.t * Fork_action.blocking) list -> 47 49 executable:string -> ··· 53 55 sw:Switch.t -> 54 56 _ mgr -> 55 57 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 58 + ?pgid:int -> 56 59 fds:(int * Fd.t * Fork_action.blocking) list -> 57 60 ?env:string array -> 58 61 ?executable:string ->
+5 -1
lib_eio_linux/eio_linux.ml
··· 219 219 module T = struct 220 220 type t = unit 221 221 222 - let spawn_unix () ~sw ?cwd ~env ~fds ~executable args = 222 + let spawn_unix () ~sw ?cwd ?pgid ~env ~fds ~executable args = 223 223 let actions = Low_level.Process.Fork_action.[ 224 224 Eio_unix.Private.Fork_action.inherit_fds fds; 225 225 execve executable ~argv:(Array.of_list args) ~env 226 226 ] in 227 + let actions = match pgid with 228 + | None -> actions 229 + | Some pgid -> Eio_unix.Private.Fork_action.setpgid pgid :: actions 230 + in 227 231 let with_actions cwd fn = match cwd with 228 232 | None -> fn actions 229 233 | Some (fd, s) ->
+5 -1
lib_eio_posix/process.ml
··· 23 23 module T = struct 24 24 type t = unit 25 25 26 - let spawn_unix () ~sw ?cwd ~env ~fds ~executable args = 26 + let spawn_unix () ~sw ?cwd ?pgid ~env ~fds ~executable args = 27 27 let actions = Low_level.Process.Fork_action.[ 28 28 inherit_fds fds; 29 29 execve executable ~argv:(Array.of_list args) ~env 30 30 ] in 31 + let actions = match pgid with 32 + | None -> actions 33 + | Some pgid -> Low_level.Process.Fork_action.setpgid pgid :: actions 34 + in 31 35 let with_actions cwd fn = match cwd with 32 36 | None -> fn actions 33 37 | Some ((dir, path) : Eio.Fs.dir_ty Eio.Path.t) ->