Something went wrong. Try again.
Shells in OCaml
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727open Import
module Make (Fd : Types.Fd) (S : Types.State) = struct type fd = Fd.t type state = S.t type 'a trace = ?trace:bool -> 'a
type ctx = { interactive : bool; toplevel : bool; subshell : bool; state : state; local_state : (string * Ast.fragments) list Stack.t; fd_table : Fd_table.t; options : Options.t; last_background_process : string; last_pipeline_status : int option; exit_handler : Ast.complete_commands option; program : string; argv : string array; functions : (string * Ast.compound_command) list; hash : Hash.t; rdrs : fd Types.redirect list; quotes : [ `None | `Single | `Double ]; umask : int; current_pipeline : string option; current_context : [ `Toplevel | `Function | `CompoundCommand ]; command : Ast.complete_commands; (* Non-shell evaluation state *) commit : bool; trace : Trace.t; diff : Diff.t; build : Zfs_store.Build.t; overlays : Zfs_store.Build.t list; mode : Void.mode; } (** A shell context. *)
let mode r = r.mode let overlays r = r.overlays let build r = r.build let diff r = r.diff let trace r = r.trace let commit r = r.commit let command r = r.command let current_context r = r.current_context let current_pipeline r = r.current_pipeline let umask r = r.umask let quotes r = r.quotes let rdrs r = r.rdrs let hash r = r.hash let functions r = r.functions let argv r = r.argv let program r = r.program let exit_handler r = r.exit_handler let last_pipeline_status r = r.last_pipeline_status let last_background_process r = r.last_background_process let options r = r.options let fd_table r = r.fd_table let local_state r = r.local_state let state r = r.state let subshell r = r.subshell let toplevel r = r.toplevel let interactive r = r.interactive
let make ~interactive ~toplevel ~subshell ~state ~local_state ~fd_table ~options ~last_background_process ~last_pipeline_status ~exit_handler ~program ~argv ~functions ~hash ~rdrs ~quotes ~umask ~current_pipeline ~current_context ~command ~commit ~trace ~diff ~build ~overlays ~mode = { interactive; toplevel; subshell; state; local_state; fd_table; options; last_background_process; last_pipeline_status; exit_handler; program; argv; functions; hash; rdrs; quotes; umask; current_pipeline; current_context; command; commit; trace; diff; build; overlays; mode; }
let with_ctx ?interactive:interactive_v ?toplevel:toplevel_v ?subshell:subshell_v ?state:state_v ?local_state:local_state_v ?fd_table:fd_table_v ?options:options_v ?last_background_process:last_background_process_v ?last_pipeline_status:last_pipeline_status_v ?exit_handler:exit_handler_v ?program:program_v ?argv:argv_v ?functions:functions_v ?hash:hash_v ?rdrs:rdrs_v ?quotes:quotes_v ?umask:umask_v ?current_pipeline:current_pipeline_v ?current_context:current_context_v ?command:command_v ?commit:commit_v ?trace:trace_v ?diff:diff_v ?build:build_v ?overlays:overlays_v ?mode:mode_v v = { interactive = Option.value interactive_v ~default:v.interactive; toplevel = Option.value toplevel_v ~default:v.toplevel; subshell = Option.value subshell_v ~default:v.subshell; state = Option.value state_v ~default:v.state; local_state = Option.value local_state_v ~default:v.local_state; fd_table = Option.value fd_table_v ~default:v.fd_table; options = Option.value options_v ~default:v.options; last_background_process = Option.value last_background_process_v ~default:v.last_background_process; last_pipeline_status = Option.value last_pipeline_status_v ~default:v.last_pipeline_status; exit_handler = Option.value exit_handler_v ~default:v.exit_handler; program = Option.value program_v ~default:v.program; argv = Option.value argv_v ~default:v.argv; functions = Option.value functions_v ~default:v.functions; hash = Option.value hash_v ~default:v.hash; rdrs = Option.value rdrs_v ~default:v.rdrs; quotes = Option.value quotes_v ~default:v.quotes; umask = Option.value umask_v ~default:v.umask; current_pipeline = Option.value current_pipeline_v ~default:v.current_pipeline; current_context = Option.value current_context_v ~default:v.current_context; command = Option.value command_v ~default:v.command; commit = Option.value commit_v ~default:v.commit; trace = Option.value trace_v ~default:v.trace; diff = Option.value diff_v ~default:v.diff; build = Option.value build_v ~default:v.build; overlays = Option.value overlays_v ~default:v.overlays; mode = Option.value mode_v ~default:v.mode; }
let default_trace = true
let add_trace ~trace e ctx = if trace then with_ctx ~trace:(e :: ctx.trace) ctx else ctx
let find_function ?(trace = default_trace) ~name ctx = let e = Trace.make_entry ~arg:name Fn Read in let ctx = add_trace ~trace e ctx in let opt = List.assoc_opt ~compare:String.compare name ctx.functions in (opt, ctx)
let add_function ?(trace = default_trace) ~name cc ctx = let e = Trace.make_entry ~arg:name Fn Write in let ctx = add_trace ~trace e ctx in let functions = (name, cc) :: ctx.functions in let ctx = { ctx with functions } in ctx
let get_option ?(trace = default_trace) opt ctx = let e = Trace.make_entry ~arg:(Options.posix_to_letter opt) Opt Read in let ctx = add_trace ~trace e ctx in let opt = Options.get opt ctx.options in (opt, ctx)
let set_option ?(trace = default_trace) opt b ctx = let e = Trace.make_entry ~arg:(Options.posix_to_letter opt) Opt Write in let ctx = add_trace ~trace e ctx in let options = Options.set opt b ctx.options in let ctx = { ctx with options } in ctx
(* This function exists to be able to obtain a stable hash for the same commands that may differ in their post execution fields. *) let set_for_hash t = { t with trace = Trace.empty; diff = []; current_pipeline = None; last_pipeline_status = None; fd_table = Fd_table.empty; hash = Hash.empty; rdrs = []; }
type t = ctx list
let equal_ctx t1 t2 = S.equal t1.state t2.state && Stdlib.( = ) { t1 with state = S.empty } { t2 with state = S.empty }
let equal t1 t2 = List.equal equal_ctx t1 t2
let fd_jsont = Jsont.map Jsont.int ~enc:Fd.to_int ~dec:(function | 0 -> Fd.stdin | 1 -> Fd.stdout | 2 -> Fd.stderr | fd -> Fmt.invalid_arg "Trying to deserialise FD: %i" fd)
let void_mode_jsont = Jsont.enum ~doc:"Void mode" [ ("R", Void.R); ("RW", Void.RW) ]
let ctx_jsont = let make interactive toplevel subshell state local_state fd_table options last_background_process last_pipeline_status exit_handler program argv functions hash rdrs quotes umask current_pipeline current_context commit trace diff build overlays mode command = { interactive; toplevel; subshell; state; local_state; fd_table; options; last_background_process; last_pipeline_status; exit_handler; program; argv; functions; hash; rdrs; quotes; umask; current_pipeline; current_context; commit; trace; diff; build; overlays; mode; command; } in Jsont.Object.map ~kind:"Context" make |> Jsont.Object.mem "interactive" Jsont.bool ~enc:(fun t -> t.interactive) |> Jsont.Object.mem "toplevel" Jsont.bool ~enc:(fun t -> t.toplevel) |> Jsont.Object.mem "subshell" Jsont.bool ~enc:(fun t -> t.subshell) |> Jsont.Object.mem "state" S.jsont ~enc:(fun t -> t.state) |> Jsont.Object.mem "local_state" (Stack.jsont (Jsont.list (let get_or_raise = function | Ok r -> r | Error err -> raise (Jsont.Error err) in let enc f acc (e0, e1) = let e0 = Jsont.Json.encode' Jsont.string e0 |> get_or_raise in let e1 = Jsont.Json.encode' Ast.fragments_jsont e1 |> get_or_raise in [ (0, e0); (1, e1) ] |> Stdlib.List.fold_left (fun acc (i, e) -> f acc i e) acc in let dec_empty () = (None, None) in let dec_add i elt (e0, e1) = match i with | 0 -> let e = Jsont.Json.decode' Jsont.string elt |> get_or_raise in (Some e, e1) | 1 -> let e = Jsont.Json.decode' Ast.fragments_jsont elt |> get_or_raise in (e0, Some e) | _ -> Jsont.Error.msgf Jsont.Meta.none "Too many elements for tuple." in let dec_finish meta _ (e0, e1) = let get_or_raise i o = match o with | Some v -> v | None -> Jsont.Error.msgf meta "Missing tuple member #%i" i in (get_or_raise 0 e0, get_or_raise 1 e1) in Jsont.Array.map ~enc:{ enc } ~dec_empty ~dec_add ~dec_finish Jsont.json |> Jsont.Array.array))) ~enc:(fun t -> t.local_state) |> Jsont.Object.mem "fd_table" Fd_table.jsont ~enc:(fun t -> t.fd_table) |> Jsont.Object.mem "options" Options.jsont ~enc:(fun t -> t.options) |> Jsont.Object.mem "last_background_process" Jsont.string ~enc:(fun t -> t.last_background_process) |> Jsont.Object.mem "last_pipeline_status" (Jsont.option Jsont.int) ~enc:(fun t -> t.last_pipeline_status) |> Jsont.Object.mem "exit_handler" (Jsont.option (Jsont.list Ast.complete_command_jsont)) ~enc:(fun t -> t.exit_handler) |> Jsont.Object.mem "program" Jsont.string ~enc:(fun t -> t.program) |> Jsont.Object.mem "argv" (Jsont.array Jsont.string) ~enc:(fun t -> t.argv) |> Jsont.Object.mem "functions" (Jsont.list (let get_or_raise = function | Ok r -> r | Error err -> raise (Jsont.Error err) in let enc f acc (e0, e1) = let e0 = Jsont.Json.encode' Jsont.string e0 |> get_or_raise in let e1 = Jsont.Json.encode' Ast.compound_command_jsont e1 |> get_or_raise in [ (0, e0); (1, e1) ] |> Stdlib.List.fold_left (fun acc (i, e) -> f acc i e) acc in let dec_empty () = (None, None) in let dec_add i elt (e0, e1) = match i with | 0 -> let e = Jsont.Json.decode' Jsont.string elt |> get_or_raise in (Some e, e1) | 1 -> let e = Jsont.Json.decode' Ast.compound_command_jsont elt |> get_or_raise in (e0, Some e) | _ -> Jsont.Error.msgf Jsont.Meta.none "Too many elements for tuple." in let dec_finish meta _ (e0, e1) = let get_or_raise i o = match o with | Some v -> v | None -> Jsont.Error.msgf meta "Missing tuple member #%i" i in (get_or_raise 0 e0, get_or_raise 1 e1) in Jsont.Array.map ~enc:{ enc } ~dec_empty ~dec_add ~dec_finish Jsont.json |> Jsont.Array.array)) ~enc:(fun t -> t.functions) |> Jsont.Object.mem "hash" Hash.jsont ~enc:(fun t -> t.hash) |> Jsont.Object.mem "rdrs" (Jsont.list (Types.redirect_jsont fd_jsont)) ~enc:(fun t -> t.rdrs) |> Jsont.Object.mem "quotes" (Jsont.enum ~kind:"variant" [ ("None", `None); ("Single", `Single); ("Double", `Double) ]) ~enc:(fun t -> t.quotes) |> Jsont.Object.mem "umask" Jsont.int ~enc:(fun t -> t.umask) |> Jsont.Object.mem "current_pipeline" (Jsont.option Jsont.string) ~enc:(fun t -> t.current_pipeline) |> Jsont.Object.mem "current_context" (Jsont.enum ~kind:"variant" [ ("Toplevel", `Toplevel); ("Function", `Function); ("CompoundCommand", `CompoundCommand); ]) ~enc:(fun t -> t.current_context) |> Jsont.Object.mem "commit" Jsont.bool ~enc:(fun t -> t.commit) |> Jsont.Object.mem "trace" Trace.jsont ~enc:(fun t -> t.trace) |> Jsont.Object.mem "diff" Diff.jsont ~enc:(fun t -> t.diff) |> Jsont.Object.mem "build" Zfs_store.Build.jsont ~enc:(fun t -> t.build) |> Jsont.Object.mem "overlays" (Jsont.list Zfs_store.Build.jsont) ~enc:(fun t -> t.overlays) |> Jsont.Object.mem "mode" void_mode_jsont ~enc:(fun t -> t.mode) |> Jsont.Object.mem "command" (Jsont.list Ast.complete_command_jsont) ~enc:(fun t -> t.command) |> Jsont.Object.finish
let jsont = Jsont.list ctx_jsont let ctx_t = repr_of_jsont ctx_jsont let t = repr_of_jsont jsont
module Files = Set.Make (String)
let conflicts ~kind lca ~other ~ours = let shared_cmds = Option.map List.length lca |> Option.value ~default:0 in (* First we check for a merge conflict: does t1 read anything that t2 might have written to! *) let our_writes = List.concat_map (fun e -> Trace.writes ~kind e.trace) ours |> Files.of_list in (* Drop the shared commands out of t1's history. *) let other_rest = List.rev other |> List.filteri (fun i _ -> i >= shared_cmds) |> List.rev in let other_reads = List.concat_map (fun e -> Trace.reads ~kind e.trace) other_rest |> Files.of_list in let overlap = Files.inter our_writes other_reads in overlap
let rw_inconsistency conflicting = let s = Fmt.str "read-write inconsistency: %a consider using %@ replay <br> instead." Fmt.(braces (list ~sep:Fmt.comma string)) (Files.to_list conflicting) in Fmt.epr "%a\n%!" Fmt.(styled (`Fg `Red) string) s; Irmin.Merge.conflict "read-write inconsistency"
let merge_function ~old other ours = (* By the design of the merge function these three histories will have a subset of commands that are the same ([old]) and all of the new commands are what is left *) match old () with | Error _ as e -> e | Ok old -> ( let conflicting_files, conflict_env_vars = ( conflicts ~kind:Trace.is_open old ~other ~ours, conflicts ~kind:Trace.is_env old ~other ~ours ) in match (Files.is_empty conflicting_files, Files.is_empty conflict_env_vars) with | false, _ -> rw_inconsistency conflicting_files | _, false -> rw_inconsistency conflict_env_vars | true, true -> let our_latest = List.hd ours in let other_latest = List.hd other in let shared_cmds = Option.map List.length old |> Option.value ~default:0 in let other_rest = List.rev other |> List.filteri (fun i _ -> i >= shared_cmds) |> List.rev in let open Result.Syntax in let old_latest = Option.map List.hd old in let olden f = Option.map f old_latest |> Irmin.Merge.promise in let* state = Irmin.Merge.(f S.merge) ~old:(olden (fun o -> o.state)) (Some other_latest.state) (Some our_latest.state) in let overlays = other_latest.build :: other_latest.overlays in let new_t1_latest = { our_latest with overlays = overlays @ our_latest.overlays; state = Option.get state; } in let merged = (new_t1_latest :: other_rest) @ ours in Ok merged)
let merge = Irmin.Merge.option @@ Irmin.Merge.v t merge_function
let dump ppf t = Jsont.pp_json ppf (Jsont.Json.encode jsont t |> Result.get_ok')
module Fork = struct (* For tracing and namespacing, we actually do have to fork the shell. *) type 'a t = { res : ('a, string) result }
let t (f : 'a Jsont.t) : 'a t Jsont.t = let ok_obj = Jsont.Object.map ~kind:"Fork-ok" (fun x -> x) |> Jsont.Object.mem "v" f ~enc:(fun x -> x) |> Jsont.Object.finish in let err_obj = Jsont.Object.map ~kind:"Fork-error" (fun x -> x) |> Jsont.Object.mem "v" Jsont.string ~enc:(fun x -> x) |> Jsont.Object.finish in let ok_case = Jsont.Object.Case.map "Ok" ok_obj ~dec:Result.ok in let err_case = Jsont.Object.Case.map "Error" err_obj ~dec:Result.error in let enc_case = function | Ok c -> Jsont.Object.Case.value ok_case c | Error r -> Jsont.Object.Case.value err_case r in let cases = Jsont.Object.Case.[ make ok_case; make err_case ] in let make r = { res = r } in
(* Assemble the parent record object *) Jsont.Object.map ~kind:"Fork" make |> Jsont.Object.case_mem "res" Jsont.string ~enc:(fun x -> x.res) ~enc_case cases |> Jsont.Object.finish
let write_all fd s = let len = Bytes.length s in let rec loop written = if written = len then () else let v = Unix.write fd s 0 (len - written) in loop (written + v) in loop 0
let read_all fd = let buf = Buffer.create 16 in let bs = Bytes.create 1024 in let rec loop n = Debug.Log.info (fun f -> f "Loop %i" n); match Unix.read fd bs 0 1024 with | 0 | (exception End_of_file) -> Buffer.contents buf | n -> Buffer.add_bytes buf (Bytes.sub bs 0 n); loop n in let r = loop 0 in Unix.close fd; Debug.Log.info (fun f -> f "Got %s" r); r
let make_waiter () = let r, w = Unix.pipe ~cloexec:false () in let go () = assert (Unix.write_substring w "1" 0 1 = 1); Unix.close w in let wait () = let bs = Bytes.create 1 in assert (Unix.read r bs 0 1 = 1); Unix.close r in (go, wait)
let to_other_sinks_as_well ~others (Eio.Resource.T (t, handler) : Eio.Flow.sink_ty Eio.Flow.sink) = let module Sink = (val Eio.Resource.get handler Eio.Flow.Pi.Sink) in let buf = Cstruct.create 4096 in let copy () ~src = try while true do match Eio.Flow.single_read src buf with | i -> let bufs = [ Cstruct.sub buf 0 i ] in Eio.Fiber.both (fun () -> Eio.Fiber.List.iter (fun other -> Eio.Flow.write other bufs) others) (fun () -> Sink.copy ~src:(Eio.Flow.cstruct_source bufs) t) done with | End_of_file | Eio.Io (Eio.Exn.X (Eio_unix.Unix_error (Unix.EIO, _, _)), _) -> () in let single_write () x = Eio.Fiber.List.iter (fun other -> let _ : int = Eio.Flow.single_write other x in ()) others; Sink.single_write t x in let module T = struct type t = unit
let single_write = single_write let copy = copy end in Eio.Resource.T ((), Eio.Flow.Pi.sink (module T))
let tracing_process args = let r, w = Unix.pipe ~cloexec:false () in let pid = Unix.create_process "bpftrace" args Unix.stdin w dev_null in Unix.close w; ((fun () -> read_all r), pid)
let spawn ~log ~stdout ~cwd ~fs ?(actions = []) (fn : (ctx Exit.t -> unit) -> Types.env -> ctx Exit.t) = let run () = Eio.Switch.run @@ fun sw -> let log = (log :> Eio.Flow.sink_ty Eio.Flow.sink) in let stdout = (stdout :> Eio.Flow.sink_ty Eio.Flow.sink) in let go, wait = make_waiter () in let read_ctx, write_ctx = Unix.pipe ~cloexec:false () in let codec = t (Exit.jsont ctx_jsont) in let log_pty = Eio_unix.Pty.open_pty ~sw () in let log_r = Eio_unix.Pty.source log_pty in let log_w = Eio_unix.Pty.tty log_pty in let copy_stdout = to_other_sinks_as_well ~others:[ log; stdout ] (Eio_unix.Pty.sink log_pty :> Eio.Flow.sink_ty Eio.Flow.sink) in let rdrs = [ (0, log_w, `Blocking); (1, log_w, `Blocking); (2, log_w, `Blocking); ] in let actions = actions @ [ Eio_unix.Private.Fork_action.setpgid 0; Eio_unix.Private.Fork_action.inherit_fds rdrs; ] in Eio.Fiber.fork ~sw (fun () -> Eio.Flow.copy log_r copy_stdout); match Void.Private.(fork_actions actions) with | 0, _ -> ( (* CHILD *) wait (); Eio_posix.run @@ fun env -> (* Re-establish cwd *) Unix.chdir cwd; let internal_exit_handler v = let t = { res = Ok v } in match Jsont_bytesrw.encode_string codec t with | Error _ -> assert false | Ok v -> write_all write_ctx (Bytes.of_string v); Unix.close write_ctx in let v = try Ok (fn internal_exit_handler (env :> Types.env)) with exn -> Error (Printexc.to_string exn) in let t = { res = v } in match Jsont_bytesrw.encode_string codec t with | Error exn -> Fmt.epr "Error: %s" exn; Fmt.failwith "Failed to encode string" | Ok v -> write_all write_ctx (Bytes.of_string v); Unix.close write_ctx; exit 0) | pid, _pid_fd -> ( (* PARENT *) Eio_unix.Fd.close log_w; Unix.close write_ctx; let cgroup = Eio.Path.load Eio.Path.(fs / Fmt.str "/proc/%i/cgroup" pid) |> Astring.String.cut ~sep:"::" |> function | Some (_, path) -> String.trim path | None -> Fmt.failwith "Failed to find cgroup for %i" pid in let read_trace, trace_pid = tracing_process [| "bpftrace"; "-B"; "none"; "-e"; {|tracepoint:syscalls:sys_enter_open / cgroup == |} ^ Fmt.str "cgroupid(\"/sys/fs/cgroup/%s\")" cgroup ^ {|/ { printf("open,%s,%s,0x%x\n", str(args->filename), comm, args->flags); } |} ^ {|tracepoint:syscalls:sys_enter_openat / cgroup == |} ^ Fmt.str "cgroupid(\"/sys/fs/cgroup/%s\")" cgroup ^ {|/ { printf("openat,%s,%s,0x%x\n", str(args->filename), comm, args->flags); } |} ^ {|tracepoint:syscalls:sys_enter_openat2 / cgroup == |} ^ Fmt.str "cgroupid(\"/sys/fs/cgroup/%s\")" cgroup ^ {|/ { printf("openat2,%s,%s,0x%x\n", str(args->filename), comm, args.how->flags); } |}; |] in (* Let the trace establish itself. *) Unix.sleepf 0.2; go (); Debug.Log.info (fun f -> f "Parent waiting for %i" pid); match Unix.waitpid [] pid with | _, Unix.WEXITED 0 -> ( let () = Unix.kill trace_pid 9 in let trace = read_trace () |> Trace.of_bpftrace in Debug.Log.info (fun f -> f "Done waiting for %i : %a" pid Trace.pp trace); let res_raw = read_all read_ctx in Debug.Log.info (fun f -> f "Read ctx back for %i" pid); let res = Jsont_bytesrw.decode_string codec res_raw in match res with | Ok v -> Result.map (fun f -> (f, trace)) v.res | Error _ as e -> e) | _, Unix.WEXITED _ -> ( let () = Unix.kill trace_pid 9 in let trace = read_trace () |> Trace.of_bpftrace in let res_raw = read_all read_ctx in let res = Jsont_bytesrw.decode_string codec res_raw in match res with | Ok v -> Result.map (fun f -> (f, trace)) v.res | Error _ as e -> e) | _, _ -> Unix.kill trace_pid 9; Fmt.failwith "TODO: failed") in let v = run () in Debug.Log.info (fun f -> f "spawn complete"); v end
let default_ctx = { interactive = false; toplevel = true; subshell = false; state = S.empty; local_state = Stack.empty; fd_table = Fd_table.empty; options = Options.default; last_background_process = ""; last_pipeline_status = None; exit_handler = None; program = "msh"; argv = [||]; functions = []; hash = Hash.empty; rdrs = []; quotes = `None; umask = 0; current_pipeline = None; current_context = `Toplevel; command = Ast.of_string "echo hello"; (* Non-shell evaluation state *) commit = true; trace = Trace.empty; diff = []; build = Zfs_store.Build.Image "alpine"; overlays = []; mode = Void.RW; }end