|
@@ -50,7 +50,7 @@ _get_ppid :: proc() -> int {
|
|
|
|
|
|
@(private="package")
|
|
@(private="package")
|
|
_process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error) {
|
|
_process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error) {
|
|
- TEMP_ALLOCATOR_GUARD()
|
|
|
|
|
|
+ temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
|
|
|
|
|
|
dir_fd, errno := linux.open("/proc/", _OPENDIR_FLAGS)
|
|
dir_fd, errno := linux.open("/proc/", _OPENDIR_FLAGS)
|
|
#partial switch errno {
|
|
#partial switch errno {
|
|
@@ -68,9 +68,9 @@ _process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error)
|
|
}
|
|
}
|
|
defer linux.close(dir_fd)
|
|
defer linux.close(dir_fd)
|
|
|
|
|
|
- dynamic_list := make([dynamic]int, temp_allocator()) or_return
|
|
|
|
|
|
+ dynamic_list := make([dynamic]int, temp_allocator) or_return
|
|
|
|
|
|
- buf := make([dynamic]u8, 128, 128, temp_allocator()) or_return
|
|
|
|
|
|
+ buf := make([dynamic]u8, 128, 128, temp_allocator) or_return
|
|
loop: for {
|
|
loop: for {
|
|
buflen: int
|
|
buflen: int
|
|
buflen, errno = linux.getdents(dir_fd, buf[:])
|
|
buflen, errno = linux.getdents(dir_fd, buf[:])
|
|
@@ -100,7 +100,7 @@ _process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error)
|
|
|
|
|
|
@(private="package")
|
|
@(private="package")
|
|
_process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) {
|
|
_process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator: runtime.Allocator) -> (info: Process_Info, err: Error) {
|
|
- TEMP_ALLOCATOR_GUARD()
|
|
|
|
|
|
+ temp_allocator := TEMP_ALLOCATOR_GUARD({ allocator })
|
|
|
|
|
|
info.pid = pid
|
|
info.pid = pid
|
|
|
|
|
|
@@ -126,7 +126,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
|
|
|
|
passwd_bytes: []u8
|
|
passwd_bytes: []u8
|
|
passwd_err: Error
|
|
passwd_err: Error
|
|
- passwd_bytes, passwd_err = _read_entire_pseudo_file_cstring("/etc/passwd", temp_allocator())
|
|
|
|
|
|
+ passwd_bytes, passwd_err = _read_entire_pseudo_file_cstring("/etc/passwd", temp_allocator)
|
|
if passwd_err != nil {
|
|
if passwd_err != nil {
|
|
err = passwd_err
|
|
err = passwd_err
|
|
break username_if
|
|
break username_if
|
|
@@ -168,7 +168,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_string(&path_builder, "/cmdline")
|
|
strings.write_string(&path_builder, "/cmdline")
|
|
|
|
|
|
- cmdline_bytes, cmdline_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator())
|
|
|
|
|
|
+ cmdline_bytes, cmdline_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator)
|
|
if cmdline_err != nil || len(cmdline_bytes) == 0 {
|
|
if cmdline_err != nil || len(cmdline_bytes) == 0 {
|
|
err = cmdline_err
|
|
err = cmdline_err
|
|
break cmdline_if
|
|
break cmdline_if
|
|
@@ -189,7 +189,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_string(&path_builder, "/cwd")
|
|
strings.write_string(&path_builder, "/cwd")
|
|
|
|
|
|
- cwd, cwd_err = _read_link_cstr(strings.to_cstring(&path_builder) or_return, temp_allocator()) // allowed to fail
|
|
|
|
|
|
+ cwd, cwd_err = _read_link_cstr(strings.to_cstring(&path_builder) or_return, temp_allocator) // allowed to fail
|
|
if cwd_err == nil && .Working_Dir in selection {
|
|
if cwd_err == nil && .Working_Dir in selection {
|
|
info.working_dir = strings.clone(cwd, allocator) or_return
|
|
info.working_dir = strings.clone(cwd, allocator) or_return
|
|
info.fields += {.Working_Dir}
|
|
info.fields += {.Working_Dir}
|
|
@@ -245,7 +245,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_string(&path_builder, "/stat")
|
|
strings.write_string(&path_builder, "/stat")
|
|
|
|
|
|
- proc_stat_bytes, stat_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator())
|
|
|
|
|
|
+ proc_stat_bytes, stat_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator)
|
|
if stat_err != nil {
|
|
if stat_err != nil {
|
|
err = stat_err
|
|
err = stat_err
|
|
break stat_if
|
|
break stat_if
|
|
@@ -284,7 +284,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
Nice,
|
|
Nice,
|
|
//... etc,
|
|
//... etc,
|
|
}
|
|
}
|
|
- stat_fields := strings.split(stats, " ", temp_allocator()) or_return
|
|
|
|
|
|
+ stat_fields := strings.split(stats, " ", temp_allocator) or_return
|
|
|
|
|
|
if len(stat_fields) <= int(Fields.Nice) {
|
|
if len(stat_fields) <= int(Fields.Nice) {
|
|
break stat_if
|
|
break stat_if
|
|
@@ -327,7 +327,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_string(&path_builder, "/exe")
|
|
strings.write_string(&path_builder, "/exe")
|
|
|
|
|
|
- if exe_bytes, exe_err := _read_link(strings.to_string(path_builder), temp_allocator()); exe_err == nil {
|
|
|
|
|
|
+ if exe_bytes, exe_err := _read_link(strings.to_string(path_builder), temp_allocator); exe_err == nil {
|
|
info.executable_path = strings.clone(string(exe_bytes), allocator) or_return
|
|
info.executable_path = strings.clone(string(exe_bytes), allocator) or_return
|
|
info.fields += {.Executable_Path}
|
|
info.fields += {.Executable_Path}
|
|
} else {
|
|
} else {
|
|
@@ -341,7 +341,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_int(&path_builder, pid)
|
|
strings.write_string(&path_builder, "/environ")
|
|
strings.write_string(&path_builder, "/environ")
|
|
|
|
|
|
- if env_bytes, env_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator()); env_err == nil {
|
|
|
|
|
|
+ if env_bytes, env_err := _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator); env_err == nil {
|
|
env := string(env_bytes)
|
|
env := string(env_bytes)
|
|
|
|
|
|
env_list := make([dynamic]string, allocator) or_return
|
|
env_list := make([dynamic]string, allocator) or_return
|
|
@@ -392,7 +392,7 @@ _process_open :: proc(pid: int, _: Process_Open_Flags) -> (process: Process, err
|
|
|
|
|
|
@(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 := TEMP_ALLOCATOR_GUARD({})
|
|
|
|
|
|
if len(desc.command) == 0 {
|
|
if len(desc.command) == 0 {
|
|
return process, .Invalid_Command
|
|
return process, .Invalid_Command
|
|
@@ -401,7 +401,7 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|
dir_fd := linux.AT_FDCWD
|
|
dir_fd := linux.AT_FDCWD
|
|
errno: linux.Errno
|
|
errno: linux.Errno
|
|
if desc.working_dir != "" {
|
|
if desc.working_dir != "" {
|
|
- dir_cstr := temp_cstring(desc.working_dir) or_return
|
|
|
|
|
|
+ dir_cstr := clone_to_cstring(desc.working_dir, temp_allocator) or_return
|
|
if dir_fd, errno = linux.open(dir_cstr, _OPENDIR_FLAGS); errno != .NONE {
|
|
if dir_fd, errno = linux.open(dir_cstr, _OPENDIR_FLAGS); errno != .NONE {
|
|
return process, _get_platform_error(errno)
|
|
return process, _get_platform_error(errno)
|
|
}
|
|
}
|
|
@@ -414,10 +414,10 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|
exe_path: cstring
|
|
exe_path: cstring
|
|
executable_name := desc.command[0]
|
|
executable_name := desc.command[0]
|
|
if strings.index_byte(executable_name, '/') < 0 {
|
|
if strings.index_byte(executable_name, '/') < 0 {
|
|
- path_env := get_env("PATH", temp_allocator())
|
|
|
|
- path_dirs := split_path_list(path_env, temp_allocator()) or_return
|
|
|
|
|
|
+ path_env := get_env("PATH", temp_allocator)
|
|
|
|
+ path_dirs := split_path_list(path_env, temp_allocator) or_return
|
|
|
|
|
|
- exe_builder := strings.builder_make(temp_allocator()) or_return
|
|
|
|
|
|
+ exe_builder := strings.builder_make(temp_allocator) or_return
|
|
|
|
|
|
found: bool
|
|
found: bool
|
|
for dir in path_dirs {
|
|
for dir in path_dirs {
|
|
@@ -444,7 +444,7 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- exe_path = temp_cstring(executable_name) or_return
|
|
|
|
|
|
+ exe_path = clone_to_cstring(executable_name, temp_allocator) or_return
|
|
if linux.access(exe_path, linux.X_OK) != .NONE {
|
|
if linux.access(exe_path, linux.X_OK) != .NONE {
|
|
return process, .Not_Exist
|
|
return process, .Not_Exist
|
|
}
|
|
}
|
|
@@ -452,20 +452,20 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|
|
|
|
|
// args and environment need to be a list of cstrings
|
|
// args and environment need to be a list of cstrings
|
|
// that are terminated by a nil pointer.
|
|
// that are terminated by a nil pointer.
|
|
- cargs := make([]cstring, len(desc.command) + 1, temp_allocator()) or_return
|
|
|
|
|
|
+ cargs := make([]cstring, len(desc.command) + 1, temp_allocator) or_return
|
|
for command, i in desc.command {
|
|
for command, i in desc.command {
|
|
- cargs[i] = temp_cstring(command) or_return
|
|
|
|
|
|
+ cargs[i] = clone_to_cstring(command, temp_allocator) or_return
|
|
}
|
|
}
|
|
|
|
|
|
// Use current process' environment if description didn't provide it.
|
|
// Use current process' environment if description didn't provide it.
|
|
env: [^]cstring
|
|
env: [^]cstring
|
|
if desc.env == nil {
|
|
if desc.env == nil {
|
|
// take this process's current environment
|
|
// take this process's current environment
|
|
- env = raw_data(export_cstring_environment(temp_allocator()))
|
|
|
|
|
|
+ env = raw_data(export_cstring_environment(temp_allocator))
|
|
} else {
|
|
} else {
|
|
- cenv := make([]cstring, len(desc.env) + 1, temp_allocator()) or_return
|
|
|
|
|
|
+ cenv := make([]cstring, len(desc.env) + 1, temp_allocator) or_return
|
|
for env, i in desc.env {
|
|
for env, i in desc.env {
|
|
- cenv[i] = temp_cstring(env) or_return
|
|
|
|
|
|
+ cenv[i] = clone_to_cstring(env, temp_allocator) or_return
|
|
}
|
|
}
|
|
env = &cenv[0]
|
|
env = &cenv[0]
|
|
}
|
|
}
|
|
@@ -593,7 +593,7 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
|
}
|
|
}
|
|
|
|
|
|
_process_state_update_times :: proc(state: ^Process_State) -> (err: Error) {
|
|
_process_state_update_times :: proc(state: ^Process_State) -> (err: Error) {
|
|
- TEMP_ALLOCATOR_GUARD()
|
|
|
|
|
|
+ temp_allocator := TEMP_ALLOCATOR_GUARD({})
|
|
|
|
|
|
stat_path_buf: [48]u8
|
|
stat_path_buf: [48]u8
|
|
path_builder := strings.builder_from_bytes(stat_path_buf[:])
|
|
path_builder := strings.builder_from_bytes(stat_path_buf[:])
|
|
@@ -602,7 +602,7 @@ _process_state_update_times :: proc(state: ^Process_State) -> (err: Error) {
|
|
strings.write_string(&path_builder, "/stat")
|
|
strings.write_string(&path_builder, "/stat")
|
|
|
|
|
|
stat_buf: []u8
|
|
stat_buf: []u8
|
|
- stat_buf, err = _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator())
|
|
|
|
|
|
+ stat_buf, err = _read_entire_pseudo_file(strings.to_cstring(&path_builder) or_return, temp_allocator)
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|