this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

proc_pidinfo_tbsdinfo: Use readline instead

4096 can be too small, depending on the host's hardware (specifically,
the CPU core count).

Instead of that, use readline, which is more appropriate in this case.

+18 -12
+18 -12
src/kernel/emulation/linux/misc/proc_info.c
··· 24 24 #include <stddef.h> 25 25 #include "../elfcalls_wrapper.h" 26 26 #include <darlingserver/rpc.h> 27 + #include "../readline.h" 27 28 28 29 #define LINUX_PR_SET_NAME 15 29 30 ··· 285 286 286 287 uint64_t starttime = __simple_atoi(elem, NULL); 287 288 288 - if (!read_string("/proc/stat", stat, sizeof(stat))) 289 + struct rdline_buffer rbuf; 290 + int statfd = sys_open("/proc/stat", BSD_O_RDONLY, 0); 291 + 292 + if (statfd < 0) 289 293 return -ESRCH; 290 - 291 - statptr = stat; 294 + 295 + _readline_init(&rbuf); 292 296 293 297 uint64_t btime; 298 + const char* line = NULL; 294 299 295 - while (statptr < stat + sizeof(stat)) 300 + while ((line = _readline(statfd, &rbuf)) != NULL) 296 301 { 297 - if (strncmp(statptr, "btime ", 6) == 0) 302 + if (strncmp(line, "btime ", 6) == 0) 298 303 { 299 - statptr += 6; 300 - btime = __simple_atoi(statptr, NULL); 304 + line += 6; 305 + btime = __simple_atoi(line, NULL); 301 306 break; 302 307 } 308 + } 303 309 304 - char* next = strchr(statptr, '\n'); 305 - if (!next) 306 - return -ESRCH; 307 - 308 - statptr = next + 1; 310 + close_internal(statfd); 311 + 312 + // if we see `line == NULL`, we didn't break out early, so we didn't see "btime" 313 + if (line == NULL) { 314 + return -ESRCH; 309 315 } 310 316 311 317 long ticks_per_sec = native_sysconf(_SC_CLK_TCK);