init: enable error reporting of builtin functions
Enable error reporting when builtin functions fail. These errors are
now reported with full context including the source file and line
number, e.g.
init: Command 'write /sys/module/subsystem_restart/parameters/enable_debug ${persist.sys.ssr.enable_debug}' action=early-boot (/init.bullhead.rc:84) took 0ms and failed: cannot expand '${persist.sys.ssr.enable_debug}'
There are two small caveats:
1) There are nearly 200 reports of builtins failure due to "No such
file or directory". Many of these are due to legacy paths included
in rootdir/init.rc. Until they are cleaned up, reporting of these
failures is disabled.
2) Similarly, symlink is often used to create backwards compatible
symlinks. By their very nature, these calls are expected to fail
on newer systems that do already use the new path. Due to this,
failures of symlink due to EEXIST are not reported.
Bug: 38038887
Test: boot bullhead, only see true errors reported from builtins.
Change-Id: I316c13e3adc992cacc6d79ffee987adc8738fca0
diff --git a/init/action.cpp b/init/action.cpp
index a7aa756..60204a8 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -91,8 +91,19 @@
auto result = command.InvokeFunc();
auto duration = t.duration();
+ // There are many legacy paths in rootdir/init.rc that will virtually never exist on a new
+ // device, such as '/sys/class/leds/jogball-backlight/brightness'. As of this writing, there
+ // are 198 such failures on bullhead. Instead of spamming the log reporting them, we do not
+ // report such failures unless we're running at the DEBUG log level.
+ bool report_failure = !result.has_value();
+ if (report_failure && android::base::GetMinimumLogSeverity() > android::base::DEBUG &&
+ result.error_errno() == ENOENT) {
+ report_failure = false;
+ }
+
// Any action longer than 50ms will be warned to user as slow operation
- if (duration > 50ms || android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
+ if (report_failure || duration > 50ms ||
+ android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
std::string trigger_name = BuildTriggersString();
std::string cmd_str = command.BuildCommandString();
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 3d0ba55..54ccf09 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -612,6 +612,11 @@
static Result<Success> do_symlink(const std::vector<std::string>& args) {
if (symlink(args[1].c_str(), args[2].c_str()) < 0) {
+ // The symlink builtin is often used to create symlinks for older devices to be backwards
+ // compatible with new paths, therefore we skip reporting this error.
+ if (errno == EEXIST && android::base::GetMinimumLogSeverity() > android::base::DEBUG) {
+ return Success();
+ }
return ErrnoError() << "symlink() failed";
}
return Success();