Skip to content

Commit

Permalink
Revert use of $TMPDIR
Browse files Browse the repository at this point in the history
Pertaining to #68.
  • Loading branch information
kotauskas committed Jul 21, 2024
1 parent 050ae2e commit f5c8afb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ platform to be demoted, although promotions quite obviously can happen as minor
- Interprocess is guaranteed to compile and succeed in running all tests – it would be a critical
bug for it not to
- CI, currently provided by GitHub Actions, runs on all of those platforms and displays an ugly red
badge if anything is wrong on any of those systems
badge if anything is wrong on any of those systems
- Certain `#[cfg]`-gated platform-specific features are supported with stable public APIs

##### Explicit support without CI
Expand Down
18 changes: 11 additions & 7 deletions src/os/unix/uds_local_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ fn get_run_user() -> io::Result<Option<OsString>> {
}
}

/// Gets the `TMPDIR` environment variable, or returns `/tmp` if it doesn't exist.
fn get_tmpdir() -> Cow<'static, OsStr> {
std::env::var_os("TMPDIR")
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(OsStr::new("/tmp")))
}
static TMPDIR: &str = {
#[cfg(target_os = "android")]
{
"/data/local/tmp"
}
#[cfg(not(target_os = "android"))]
{
"/tmp"
}
};

#[allow(clippy::indexing_slicing, clippy::arithmetic_side_effects)]
fn construct_and_prepare_pseudo_ns(
Expand All @@ -95,7 +99,7 @@ fn construct_and_prepare_pseudo_ns(
return Err(io::Error::new(io::ErrorKind::InvalidInput, TOOLONG));
}
let run_user = get_run_user()?;
let pfx = run_user.map(Cow::Owned).unwrap_or_else(get_tmpdir);
let pfx = run_user.map(Cow::Owned).unwrap_or(Cow::Borrowed(OsStr::new(TMPDIR)));
let pl = pfx.len();
let mut path = [0; SUN_LEN];
path[..pl].copy_from_slice(pfx.as_bytes());
Expand Down

0 comments on commit f5c8afb

Please sign in to comment.