Skip to content

Commit 7668a1e

Browse files
committed
libstd: Add thread unsafety warnings around setenv() and unsetenv()
See: https://sourceware.org/bugzilla/show_bug.cgi?id=4887#c9 https://bugs.freedesktop.org/show_bug.cgi?id=65681 I just noticed this while talking to someone who was using `os.environ['FOO'] = 'BAR'` in Python and since I'm learning Rust, I was curious if it did anything special here (and the answer appears to be no). Java got this right by disallowing `setenv()` from the start.
1 parent 69e47c7 commit 7668a1e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libstd/env.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ impl Error for VarError {
241241
}
242242

243243
/// Sets the environment variable `k` to the value `v` for the currently running
244-
/// process.
244+
/// process. Warning: On some operating systems, this function manipulates global
245+
/// state in a thread-unsafe fashion. On most Unix implementations, it will be
246+
/// safe to call this only very early in process startup, before any other threads
247+
/// are created that will potentially call `getenv()`.
245248
///
246249
/// # Examples
247250
///
@@ -261,6 +264,10 @@ pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
261264
}
262265

263266
/// Removes an environment variable from the environment of the currently running process.
267+
/// Warning: On some operating systems, this function manipulates global
268+
/// state in a thread-unsafe fashion. On most Unix implementations, it will be
269+
/// safe to call this only very early in process startup, before any other threads
270+
/// are created that will potentially call `getenv()`.
264271
///
265272
/// # Examples
266273
///

0 commit comments

Comments
 (0)