Skip to content

Commit b05f97d

Browse files
authoredSep 1, 2022
Rollup merge of rust-lang#100852 - Samyak2:samyak/100459, r=Mark-Simulacrum
Use `getuid` to check instead of `USER` env var in rustbuild This makes it consistent with `x.py` as changed in rust-lang#95671 Fixes rust-lang#100459
2 parents da1d738 + b9c47f6 commit b05f97d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎src/bootstrap/bootstrap.py

+2
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ def set_dist_environment(self, url):
793793

794794
def check_vendored_status(self):
795795
"""Check that vendoring is configured properly"""
796+
# keep this consistent with the equivalent check in rustbuild:
797+
# https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/lib.rs#L399-L405
796798
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
797799
if os.getuid() == 0:
798800
self.use_vendored_sources = True

‎src/bootstrap/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,18 @@ impl Build {
395395
let src = config.src.clone();
396396
let out = config.out.clone();
397397

398+
#[cfg(unix)]
399+
// keep this consistent with the equivalent check in x.py:
400+
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
398401
let is_sudo = match env::var_os("SUDO_USER") {
399-
Some(sudo_user) => match env::var_os("USER") {
400-
Some(user) => user != sudo_user,
401-
None => false,
402-
},
402+
Some(_sudo_user) => {
403+
let uid = unsafe { libc::getuid() };
404+
uid == 0
405+
}
403406
None => false,
404407
};
408+
#[cfg(not(unix))]
409+
let is_sudo = false;
405410

406411
let ignore_git = config.ignore_git;
407412
let rust_info = channel::GitInfo::new(ignore_git, &src);

0 commit comments

Comments
 (0)
Please sign in to comment.