···374374 in
375375 loop saved_ctx job (pgid, some_read) rest
376376 | None -> (
377377- let exec_and_args =
378378- if is_command then begin
379379- match command_args with
380380- | [] -> assert false
381381- | x :: xs -> (
382382- Eunix.with_redirections rdrs @@ fun () ->
383383- match resolve_program ~update:false ctx x with
384384- | _, None -> Exit.nonzero ("", []) 1
385385- | _, Some prog ->
386386- if print_command then
387387- Exit.zero ("echo", [ prog ])
388388- else Exit.zero (x, xs))
389389- end
390390- else Exit.zero (executable, args_as_strings)
391391- in
392392- match exec_and_args with
393393- | Exit.Nonzero _ as v ->
394394- let job =
395395- handle_job ~pgid job (`Built_in (v >|= fun _ -> ()))
377377+ match Built_ins.of_args command_args with
378378+ | Some (Error _) ->
379379+ ( ctx,
380380+ handle_job ~pgid job (`Built_in (Exit.nonzero () 1))
381381+ )
382382+ | Some (Ok bi) ->
383383+ let ctx =
384384+ handle_built_in ~rdrs ~stdout:some_write ctx bi
385385+ in
386386+ close_stdout ~is_global some_write;
387387+ let built_in = ctx >|= fun _ -> () in
388388+ let job = handle_job ~pgid job (`Built_in built_in) in
389389+ loop (Exit.value ctx) job (pgid, some_read) rest
390390+ | _ -> (
391391+ let exec_and_args =
392392+ if is_command then begin
393393+ match command_args with
394394+ | [] -> assert false
395395+ | x :: xs -> (
396396+ Eunix.with_redirections rdrs @@ fun () ->
397397+ match resolve_program ~update:false ctx x with
398398+ | _, None -> Exit.nonzero ("", []) 1
399399+ | _, Some prog ->
400400+ if print_command then
401401+ Exit.zero ("echo", [ prog ])
402402+ else Exit.zero (x, xs))
403403+ end
404404+ else Exit.zero (executable, args_as_strings)
396405 in
397397- loop ctx job (pgid, some_read) rest
398398- | Exit.Zero (executable, args) -> (
399399- match stdout_of_previous with
400400- | None ->
401401- let ctx, job =
402402- exec_process ctx job ~fds:rdrs
403403- ~stdout:some_write ~pgid executable args
406406+ match exec_and_args with
407407+ | Exit.Nonzero _ as v ->
408408+ let job =
409409+ handle_job ~pgid job
410410+ (`Built_in (v >|= fun _ -> ()))
404411 in
405405- close_stdout ~is_global some_write;
406412 loop ctx job (pgid, some_read) rest
407407- | Some stdout ->
408408- let ctx, job =
409409- exec_process ctx job ~fds:rdrs ~stdin:stdout
410410- ~stdout:some_write ~pgid executable
411411- args_as_strings
412412- in
413413- close_stdout ~is_global some_write;
414414- loop ctx job (pgid, some_read) rest))))
413413+ | Exit.Zero (executable, args) -> (
414414+ match stdout_of_previous with
415415+ | None ->
416416+ let ctx, job =
417417+ exec_process ctx job ~fds:rdrs
418418+ ~stdout:some_write ~pgid executable args
419419+ in
420420+ close_stdout ~is_global some_write;
421421+ loop ctx job (pgid, some_read) rest
422422+ | Some stdout ->
423423+ let ctx, job =
424424+ exec_process ctx job ~fds:rdrs ~stdin:stdout
425425+ ~stdout:some_write ~pgid executable
426426+ args_as_strings
427427+ in
428428+ close_stdout ~is_global some_write;
429429+ loop ctx job (pgid, some_read) rest)))))
415430 | Some (Ok bi) ->
416431 let ctx = handle_built_in ~rdrs ~stdout:some_write ctx bi in
417432 close_stdout ~is_global some_write;
+4
test/built_ins.t
···184184 $ msh -c "command -v skjdlksjdlkwjdlkw"
185185 [1]
186186187187+Command should also still allow shell built-ins to run.
188188+189189+ $ msh -c "command pwd | xargs -- basename"
190190+1871918. Alias
188192189193This is mostly handled by Morbig, but we have had to do some fixes...