···237237CAMLprim value eio_unix_fork_dups(value v_unit) {
238238 return Val_fork_fn(action_dups);
239239}
240240+241241+static void action_setpgid(int errors, value v_config) {
242242+ #ifdef _WIN32
243243+ eio_unix_fork_error(errors, "setpgid", "Unsupported operation on windows");
244244+ _exit(1);
245245+ #else
246246+ value vpid = Field(v_config, 1);
247247+ value vpgid = Field(v_config, 2);
248248+249249+ int r;
250250+ r = setpgid(Int_val(vpid), Int_val(vpgid));
251251+ if (r != 0) {
252252+ eio_unix_fork_error(errors, "setpgid", strerror(errno));
253253+ _exit(1);
254254+ }
255255+ #endif
256256+}
257257+258258+CAMLprim value eio_unix_fork_setpgid(value v_unit) {
259259+ return Val_fork_fn(action_setpgid);
260260+}
+6
lib_eio/unix/fork_action.ml
···6868 with_fds m @@ fun m ->
6969 let plan : action list = Inherit_fds.plan m in
7070 { run = fun k -> k (Obj.repr (action_dups, plan, blocking)) }
7171+7272+external action_setpgid : unit -> fork_fn = "eio_unix_fork_setpgid"
7373+let action_setpgid = action_setpgid ()
7474+7575+let setpgid pgid =
7676+ { run = fun k -> k (Obj.repr (action_setpgid, 0, pgid)) }
+6
lib_eio/unix/fork_action.mli
···5858 A mapping from an FD to itself simply clears the close-on-exec flag.
59596060 After this, the new FDs may also be set as blocking or non-blocking, depending on [flags]. *)
6161+6262+val setpgid : int -> t
6363+(** [setpgid pgid] sets the child's process group ID to [pgid].
6464+6565+ If [pgid] is [0] the child's process ID will be used as the PGID, placing
6666+ the child in a {e new} process group. *)
+4-2
lib_eio/unix/process.ml
···8383 t ->
8484 sw:Switch.t ->
8585 ?cwd:Eio.Fs.dir_ty Eio.Path.t ->
8686+ ?pgid:int ->
8687 env:string array ->
8788 fds:(int * Fd.t * Fork_action.blocking) list ->
8889 executable:string ->
···107108 t ->
108109 sw:Switch.t ->
109110 ?cwd:Eio.Fs.dir_ty Eio.Path.t ->
111111+ ?pgid:int ->
110112 env:string array ->
111113 fds:(int * Fd.t * Fork_action.blocking) list ->
112114 executable:string ->
···138140 let spawn_unix = X.spawn_unix
139141end
140142141141-let spawn_unix ~sw (Eio.Resource.T (v, ops)) ?cwd ~fds ?env ?executable args =
143143+let spawn_unix ~sw (Eio.Resource.T (v, ops)) ?cwd ?pgid ~fds ?env ?executable args =
142144 let module X = (val (Eio.Resource.get ops Pi.Mgr_unix)) in
143145 let executable = get_executable executable ~args in
144146 let env = get_env env in
145145- X.spawn_unix v ~sw ?cwd ~fds ~env ~executable args
147147+ X.spawn_unix v ~sw ?cwd ?pgid ~fds ~env ~executable args
146148147149let sigchld = Eio.Condition.create ()
148150