hare

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

commit ebb81682f2a1aff982b85ce66279967f0ed1fd6e
parent 87fd0f4fcbc3bd7738bb327f7667a91f5ed53ce4
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  8 Feb 2021 14:16:09 -0500

os::exec: set CLOEXEC on the pipe flags

Diffstat:
Mos/exec/+linux.ha | 2+-
Mos/exec/cmd.ha | 5++++-
Mrt/+linux/types.ha | 2++
3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/os/exec/+linux.ha b/os/exec/+linux.ha @@ -57,7 +57,7 @@ fn platform_exec(cmd: *command) os_error = { fn platform_start(cmd: *command) (os_error | void) = { // TODO: Let the user configure clone more to their taste (e.g. SIGCHLD) let pipe: [2]int = [0...]; - match (rt::pipe2(&pipe, 0)) { + match (rt::pipe2(&pipe, rt::O_CLOEXEC)) { err: rt::errno => return errno_to_os(err), void => void, }; diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha @@ -65,7 +65,10 @@ export fn finish(cmd: *command) void = { // Executes a prepared command in the current address space, overwriting the // running process with the new command. -export fn exec(cmd: *command) os_error = platform_exec(cmd); +export fn exec(cmd: *command) error = { + defer finish(cmd); // Note: doesn't happen if exec succeeds + return platform_exec(cmd); +}; // Starts a prepared command in a new process. export fn start(cmd: *command) (error | void) = { diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -33,6 +33,8 @@ export def AT_RECURSIVE: int = 0x8000; export def O_RDONLY: int = 0; export def O_WRONLY: int = 1; export def O_RDWR: int = 2; +// TODO: Add the other flags: +export def O_CLOEXEC: int = 0o2000000; type statx_timestamp = struct { tv_sec: i64,