mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
close null_handle
This commit is contained in:
@@ -264,8 +264,10 @@ specific process, even after it has died.
|
|||||||
**Note(linux)**: The `handle` will be referring to pidfd.
|
**Note(linux)**: The `handle` will be referring to pidfd.
|
||||||
*/
|
*/
|
||||||
Process :: struct {
|
Process :: struct {
|
||||||
pid: int,
|
pid: int,
|
||||||
handle: uintptr,
|
handle: uintptr,
|
||||||
|
// Implementation specific state/data.
|
||||||
|
_impl: _Process,
|
||||||
}
|
}
|
||||||
|
|
||||||
Process_Open_Flags :: bit_set[Process_Open_Flag]
|
Process_Open_Flags :: bit_set[Process_Open_Flag]
|
||||||
@@ -290,21 +292,10 @@ process_open :: proc(pid: int, flags := Process_Open_Flags {}) -> (Process, Erro
|
|||||||
return _process_open(pid, flags)
|
return _process_open(pid, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
OS-specific process attributes.
|
|
||||||
*/
|
|
||||||
Process_Attributes :: struct {
|
|
||||||
sys_attr: _Sys_Process_Attributes,
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The description of how a process should be created.
|
The description of how a process should be created.
|
||||||
*/
|
*/
|
||||||
Process_Desc :: struct {
|
Process_Desc :: struct {
|
||||||
// OS-specific attributes.
|
|
||||||
sys_attr: Process_Attributes,
|
|
||||||
|
|
||||||
// The working directory of the process. If the string has length 0, the
|
// The working directory of the process. If the string has length 0, the
|
||||||
// working directory is assumed to be the current working directory of the
|
// working directory is assumed to be the current working directory of the
|
||||||
// current process.
|
// current process.
|
||||||
|
|||||||
@@ -362,6 +362,9 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
|||||||
return _process_info_by_pid(get_pid(), selection, allocator)
|
return _process_info_by_pid(get_pid(), selection, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(private="package")
|
||||||
|
_Process :: struct {}
|
||||||
|
|
||||||
@(private="package")
|
@(private="package")
|
||||||
_process_open :: proc(pid: int, _: Process_Open_Flags) -> (process: Process, err: Error) {
|
_process_open :: proc(pid: int, _: Process_Open_Flags) -> (process: Process, err: Error) {
|
||||||
process.pid = pid
|
process.pid = pid
|
||||||
@@ -378,9 +381,6 @@ _process_open :: proc(pid: int, _: Process_Open_Flags) -> (process: Process, err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private="package")
|
|
||||||
_Sys_Process_Attributes :: struct {}
|
|
||||||
|
|
||||||
@(private="package")
|
@(private="package")
|
||||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD()
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
|||||||
return _process_info_by_pid(_get_pid(), selection, allocator)
|
return _process_info_by_pid(_get_pid(), selection, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
_Sys_Process_Attributes :: struct {}
|
_Process :: struct {}
|
||||||
|
|
||||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||||
if len(desc.command) == 0 {
|
if len(desc.command) == 0 {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_Sys_Process_Attributes :: struct {}
|
_Process :: struct {}
|
||||||
|
|
||||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||||
err = .Unsupported
|
err = .Unsupported
|
||||||
|
|||||||
@@ -418,7 +418,9 @@ _process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(private="package")
|
@(private="package")
|
||||||
_Sys_Process_Attributes :: struct {}
|
_Process :: struct {
|
||||||
|
null_handle: win32.HANDLE,
|
||||||
|
}
|
||||||
|
|
||||||
@(private="package")
|
@(private="package")
|
||||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||||
@@ -436,9 +438,8 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|||||||
stdout_handle: win32.HANDLE
|
stdout_handle: win32.HANDLE
|
||||||
stdin_handle: win32.HANDLE
|
stdin_handle: win32.HANDLE
|
||||||
|
|
||||||
null_handle: win32.HANDLE
|
|
||||||
if desc.stdout == nil || desc.stderr == nil || desc.stdin == nil {
|
if desc.stdout == nil || desc.stderr == nil || desc.stdin == nil {
|
||||||
null_handle := win32.CreateFileW(
|
process._impl.null_handle = win32.CreateFileW(
|
||||||
win32.L("NUL"),
|
win32.L("NUL"),
|
||||||
win32.GENERIC_READ|win32.GENERIC_WRITE,
|
win32.GENERIC_READ|win32.GENERIC_WRITE,
|
||||||
win32.FILE_SHARE_READ|win32.FILE_SHARE_WRITE,
|
win32.FILE_SHARE_READ|win32.FILE_SHARE_WRITE,
|
||||||
@@ -450,23 +451,23 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|||||||
win32.FILE_ATTRIBUTE_NORMAL,
|
win32.FILE_ATTRIBUTE_NORMAL,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
assert(null_handle != nil)
|
assert(process._impl.null_handle != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if desc.stdout == nil {
|
if desc.stdout == nil {
|
||||||
stdout_handle = null_handle
|
stdout_handle = process._impl.null_handle
|
||||||
} else {
|
} else {
|
||||||
stdout_handle = win32.HANDLE((^File_Impl)(desc.stdout.impl).fd)
|
stdout_handle = win32.HANDLE((^File_Impl)(desc.stdout.impl).fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if desc.stderr == nil {
|
if desc.stderr == nil {
|
||||||
stderr_handle = null_handle
|
stderr_handle = process._impl.null_handle
|
||||||
} else {
|
} else {
|
||||||
stderr_handle = win32.HANDLE((^File_Impl)(desc.stderr.impl).fd)
|
stderr_handle = win32.HANDLE((^File_Impl)(desc.stderr.impl).fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if desc.stdin == nil {
|
if desc.stdin == nil {
|
||||||
stdin_handle = null_handle
|
stdin_handle = process._impl.null_handle
|
||||||
} else {
|
} else {
|
||||||
stdin_handle = win32.HANDLE((^File_Impl)(desc.stdin.impl).fd)
|
stdin_handle = win32.HANDLE((^File_Impl)(desc.stdin.impl).fd)
|
||||||
}
|
}
|
||||||
@@ -506,6 +507,10 @@ _process_wait :: proc(process: Process, timeout: time.Duration) -> (process_stat
|
|||||||
|
|
||||||
switch win32.WaitForSingleObject(handle, timeout_ms) {
|
switch win32.WaitForSingleObject(handle, timeout_ms) {
|
||||||
case win32.WAIT_OBJECT_0:
|
case win32.WAIT_OBJECT_0:
|
||||||
|
if process._impl.null_handle != nil {
|
||||||
|
win32.CloseHandle(process._impl.null_handle)
|
||||||
|
}
|
||||||
|
|
||||||
exit_code: u32
|
exit_code: u32
|
||||||
if !win32.GetExitCodeProcess(handle, &exit_code) {
|
if !win32.GetExitCodeProcess(handle, &exit_code) {
|
||||||
err =_get_platform_error()
|
err =_get_platform_error()
|
||||||
@@ -532,6 +537,10 @@ _process_wait :: proc(process: Process, timeout: time.Duration) -> (process_stat
|
|||||||
err = General_Error.Timeout
|
err = General_Error.Timeout
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
|
if process._impl.null_handle != nil {
|
||||||
|
win32.CloseHandle(process._impl.null_handle)
|
||||||
|
}
|
||||||
|
|
||||||
err = _get_platform_error()
|
err = _get_platform_error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user