Mutable global state is evil. Friends don’t let friends use mutable global state. I hate envvars. It’s “the Linux way”. I avoid them like the plague. A++ strong recommend. libc is terrible. The world needs to move on.
Env vars are good if you treat them as read-only within the process
C stdlib isn't threadsafe and even safe Rust didn't save us
11–20 of 370 posts
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#12Mutable global state is evil. Friends don’t let friends use mutable global state. I hate envvars. It’s “the Linux way”. I avoid them like the plague. A++ strong recommend. libc is terrible. The world needs to move on.
Throw away your CPU and RAM then.
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#13In the Rust std, `set_var` and `remove_var` will correctly require using an `unsafe {}` block in the next edition (2024). The documentation does now mention the safety issue but obviously it was a mistake to make these functions safe originally (albeit a mistake even higher level languages have made). https://doc.rust-lang.org/stable/std/env/fn.set_var.html There is a patch for glibc which makes `getenv` safe in more…
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#14Yet another person is burned by calling setenv() in a multi-threaded context. There really needs to be a big warning banner on the manpage for setenv() that warns about this because it seems like a far more common problem than you would expect.
The man page says: > POSIX.1 does not require setenv() or unsetenv() to be reentrant. A non-reentrant function cannot be thread safe. In general (for POSIX, libc and many other libraries: if the docs do not explicitly say "this function is thread safe" they are not).
"It is ridiculous that this has been a known problem for so long. It has wasted thousands of hours of people's time, either debugging the problems, or debating what to do about it. We know how to fix the problem." https://www.evanjones.ca/setenv-is-not-thread-safe.html
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#15Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#16In the Rust std, `set_var` and `remove_var` will correctly require using an `unsafe {}` block in the next edition (2024). The documentation does now mention the safety issue but obviously it was a mistake to make these functions safe originally (albeit a mistake even higher level languages have made). https://doc.rust-lang.org/stable/std/env/fn.set_var.html There is a patch for glibc which makes `getenv` safe in more…
Why requiring unsafe when the std implementation could take care of the synchronisation?
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#17Mutable global state is evil. Friends don’t let friends use mutable global state. I hate envvars. It’s “the Linux way”. I avoid them like the plague. A++ strong recommend. libc is terrible. The world needs to move on.
> Mutable global state is evil. Friends don’t let friends use mutable global state. Throw away your CPU and RAM then.
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#18In the Rust std, `set_var` and `remove_var` will correctly require using an `unsafe {}` block in the next edition (2024). The documentation does now mention the safety issue but obviously it was a mistake to make these functions safe originally (albeit a mistake even higher level languages have made). https://doc.rust-lang.org/stable/std/env/fn.set_var.html There is a patch for glibc which makes `getenv` safe in more…
Why requiring unsafe when the std implementation could take care of the synchronisation?
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#19In the Rust std, `set_var` and `remove_var` will correctly require using an `unsafe {}` block in the next edition (2024). The documentation does now mention the safety issue but obviously it was a mistake to make these functions safe originally (albeit a mistake even higher level languages have made). https://doc.rust-lang.org/stable/std/env/fn.set_var.html There is a patch for glibc which makes `getenv` safe in more…
Why requiring unsafe when the std implementation could take care of the synchronisation?
The only way to coordinate locking would be to do so in libc itself.
Re: C stdlib isn't threadsafe and even safe Rust didn't save us
#20Mutable global state is evil. Friends don’t let friends use mutable global state. I hate envvars. It’s “the Linux way”. I avoid them like the plague. A++ strong recommend. libc is terrible. The world needs to move on.