From d36f4a36ed84ee108f41f13f1c66d58e79d636e9 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 23 Jul 2020 09:13:37 -0700 Subject: [PATCH] init: set $PATH in second stage init If the system partition has been updated and _PATH_DEFPATH has a new value, then we must set $PATH in second stage init to take on the new value, as well as having set it in first stage init. Bug: 160210288 Test: build Change-Id: I18765709dc9bff9379b0ae39272199cf74a79d2f --- init/init.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/init.cpp b/init/init.cpp index ba880ea32..cb5bbbab9 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -727,6 +728,12 @@ int SecondStageMain(int argc, char** argv) { InitSecondStageLogging(argv); LOG(INFO) << "init second stage started!"; + // Update $PATH in the case the second stage init is newer than first stage init, where it is + // first set. + if (setenv("PATH", _PATH_DEFPATH, 1) != 0) { + PLOG(FATAL) << "Could not set $PATH to '" << _PATH_DEFPATH << "' in second stage"; + } + // Init should not crash because of a dependence on any other process, therefore we ignore // SIGPIPE and handle EPIPE at the call site directly. Note that setting a signal to SIG_IGN // is inherited across exec, but custom signal handlers are not. Since we do not want to