diff options
| -rw-r--r-- | core/net/socket_linux.odin | 6 | ||||
| -rw-r--r-- | core/os/os2/file.odin | 12 | ||||
| -rw-r--r-- | core/os/os2/file_linux.odin | 4 | ||||
| -rw-r--r-- | core/os/os2/file_windows.odin | 2 |
4 files changed, 16 insertions, 8 deletions
diff --git a/core/net/socket_linux.odin b/core/net/socket_linux.odin index a5d553234..350d3947c 100644 --- a/core/net/socket_linux.odin +++ b/core/net/socket_linux.odin @@ -117,7 +117,7 @@ _wrap_os_addr :: proc "contextless" (addr: linux.Sock_Addr_Any)->(Endpoint) { _create_socket :: proc(family: Address_Family, protocol: Socket_Protocol) -> (Any_Socket, Network_Error) { family := _unwrap_os_family(family) proto, socktype := _unwrap_os_proto_socktype(protocol) - sock, errno := linux.socket(family, socktype, {}, proto) + sock, errno := linux.socket(family, socktype, {.CLOEXEC}, proto) if errno != .NONE { return {}, Create_Socket_Error(errno) } @@ -132,7 +132,7 @@ _dial_tcp_from_endpoint :: proc(endpoint: Endpoint, options := default_tcp_optio } // Create new TCP socket os_sock: linux.Fd - os_sock, errno = linux.socket(_unwrap_os_family(family_from_endpoint(endpoint)), .STREAM, {}, .TCP) + os_sock, errno = linux.socket(_unwrap_os_family(family_from_endpoint(endpoint)), .STREAM, {.CLOEXEC}, .TCP) if errno != .NONE { // TODO(flysand): should return invalid file descriptor here casted as TCP_Socket return {}, Create_Socket_Error(errno) @@ -172,7 +172,7 @@ _listen_tcp :: proc(endpoint: Endpoint, backlog := 1000) -> (TCP_Socket, Network ep_address := _unwrap_os_addr(endpoint) // Create TCP socket os_sock: linux.Fd - os_sock, errno = linux.socket(ep_family, .STREAM, {}, .TCP) + os_sock, errno = linux.socket(ep_family, .STREAM, {.CLOEXEC}, .TCP) if errno != .NONE { // TODO(flysand): should return invalid file descriptor here casted as TCP_Socket return {}, Create_Socket_Error(errno) diff --git a/core/os/os2/file.odin b/core/os/os2/file.odin index be03155ff..978e64fb4 100644 --- a/core/os/os2/file.odin +++ b/core/os/os2/file.odin @@ -29,7 +29,7 @@ File_Flag :: enum { Sync, Trunc, Sparse, - Close_On_Exec, + Inheritable, Unbuffered_IO, } @@ -43,7 +43,15 @@ O_EXCL :: File_Flags{.Excl} O_SYNC :: File_Flags{.Sync} O_TRUNC :: File_Flags{.Trunc} O_SPARSE :: File_Flags{.Sparse} -O_CLOEXEC :: File_Flags{.Close_On_Exec} + +/* + If specified, the file handle is inherited upon the creation of a child + process. By default all handles are created non-inheritable. + + **Note**: The standard file handles (stderr, stdout and stdin) are always + initialized as inheritable. +*/ +O_INHERITABLE :: File_Flags{.Inheritable} stdin: ^File = nil // OS-Specific stdout: ^File = nil // OS-Specific diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin index 482c9b5b4..7828e5fd9 100644 --- a/core/os/os2/file_linux.odin +++ b/core/os/os2/file_linux.odin @@ -70,7 +70,7 @@ _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (f: ^File, er // Just default to using O_NOCTTY because needing to open a controlling // terminal would be incredibly rare. This has no effect on files while // allowing us to open serial devices. - sys_flags: linux.Open_Flags = {.NOCTTY} + sys_flags: linux.Open_Flags = {.NOCTTY, .CLOEXEC} switch flags & O_RDONLY|O_WRONLY|O_RDWR { case O_RDONLY: case O_WRONLY: sys_flags += {.WRONLY} @@ -82,7 +82,7 @@ _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (f: ^File, er if .Excl in flags { sys_flags += {.EXCL} } if .Sync in flags { sys_flags += {.DSYNC} } if .Trunc in flags { sys_flags += {.TRUNC} } - if .Close_On_Exec in flags { sys_flags += {.CLOEXEC} } + if .Inheritable in flags { sys_flags -= {.CLOEXEC} } fd, errno := linux.open(name_cstr, sys_flags, transmute(linux.Mode)(u32(perm))) if errno != .NONE { diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index b11e7745f..5ce081e3a 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -79,7 +79,7 @@ _open_internal :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (han share_mode := u32(win32.FILE_SHARE_READ | win32.FILE_SHARE_WRITE) sa := win32.SECURITY_ATTRIBUTES { nLength = size_of(win32.SECURITY_ATTRIBUTES), - bInheritHandle = .Close_On_Exec not_in flags, + bInheritHandle = .Inheritable in flags, } create_mode: u32 = win32.OPEN_EXISTING |