Shells in OCaml
3
fork

Configure Feed

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

Tcsetpgrp for interactive stdin

+22 -3
+12
src/lib/eunix.ml
··· 18 18 Fmt.str "%s@%s" name host 19 19 20 20 external tcsetpgrp : int -> int -> int = "caml_merry_tcsetpgrp" 21 + 22 + let delegate_control ~pgid fn = 23 + let shell_pid = Unix.getpid () in 24 + Fun.protect 25 + ~finally:(fun () -> 26 + let _ : int = tcsetpgrp 0 shell_pid in 27 + ()) 28 + (fun () -> 29 + match tcsetpgrp (Obj.magic Unix.stdin : int) pgid with 30 + | 0 -> fn () 31 + | n -> Fmt.failwith "tcsetpgrp: %i" n) 32 + 21 33 external setpgrp : int -> int -> int = "caml_merry_setpgid" 22 34 23 35 let make_process_group () = match setpgrp 0 0 with 0 -> () | n -> exit n
+2 -1
src/lib/eval.ml
··· 437 437 | None -> Exit.zero ctx 438 438 | Some job -> 439 439 if not async then begin 440 - J.await_exit ~pipefail:false job >|= fun () -> ctx 440 + J.await_exit ~pipefail:false ~interactive:ctx.interactive job 441 + >|= fun () -> ctx 441 442 end 442 443 else begin 443 444 Exit.zero { ctx with background_jobs = job :: ctx.background_jobs }
+3
src/lib/interactive.ml
··· 30 30 Format.flush_str_formatter () 31 31 32 32 let run ?(prompt = default_prompt) initial_ctx = 33 + Sys.set_signal Sys.sigttou Sys.Signal_ignore; 34 + Sys.set_signal Sys.sigttin Sys.Signal_ignore; 35 + Sys.set_signal Sys.sigtstp Sys.Signal_ignore; 33 36 let rec loop (ctx : Eval.ctx Exit.t) = 34 37 Option.iter (Fmt.epr "%s%!") 35 38 (S.lookup (Exit.value ctx).state ~param:"PS1"
+5 -2
src/lib/job.ml
··· 21 21 let add_error b t = { t with processes = Nlist.cons (`Error b) t.processes } 22 22 23 23 (* Section 2.9.2 https://pubs.opengroup.org/onlinepubs/9799919799/ *) 24 - let await_exit ~pipefail t = 24 + let await_exit ~pipefail ~interactive t = 25 25 let await = function 26 - | `Process p -> E.await p 26 + | `Process p -> 27 + if interactive then 28 + Eunix.delegate_control ~pgid:t.id @@ fun () -> E.await p 29 + else E.await p 27 30 | `Built_in b -> b 28 31 | `Error n -> Exit.nonzero () n 29 32 in