Skip to content

Commit

Permalink
Rollup merge of rust-lang#100852 - Samyak2:samyak/100459, r=Mark-Simu…
Browse files Browse the repository at this point in the history
…lacrum

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
  • Loading branch information
JohnTitor authored Aug 23, 2022
2 parents 3577767 + 9fc23bb commit b2407ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ def set_dist_environment(self, url):

def check_vendored_status(self):
"""Check that vendoring is configured properly"""
# keep this consistent with the equivalent check in rustbuild:
# https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/lib.rs#L399-L405
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
if os.getuid() == 0:
self.use_vendored_sources = True
Expand Down
10 changes: 6 additions & 4 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,13 @@ impl Build {
let src = config.src.clone();
let out = config.out.clone();

// keep this consistent with the equivalent check in x.py:
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
let is_sudo = match env::var_os("SUDO_USER") {
Some(sudo_user) => match env::var_os("USER") {
Some(user) => user != sudo_user,
None => false,
},
Some(_sudo_user) => {
let uid = unsafe { libc::getuid() };
uid == 0
}
None => false,
};

Expand Down

0 comments on commit b2407ea

Please sign in to comment.