Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getuid to check instead of USER env var in rustbuild #100852

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 9 additions & 4 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,18 @@ impl Build {
let src = config.src.clone();
let out = config.out.clone();

#[cfg(unix)]
Mark-Simulacrum marked this conversation as resolved.
Show resolved Hide resolved
// 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") {
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
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,
};
#[cfg(not(unix))]
let is_sudo = false;

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