diff options
| author | Tom Cherry <tomcherry@google.com> | 2017-08-01 13:50:23 -0700 |
|---|---|---|
| committer | Tom Cherry <tomcherry@google.com> | 2017-08-14 14:07:39 -0700 |
| commit | 557946e57c375b05deb5ba07b739f27abc70697e (patch) | |
| tree | a073dadfaa7529739187ae7264abc21b881c8b97 /init/init.cpp | |
| parent | 11a3aeeae3dc887b889d4086d4d26d95c324c08d (diff) | |
| download | system_core-557946e57c375b05deb5ba07b739f27abc70697e.tar.gz system_core-557946e57c375b05deb5ba07b739f27abc70697e.tar.bz2 system_core-557946e57c375b05deb5ba07b739f27abc70697e.zip | |
init: use Result<T> for builtin functions
We currently throw out the return values from builtin functions and
occasionally log errors with no supporting context. This change uses
the newly introduced Result<T> class to communicate a successful result
or an error back to callers in order to print an error with clear
context when a builtin fails.
Example:
init: Command 'write /sys/class/leds/vibrator/trigger transient' action=init (/init.rc:245) took 0ms and failed: Unable to write to file '/sys/class/leds/vibrator/trigger': open() failed: No such file or directory
Test: boot bullhead
Merged-In: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
Diffstat (limited to 'init/init.cpp')
| -rw-r--r-- | init/init.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/init/init.cpp b/init/init.cpp index ee3a84c29..c65d8460b 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -238,7 +238,7 @@ void handle_control_message(const std::string& msg, const std::string& name) { } } -static int wait_for_coldboot_done_action(const std::vector<std::string>& args) { +static Result<Success> wait_for_coldboot_done_action(const std::vector<std::string>& args) { Timer t; LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE "..."; @@ -257,22 +257,20 @@ static int wait_for_coldboot_done_action(const std::vector<std::string>& args) { } property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration().count())); - return 0; + return Success(); } -static int keychord_init_action(const std::vector<std::string>& args) -{ +static Result<Success> keychord_init_action(const std::vector<std::string>& args) { keychord_init(); - return 0; + return Success(); } -static int console_init_action(const std::vector<std::string>& args) -{ +static Result<Success> console_init_action(const std::vector<std::string>& args) { std::string console = GetProperty("ro.boot.console", ""); if (!console.empty()) { default_console = "/dev/" + console; } - return 0; + return Success(); } static void import_kernel_nv(const std::string& key, const std::string& value, bool for_emulator) { @@ -354,18 +352,16 @@ static void process_kernel_cmdline() { if (qemu[0]) import_kernel_cmdline(true, import_kernel_nv); } -static int property_enable_triggers_action(const std::vector<std::string>& args) -{ +static Result<Success> property_enable_triggers_action(const std::vector<std::string>& args) { /* Enable property triggers. */ property_triggers_enabled = 1; - return 0; + return Success(); } -static int queue_property_triggers_action(const std::vector<std::string>& args) -{ +static Result<Success> queue_property_triggers_action(const std::vector<std::string>& args) { ActionManager::GetInstance().QueueBuiltinAction(property_enable_triggers_action, "enable_property_trigger"); ActionManager::GetInstance().QueueAllPropertyActions(); - return 0; + return Success(); } static void global_seccomp() { |
