hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit a99dbe17933f176b1b79f6a524179c249e80ec88
parent 22b7a5c0bfdfc43faaa93361addd80775f6ca985
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 22 Nov 2021 10:21:55 +0100

os::exec+freebsd: update platform_exec

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mos/exec/exec+freebsd.ha | 29+++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha @@ -81,8 +81,19 @@ fn platform_exec(cmd: *command) error = { envp = env: *[*]nullable *const char; }; + let need_devnull = false; for (let i = 0z; i < len(cmd.files); i += 1) { - cmd.files[i].0 = match (rt::fcntl(cmd.files[i].0, rt::F_DUPFD_CLOEXEC, 0)) { + const from = match (cmd.files[i].0) { + case file: io::file => + yield file; + case nullfd => + need_devnull = true; + continue; + case closefd => + continue; + }; + + cmd.files[i].0 = match (rt::fcntl(from, rt::F_DUPFD_CLOEXEC, 0)) { case fd: int => yield fd; case err: rt::errno => @@ -90,8 +101,22 @@ fn platform_exec(cmd: *command) error = { }; }; + const devnull: io::file = if (need_devnull) { + yield os::open("/dev/null")!; + } else -1; + for (let i = 0z; i < len(cmd.files); i += 1) { - match (rt::dup2(cmd.files[i].0, cmd.files[i].1)) { + const from = match (cmd.files[i].0) { + case file: io::file => + yield file; + case nullfd => + yield devnull; + case closefd => + io::close(cmd.files[i].1); + continue; + }; + + match (rt::dup2(from, cmd.files[i].1)) { case int => void; case e: rt::errno => return errors::errno(e);