From 9328021ce7ba61759f917f9de4d4b0eb705e7854 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 26 Sep 2019 15:24:40 -0700 Subject: [PATCH] init: add tips for debugging linker errors when launching init services Test: we can see linker errors in dmesg when following these tips Change-Id: I86b65e01d06ed7c0b908c4512d55872cd5595eca --- init/README.md | 6 ++++++ init/service.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/init/README.md b/init/README.md index 29b972d8a..cdf3487fd 100644 --- a/init/README.md +++ b/init/README.md @@ -784,6 +784,12 @@ affected. Debugging init -------------- +When a service starts from init, it may fail to `execv()` the service. This is not typical, and may +point to an error happening in the linker as the new service is started. The linker in Android +prints its logs to `logd` and `stderr`, so they are visible in `logcat`. If the error is encountered +before it is possible to access `logcat`, the `stdio_to_kmsg` service option may be used to direct +the logs that the linker prints to `stderr` to `kmsg`, where they can be read via a serial port. + Launching init services without init is not recommended as init sets up a significant amount of environment (user, groups, security label, capabilities, etc) that is hard to replicate manually. diff --git a/init/service.cpp b/init/service.cpp index e8b75d4e5..0b73dc5ef 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -490,7 +490,8 @@ Result Service::Start() { SetProcessAttributesAndCaps(); if (!ExpandArgsAndExecv(args_, sigstop_)) { - PLOG(ERROR) << "cannot execve('" << args_[0] << "')"; + PLOG(ERROR) << "cannot execv('" << args_[0] + << "'). See the 'Debugging init' section of init's README.md for tips"; } _exit(127);