Skip to content

Commit 0a1a53d

Browse files
committed
Auto merge of #24741 - cgwalters:note-setenv-and-unsetenv-are-not-threadsafe, r=alexcrichton
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.
2 parents e77b03d + 44a5bf1 commit 0a1a53d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libstd/env.rs

+22
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ impl Error for VarError {
243243
/// Sets the environment variable `k` to the value `v` for the currently running
244244
/// process.
245245
///
246+
/// Note that while concurrent access to environment variables is safe in Rust,
247+
/// some platforms only expose inherently unsafe non-threadsafe APIs for
248+
/// inspecting the environment. As a result extra care needs to be taken when
249+
/// auditing calls to unsafe external FFI functions to ensure that any external
250+
/// environment accesses are properly synchronized with accesses in Rust.
251+
///
252+
/// Discussion of this unsafety on Unix may be found in:
253+
///
254+
/// - [Austin Group Bugzilla](http://austingroupbugs.net/view.php?id=188)
255+
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
256+
///
246257
/// # Examples
247258
///
248259
/// ```
@@ -260,6 +271,17 @@ pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(k: K, v: V) {
260271

261272
/// Removes an environment variable from the environment of the currently running process.
262273
///
274+
/// Note that while concurrent access to environment variables is safe in Rust,
275+
/// some platforms only expose inherently unsafe non-threadsafe APIs for
276+
/// inspecting the environment. As a result extra care needs to be taken when
277+
/// auditing calls to unsafe external FFI functions to ensure that any external
278+
/// environment accesses are properly synchronized with accesses in Rust.
279+
///
280+
/// Discussion of this unsafety on Unix may be found in:
281+
///
282+
/// - [Austin Group Bugzilla](http://austingroupbugs.net/view.php?id=188)
283+
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
284+
///
263285
/// # Examples
264286
///
265287
/// ```

0 commit comments

Comments
 (0)