From 9fc23bbacbc86f0ca1efde8a54880cf5b1e543ed Mon Sep 17 00:00:00 2001 From: Samyak Sarnayak Date: Sun, 21 Aug 2022 23:21:58 +0530 Subject: [PATCH] Use getuid to check instead of USER env var in rustbuild This makes it consistent with `x.py` as changed in #95671 Fixes #100459 --- src/bootstrap/bootstrap.py | 2 ++ src/bootstrap/lib.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 9301c5a2ff30..03eec02a8bf0 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -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 diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index dcfa92d1004c..13ae5cd270b9 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -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, };