o_cloexec; preserve leading slashes in root-level paths

This commit is contained in:
Ryan Fleury
2025-11-07 16:37:30 -08:00
parent d4d2159389
commit 035e72306d
4 changed files with 327 additions and 312 deletions
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -110,7 +110,7 @@ internal int
demon_lnx_open_memory_fd_for_pid(pid_t pid){
Temp scratch = scratch_begin(0, 0);
String8 memory_path = push_str8f(scratch.arena, "/proc/%i/mem", pid);
int result = open((char*)memory_path.str, O_RDWR);
int result = open((char*)memory_path.str, O_RDWR|O_CLOEXEC);
scratch_end(scratch);
return(result);
}
@@ -126,7 +126,7 @@ demon_lnx_arch_from_pid(pid_t pid){
// handle to exe
int exe_fd = -1;
if (exe_path.size != 0){
exe_fd = open((char*)exe_path.str, O_RDONLY);
exe_fd = open((char*)exe_path.str, O_RDONLY|O_CLOEXEC);
}
// elf identification
@@ -199,7 +199,7 @@ demon_lnx_aux_from_pid(pid_t pid, Arch arch){
// open aux data
Temp scratch = scratch_begin(0, 0);
String8 auxv_symbol_path = push_str8f(scratch.arena, "/proc/%d/auxv", pid);
int aux_fd = open((char*)auxv_symbol_path.str, O_RDONLY);
int aux_fd = open((char*)auxv_symbol_path.str, O_RDONLY|O_CLOEXEC);
// scan aux data
if (aux_fd >= 0){
@@ -670,7 +670,7 @@ internal int
demon_lnx_open_maps(pid_t pid){
Temp scratch = scratch_begin(0, 0);
String8 path = push_str8f(scratch.arena, "/proc/%d/maps", pid);
int maps = open((char*)path.str, O_RDONLY);
int maps = open((char*)path.str, O_RDONLY|O_CLOEXEC);
scratch_end(scratch);
return(maps);
}
+17 -3
View File
@@ -1977,12 +1977,26 @@ rdim_bake_path_tree_insert(RDIM_Arena *arena, RDIM_BakePathTree *tree, RDIM_Stri
RDI_U8 *opl = string.str + string.size;
for(;ptr < opl;)
{
// rjf: skip past slashes
for(;ptr < opl && (*ptr == '/' || *ptr == '\\'); ptr += 1);
// rjf: skip past non-leading slashes
RDI_U32 leading_slash = 0;
if(ptr > string.str)
{
for(;ptr < opl && (*ptr == '/' || *ptr == '\\'); ptr += 1);
}
else if(ptr < opl)
{
leading_slash = (*ptr == '/');
}
// rjf: save beginning of non-slash range
// rjf: save beginning of path part
RDI_U8 *range_first = ptr;
// rjf: advance past leading slash
if(leading_slash)
{
ptr += 1;
}
// rjf: skip past non-slashes
for(;ptr < opl && !(*ptr == '/' || *ptr == '\\'); ptr += 1);
+2 -1
View File
@@ -284,6 +284,7 @@ os_file_open(OS_AccessFlags flags, String8 path)
{
lnx_flags |= O_CREAT;
}
lnx_flags |= O_CLOEXEC;
int fd = open((char *)path_copy.str, lnx_flags, 0755);
OS_Handle handle = {0};
if(fd != -1)
@@ -652,7 +653,7 @@ os_shared_memory_alloc(U64 size, String8 name)
{
Temp scratch = scratch_begin(0, 0);
String8 name_copy = push_str8_copy(scratch.arena, name);
int id = shm_open((char *)name_copy.str, O_RDWR | O_CREAT, 0666);
int id = shm_open((char *)name_copy.str, O_RDWR|O_CREAT, 0666);
ftruncate(id, size);
OS_Handle result = {(U64)id};
scratch_end(scratch);