News for hackers. Stuff that matters.
Re:Getaddrinfo() on glibc calls getenv(), oh boy by asveikau on Monday October 16, 2023 @09:37PM (#37909272)
I think in libc, there's a lot of stuff where an interface is kind of broken from a thread perspective, and it could be implemented better without changing the interface, but often people generally do not.

I can't think of any examples offhand, but I often think it about thread-local storage. Eg. lots of interfaces have an _r() equivalent where you provide the buffer, but many people still call the unsafe one which is broken when there are threads... In my mind, the best way to do this would be to use static thread-local storage in the non-_r() one, and have it call the _r() one ... Sure that has overhead and isn't a perfect solution, but it's better than "bad". But a lot of these old functions don't necessarily get love.

Re:Getaddrinfo() on glibc calls getenv(), oh boy by Gibbon1 on Tuesday October 17, 2023 @01:07PM (#37918149)
An a sane world creating a thread would set a global that causes non thread safe library functions to seg fault. Or maybe calling them from two different threads causes a seg fault. But just make it really obvious you're doing bad stuff.
Re:Getaddrinfo() on glibc calls getenv(), oh boy by asveikau on Tuesday October 17, 2023 @01:46PM (#37918760)
I think that sounds completely insane. The unsafety is an emergent property of what's done in the function, and entirely dependent on usage. If you were doing very disciplined use of an unsafe call, it's harmless.

Perhaps this would be a good feature of an assert, or something that breaks in a debugger if it's attached. But I don't think that is reasonable for production.