diff options
author | Steven Laver <lavers@google.com> | 2019-08-07 15:49:52 -0700 |
---|---|---|
committer | Daniel Norman <danielnorman@google.com> | 2019-08-08 17:33:09 -0700 |
commit | 0c34c9d5c54e1d0d066a222b5902d75bfbca2d89 (patch) | |
tree | 19e6fc24c2fd0248e0e76b8db30e8a0c3dd615a1 /init/builtins.cpp | |
parent | 4ea7562fdb1d3a489178c40bd6d574d7ce610b91 (diff) | |
parent | 6220136528a29e96838bf6e18ea81dad9995cecc (diff) |
Merge RP1A.190528.001
Change-Id: I31b3fcf7dfe4a5740870d57029d10413820f413e
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 110 |
1 files changed, 17 insertions, 93 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index ce2c0ace6..3d34ac919 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -16,6 +16,7 @@ #include "builtins.h" +#include <android/api-level.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> @@ -63,6 +64,7 @@ #include "action_manager.h" #include "bootchart.h" +#include "host_init_stubs.h" #include "init.h" #include "mount_namespace.h" #include "parser.h" @@ -487,78 +489,6 @@ static void import_late(const std::vector<std::string>& args, size_t start_index if (false) DumpState(); } -/* handle_fstab - * - * Read the given fstab file and execute func on it. - */ -static Result<int> handle_fstab(const std::string& fstabfile, std::function<int(Fstab*)> func) { - /* - * Call fs_mgr_[u]mount_all() to [u]mount all filesystems. We fork(2) and - * do the call in the child to provide protection to the main init - * process if anything goes wrong (crash or memory leak), and wait for - * the child to finish in the parent. - */ - pid_t pid = fork(); - if (pid > 0) { - /* Parent. Wait for the child to return */ - int status; - int wp_ret = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); - if (wp_ret == -1) { - // Unexpected error code. We will continue anyway. - PLOG(WARNING) << "waitpid failed"; - } - - if (WIFEXITED(status)) { - return WEXITSTATUS(status); - } else { - return Error() << "child aborted"; - } - } else if (pid == 0) { - /* child, call fs_mgr_[u]mount_all() */ - - // So we can always see what fs_mgr_[u]mount_all() does. - // Only needed if someone explicitly changes the default log level in their init.rc. - android::base::ScopedLogSeverity info(android::base::INFO); - - Fstab fstab; - ReadFstabFromFile(fstabfile, &fstab); - - int child_ret = func(&fstab); - - _exit(child_ret); - } else { - return Error() << "fork() failed"; - } -} - -/* mount_fstab - * - * Call fs_mgr_mount_all() to mount the given fstab - */ -static Result<int> mount_fstab(const std::string& fstabfile, int mount_mode) { - return handle_fstab(fstabfile, [mount_mode](Fstab* fstab) { - int ret = fs_mgr_mount_all(fstab, mount_mode); - if (ret == -1) { - PLOG(ERROR) << "fs_mgr_mount_all returned an error"; - } - return ret; - }); -} - -/* umount_fstab - * - * Call fs_mgr_umount_all() to umount the given fstab - */ -static Result<int> umount_fstab(const std::string& fstabfile) { - return handle_fstab(fstabfile, [](Fstab* fstab) { - int ret = fs_mgr_umount_all(fstab); - if (ret != 0) { - PLOG(ERROR) << "fs_mgr_umount_all returned " << ret; - } - return ret; - }); -} - /* Queue event based on fs_mgr return code. * * code: return code of fs_mgr_mount_all @@ -652,7 +582,7 @@ static Result<Success> do_mount_all(const BuiltinArguments& args) { bool import_rc = true; bool queue_event = true; int mount_mode = MOUNT_MODE_DEFAULT; - const auto& fstabfile = args[1]; + const auto& fstab_file = args[1]; std::size_t path_arg_end = args.size(); const char* prop_post_fix = "default"; @@ -672,13 +602,15 @@ static Result<Success> do_mount_all(const BuiltinArguments& args) { std::string prop_name = "ro.boottime.init.mount_all."s + prop_post_fix; android::base::Timer t; - auto mount_fstab_return_code = mount_fstab(fstabfile, mount_mode); - if (!mount_fstab_return_code) { - return Error() << "mount_fstab() failed " << mount_fstab_return_code.error(); + + Fstab fstab; + if (!ReadFstabFromFile(fstab_file, &fstab)) { + return Error() << "Could not read fstab"; } + auto mount_fstab_return_code = fs_mgr_mount_all(&fstab, mount_mode); property_set(prop_name, std::to_string(t.duration().count())); - if (import_rc) { + if (import_rc && SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) { /* Paths of .rc files are specified at the 2nd argument and beyond */ import_late(args.args, 2, path_arg_end); } @@ -686,7 +618,7 @@ static Result<Success> do_mount_all(const BuiltinArguments& args) { if (queue_event) { /* queue_fs_event will queue event based on mount_fstab return code * and return processed return code*/ - auto queue_fs_result = queue_fs_event(*mount_fstab_return_code); + auto queue_fs_result = queue_fs_event(mount_fstab_return_code); if (!queue_fs_result) { return Error() << "queue_fs_event() failed: " << queue_fs_result.error(); } @@ -697,9 +629,13 @@ static Result<Success> do_mount_all(const BuiltinArguments& args) { /* umount_all <fstab> */ static Result<Success> do_umount_all(const BuiltinArguments& args) { - auto umount_fstab_return_code = umount_fstab(args[1]); - if (!umount_fstab_return_code) { - return Error() << "umount_fstab() failed " << umount_fstab_return_code.error(); + Fstab fstab; + if (!ReadFstabFromFile(args[1], &fstab)) { + return Error() << "Could not read fstab"; + } + + if (auto result = fs_mgr_umount_all(&fstab); result != 0) { + return Error() << "umount_fstab() failed " << result; } return Success(); } @@ -816,17 +752,6 @@ static Result<Success> do_sysclktz(const BuiltinArguments& args) { return Success(); } -static Result<Success> do_verity_load_state(const BuiltinArguments& args) { - int mode = -1; - bool loaded = fs_mgr_load_verity_state(&mode); - if (loaded && mode != VERITY_MODE_DEFAULT) { - ActionManager::GetInstance().QueueEventTrigger("verity-logging"); - } - if (!loaded) return Error() << "Could not load verity state"; - - return Success(); -} - static Result<Success> do_verity_update_state(const BuiltinArguments& args) { int mode; if (!fs_mgr_load_verity_state(&mode)) { @@ -1268,7 +1193,6 @@ const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { {"symlink", {2, 2, {true, do_symlink}}}, {"sysclktz", {1, 1, {false, do_sysclktz}}}, {"trigger", {1, 1, {false, do_trigger}}}, - {"verity_load_state", {0, 0, {false, do_verity_load_state}}}, {"verity_update_state", {0, 0, {false, do_verity_update_state}}}, {"wait", {1, 2, {true, do_wait}}}, {"wait_for_prop", {2, 2, {false, do_wait_for_prop}}}, |