From 0335dac70df8d0d793faada8dad8d42ea40fb0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Mon, 12 Feb 2024 15:02:02 +0000 Subject: [PATCH] first_stage_console: Fix execv() child error path If the /first_stage.sh is not present on the system, the child process which attempted to execv() ends up returning from the function along with its parent, which can be seen in early logs e.g. [ 10.747576][ T51] init: Attempting to run /first_stage.sh... [ 10.757371][ T52] init: unable to execv /first_stage.sh, returned -1 errno 2 [ 10.767527][ T52] init: unable to execv, returned -1 errno 2 [...] [ 10.789189][ T51] init: unable to execv, returned -1 errno 2 where both T51 and T52 end up executing the "rest" of StartConsole(). Instead, terminate the child if its execv() failed. Test: run first_stage_init Change-Id: I20bc0aeae627761a60fb2b55bae39871ad506f69 --- init/first_stage_console.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/init/first_stage_console.cpp b/init/first_stage_console.cpp index c6c3008ce..007676483 100644 --- a/init/first_stage_console.cpp +++ b/init/first_stage_console.cpp @@ -78,6 +78,7 @@ static void RunScript() { const char* args[] = {path, "/first_stage.sh", nullptr}; int rv = execv(path, const_cast(args)); LOG(ERROR) << "unable to execv /first_stage.sh, returned " << rv << " errno " << errno; + _exit(127); } namespace android {