From 6de21f11125941ea1b94fdeec754bacea3916fd5 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 22 Aug 2017 15:41:03 -0700 Subject: init: cleanup environment handling Init keep its own copy of the environment that it uses for execve when starting services. This is unnecessary however as libc already has functions that mutate the environment and the environment that init uses is clean for starting services. This change removes init's copy of the environment and uses the libc functions instead. This also makes small clean-up to the way the Service class stores service specific environment variables. Test: boot bullhead Change-Id: I7c98a0b7aac9fa8f195ae33bd6a7515bb56faf78 --- init/builtins.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init/builtins.cpp') diff --git a/init/builtins.cpp b/init/builtins.cpp index f807343ab..593f718f1 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -159,8 +159,8 @@ static Result do_exec_start(const std::vector& args) { } static Result do_export(const std::vector& args) { - if (!add_environment(args[1].c_str(), args[2].c_str())) { - return Error(); + if (setenv(args[1].c_str(), args[2].c_str(), 1) == -1) { + return ErrnoError() << "setenv() failed"; } return Success(); } -- cgit v1.2.3 From 76af7e6a0c4ce7759e6cc5994b5496ddb09035ee Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 22 Aug 2017 16:13:59 -0700 Subject: init: log Service failures via Result Log Service failures via Result such that their context can be captured when interacting with services through builtin functions. Test: boot bullhead Change-Id: I4d99744d64008d4a06a404e3c9817182c6e177bc --- init/builtins.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'init/builtins.cpp') diff --git a/init/builtins.cpp b/init/builtins.cpp index 593f718f1..3d0ba5547 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -127,7 +127,9 @@ static Result do_enable(const std::vector& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "Could not find service"; - if (!svc->Enable()) return Error() << "Could not enable service"; + if (auto result = svc->Enable(); !result) { + return Error() << "Could not enable service: " << result.error(); + } return Success(); } @@ -137,8 +139,8 @@ static Result do_exec(const std::vector& args) { if (!service) { return Error() << "Could not create exec service"; } - if (!service->ExecStart()) { - return Error() << "Could not start exec service"; + if (auto result = service->ExecStart(); !result) { + return Error() << "Could not start exec service: " << result.error(); } ServiceList::GetInstance().AddService(std::move(service)); @@ -151,8 +153,8 @@ static Result do_exec_start(const std::vector& args) { return Error() << "Service not found"; } - if (!service->ExecStart()) { - return Error() << "Could not start Service"; + if (auto result = service->ExecStart(); !result) { + return Error() << "Could not start exec service: " << result.error(); } return Success(); @@ -583,7 +585,9 @@ static Result do_setrlimit(const std::vector& args) { static Result do_start(const std::vector& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "service " << args[1] << " not found"; - if (!svc->Start()) return Error() << "failed to start service"; + if (auto result = svc->Start(); !result) { + return Error() << "Could not start service: " << result.error(); + } return Success(); } -- cgit v1.2.3 From 68f2a4614518468f1320ad3e62a6db554e509fb1 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 22 Aug 2017 16:15:26 -0700 Subject: 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 --- init/builtins.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'init/builtins.cpp') diff --git a/init/builtins.cpp b/init/builtins.cpp index 3d0ba5547..54ccf091e 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -612,6 +612,11 @@ static Result do_trigger(const std::vector& args) { static Result do_symlink(const std::vector& 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(); -- cgit v1.2.3