diff options
author | Bernie Innocenti <codewiz@google.com> | 2020-02-06 03:49:33 +0900 |
---|---|---|
committer | Bernie Innocenti <codewiz@google.com> | 2020-02-06 17:04:27 +0000 |
commit | cecebbbaccd36dc2e9f6e80c8e91e57d979963a5 (patch) | |
tree | e866ec8f6bd1eafcc47a7f26d5b957ad787dcfdc /init/builtins.cpp | |
parent | a6bc86aae72e406c1e90ff25eb3f95b654d9a723 (diff) |
Convert system/core to Result::ok()
No functionality changes, this is a mechanical cleanup.
Test: m
Test: cd system/core && atest
Change-Id: Ifdaa3ce1947ed578f656d5a446978726eb416c36
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index 742e0896d..60c3d40a7 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -164,7 +164,7 @@ static Result<void> do_class_start(const BuiltinArguments& args) { // They must be started individually. for (const auto& service : ServiceList::GetInstance()) { if (service->classnames().count(args[1])) { - if (auto result = service->StartIfNotDisabled(); !result) { + if (auto result = service->StartIfNotDisabled(); !result.ok()) { LOG(ERROR) << "Could not start service '" << service->name() << "' as part of class '" << args[1] << "': " << result.error(); } @@ -186,7 +186,7 @@ static Result<void> do_class_start_post_data(const BuiltinArguments& args) { } for (const auto& service : ServiceList::GetInstance()) { if (service->classnames().count(args[1])) { - if (auto result = service->StartIfPostData(); !result) { + if (auto result = service->StartIfPostData(); !result.ok()) { LOG(ERROR) << "Could not start service '" << service->name() << "' as part of class '" << args[1] << "': " << result.error(); } @@ -227,7 +227,7 @@ static Result<void> do_class_restart(const BuiltinArguments& args) { } static Result<void> do_domainname(const BuiltinArguments& args) { - if (auto result = WriteFile("/proc/sys/kernel/domainname", args[1]); !result) { + if (auto result = WriteFile("/proc/sys/kernel/domainname", args[1]); !result.ok()) { return Error() << "Unable to write to /proc/sys/kernel/domainname: " << result.error(); } return {}; @@ -237,7 +237,7 @@ static Result<void> do_enable(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "Could not find service"; - if (auto result = svc->Enable(); !result) { + if (auto result = svc->Enable(); !result.ok()) { return Error() << "Could not enable service: " << result.error(); } @@ -246,10 +246,10 @@ static Result<void> do_enable(const BuiltinArguments& args) { static Result<void> do_exec(const BuiltinArguments& args) { auto service = Service::MakeTemporaryOneshotService(args.args); - if (!service) { + if (!service.ok()) { return Error() << "Could not create exec service: " << service.error(); } - if (auto result = (*service)->ExecStart(); !result) { + if (auto result = (*service)->ExecStart(); !result.ok()) { return Error() << "Could not start exec service: " << result.error(); } @@ -259,10 +259,10 @@ static Result<void> do_exec(const BuiltinArguments& args) { static Result<void> do_exec_background(const BuiltinArguments& args) { auto service = Service::MakeTemporaryOneshotService(args.args); - if (!service) { + if (!service.ok()) { return Error() << "Could not create exec background service: " << service.error(); } - if (auto result = (*service)->Start(); !result) { + if (auto result = (*service)->Start(); !result.ok()) { return Error() << "Could not start exec background service: " << result.error(); } @@ -276,7 +276,7 @@ static Result<void> do_exec_start(const BuiltinArguments& args) { return Error() << "Service not found"; } - if (auto result = service->ExecStart(); !result) { + if (auto result = service->ExecStart(); !result.ok()) { return Error() << "Could not start exec service: " << result.error(); } @@ -291,7 +291,7 @@ static Result<void> do_export(const BuiltinArguments& args) { } static Result<void> do_hostname(const BuiltinArguments& args) { - if (auto result = WriteFile("/proc/sys/kernel/hostname", args[1]); !result) { + if (auto result = WriteFile("/proc/sys/kernel/hostname", args[1]); !result.ok()) { return Error() << "Unable to write to /proc/sys/kernel/hostname: " << result.error(); } return {}; @@ -349,7 +349,7 @@ static Result<void> do_interface_restart(const BuiltinArguments& args) { static Result<void> do_interface_start(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindInterface(args[1]); if (!svc) return Error() << "interface " << args[1] << " not found"; - if (auto result = svc->Start(); !result) { + if (auto result = svc->Start(); !result.ok()) { return Error() << "Could not start interface: " << result.error(); } return {}; @@ -413,7 +413,7 @@ static Result<void> make_dir_with_options(const MkdirOptions& options) { // mkdir <path> [mode] [owner] [group] [<option> ...] static Result<void> do_mkdir(const BuiltinArguments& args) { auto options = ParseMkdir(args.args); - if (!options) return options.error(); + if (!options.ok()) return options.error(); return make_dir_with_options(*options); } @@ -681,7 +681,7 @@ static Result<void> do_mount_all(const BuiltinArguments& args) { * and return processed return code*/ initial_mount_fstab_return_code = mount_fstab_return_code; auto queue_fs_result = queue_fs_event(mount_fstab_return_code, false); - if (!queue_fs_result) { + if (!queue_fs_result.ok()) { return Error() << "queue_fs_event() failed: " << queue_fs_result.error(); } } @@ -731,7 +731,7 @@ static Result<void> do_setprop(const BuiltinArguments& args) { static Result<void> do_setrlimit(const BuiltinArguments& args) { auto rlimit = ParseRlimit(args.args); - if (!rlimit) return rlimit.error(); + if (!rlimit.ok()) return rlimit.error(); if (setrlimit(rlimit->first, &rlimit->second) == -1) { return ErrnoError() << "setrlimit failed"; @@ -742,7 +742,7 @@ static Result<void> do_setrlimit(const BuiltinArguments& args) { static Result<void> do_start(const BuiltinArguments& args) { Service* svc = ServiceList::GetInstance().FindService(args[1]); if (!svc) return Error() << "service " << args[1] << " not found"; - if (auto result = svc->Start(); !result) { + if (auto result = svc->Start(); !result.ok()) { return ErrorIgnoreEnoent() << "Could not start service: " << result.error(); } return {}; @@ -846,7 +846,7 @@ static Result<void> do_verity_update_state(const BuiltinArguments& args) { } static Result<void> do_write(const BuiltinArguments& args) { - if (auto result = WriteFile(args[1], args[2]); !result) { + if (auto result = WriteFile(args[1], args[2]); !result.ok()) { return ErrorIgnoreEnoent() << "Unable to write to file '" << args[1] << "': " << result.error(); } @@ -904,7 +904,7 @@ static Result<void> do_readahead(const BuiltinArguments& args) { } android::base::Timer t; if (S_ISREG(sb.st_mode)) { - if (auto result = readahead_file(args[1], readfully); !result) { + if (auto result = readahead_file(args[1], readfully); !result.ok()) { LOG(WARNING) << "Unable to readahead '" << args[1] << "': " << result.error(); _exit(EXIT_FAILURE); } @@ -921,7 +921,7 @@ static Result<void> do_readahead(const BuiltinArguments& args) { ftsent = fts_read(fts.get())) { if (ftsent->fts_info & FTS_F) { const std::string filename = ftsent->fts_accpath; - if (auto result = readahead_file(filename, readfully); !result) { + if (auto result = readahead_file(filename, readfully); !result.ok()) { LOG(WARNING) << "Unable to readahead '" << filename << "': " << result.error(); } @@ -938,10 +938,10 @@ static Result<void> do_readahead(const BuiltinArguments& args) { static Result<void> do_copy(const BuiltinArguments& args) { auto file_contents = ReadFile(args[1]); - if (!file_contents) { + if (!file_contents.ok()) { return Error() << "Could not read input file '" << args[1] << "': " << file_contents.error(); } - if (auto result = WriteFile(args[2], *file_contents); !result) { + if (auto result = WriteFile(args[2], *file_contents); !result.ok()) { return Error() << "Could not write to output file '" << args[2] << "': " << result.error(); } @@ -950,7 +950,7 @@ static Result<void> do_copy(const BuiltinArguments& args) { static Result<void> do_chown(const BuiltinArguments& args) { auto uid = DecodeUid(args[1]); - if (!uid) { + if (!uid.ok()) { return Error() << "Unable to decode UID for '" << args[1] << "': " << uid.error(); } @@ -960,7 +960,7 @@ static Result<void> do_chown(const BuiltinArguments& args) { if (args.size() == 4) { gid = DecodeUid(args[2]); - if (!gid) { + if (!gid.ok()) { return Error() << "Unable to decode GID for '" << args[2] << "': " << gid.error(); } } @@ -995,7 +995,7 @@ static Result<void> do_chmod(const BuiltinArguments& args) { static Result<void> do_restorecon(const BuiltinArguments& args) { auto restorecon_info = ParseRestorecon(args.args); - if (!restorecon_info) { + if (!restorecon_info.ok()) { return restorecon_info.error(); } @@ -1103,7 +1103,7 @@ static bool is_file_crypto() { static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& args, std::function<void(const std::string&)> function) { auto service = Service::MakeTemporaryOneshotService(args); - if (!service) { + if (!service.ok()) { function("MakeTemporaryOneshotService failed: " + service.error().message()); } (*service)->AddReapCallback([function](const siginfo_t& siginfo) { @@ -1111,7 +1111,7 @@ static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& ar function(StringPrintf("Exec service failed, status %d", siginfo.si_status)); } }); - if (auto result = (*service)->ExecStart(); !result) { + if (auto result = (*service)->ExecStart(); !result.ok()) { function("ExecStart failed: " + result.error().message()); } ServiceList::GetInstance().AddService(std::move(*service)); @@ -1133,7 +1133,7 @@ static Result<void> ExecVdcRebootOnFailure(const std::string& vdc_arg) { LOG(ERROR) << message << ": Rebooting into recovery, reason: " << reboot_reason; if (auto result = reboot_into_recovery( {"--prompt_and_wipe_data", "--reason="s + reboot_reason}); - !result) { + !result.ok()) { LOG(FATAL) << "Could not reboot into recovery: " << result.error(); } } else { @@ -1162,7 +1162,7 @@ static Result<void> do_remount_userdata(const BuiltinArguments& args) { if (auto rc = fs_mgr_remount_userdata_into_checkpointing(&fstab); rc < 0) { trigger_shutdown("reboot,mount_userdata_failed"); } - if (auto result = queue_fs_event(initial_mount_fstab_return_code, true); !result) { + if (auto result = queue_fs_event(initial_mount_fstab_return_code, true); !result.ok()) { return Error() << "queue_fs_event() failed: " << result.error(); } return {}; @@ -1285,16 +1285,16 @@ static Result<void> create_apex_data_dirs() { static Result<void> do_perform_apex_config(const BuiltinArguments& args) { auto create_dirs = create_apex_data_dirs(); - if (!create_dirs) { + if (!create_dirs.ok()) { return create_dirs.error(); } auto parse_configs = parse_apex_configs(); - if (!parse_configs) { + if (!parse_configs.ok()) { return parse_configs.error(); } auto update_linker_config = do_update_linker_config(args); - if (!update_linker_config) { + if (!update_linker_config.ok()) { return update_linker_config.error(); } |