Re:C stdlib isn't threadsafe and even safe Rust didn't save us
by fch42 on Thursday January 23, 2025 @11:55AM
(#42805653)
"mutating" there involves the need to (re)allocate memory. To do so in a signal handler is hard ... because memory allocators are, while threadsafe, not async-signal-safe. You can't make a hard problem easy by asserting dependence on another (unsolved) hard problem.
Btw, you can _also_ substitute libc's setenv/getenv/putenv with your own (locking) implementations, courtesy preload and all the funky features of ELF symbol resolution. Actually easy. But impossible if you link against static code using it (go ... away). Hmm. easy ? impossible ? damn this grey world. Gimme some color.
"easy": protect the page containing environ and handle the mutation from the signal handler.
/s of course.