Loading init/builtins.cpp +6 −21 Original line number Diff line number Diff line Loading @@ -640,12 +640,7 @@ static Result<void> do_mount_all(const BuiltinArguments& args) { if (!ReadFstabFromFile(fstab_file, &fstab)) { return Error() << "Could not read fstab"; } auto mount_fstab_return_code = CallFunctionAndHandleProperties(fs_mgr_mount_all, &fstab, mount_mode); if (!mount_fstab_return_code) { return Error() << "Could not call fs_mgr_mount_all(): " << mount_fstab_return_code.error(); } 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 && SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) { Loading @@ -656,7 +651,7 @@ static Result<void> 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(); } Loading @@ -672,13 +667,8 @@ static Result<void> do_umount_all(const BuiltinArguments& args) { return Error() << "Could not read fstab"; } auto result = CallFunctionAndHandleProperties(fs_mgr_umount_all, &fstab); if (!result) { return Error() << "Could not call fs_mgr_mount_all() " << result.error(); } if (*result != 0) { return Error() << "fs_mgr_mount_all() failed: " << *result; if (auto result = fs_mgr_umount_all(&fstab); result != 0) { return Error() << "umount_fstab() failed " << result; } return {}; } Loading @@ -689,13 +679,8 @@ static Result<void> do_swapon_all(const BuiltinArguments& args) { return Error() << "Could not read fstab '" << args[1] << "'"; } auto result = CallFunctionAndHandleProperties(fs_mgr_swapon_all, fstab); if (!result) { return Error() << "Could not call fs_mgr_swapon_all() " << result.error(); } if (*result == 0) { return Error() << "fs_mgr_swapon_all() failed."; if (!fs_mgr_swapon_all(fstab)) { return Error() << "fs_mgr_swapon_all() failed"; } return {}; Loading init/property_service.cpp +1 −40 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> #include <atomic> #include <map> #include <memory> #include <mutex> Loading @@ -53,7 +52,6 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <property_info_parser/property_info_parser.h> #include <property_info_serializer/property_info_serializer.h> #include <selinux/android.h> Loading @@ -61,6 +59,7 @@ #include <selinux/selinux.h> #include "debug_ramdisk.h" #include "epoll.h" #include "init.h" #include "persistent_properties.h" #include "property_type.h" Loading @@ -77,7 +76,6 @@ using android::base::StartsWith; using android::base::StringPrintf; using android::base::Timer; using android::base::Trim; using android::base::unique_fd; using android::base::WriteStringToFile; using android::properties::BuildTrie; using android::properties::ParsePropertyInfoFile; Loading Loading @@ -1004,42 +1002,5 @@ void StartPropertyService(Epoll* epoll) { } } Result<int> CallFunctionAndHandlePropertiesImpl(const std::function<int()>& f) { unique_fd reader; unique_fd writer; if (!Socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, &reader, &writer)) { return ErrnoError() << "Could not create socket pair"; } int result = 0; std::atomic<bool> end = false; auto thread = std::thread{[&f, &result, &end, &writer] { result = f(); end = true; send(writer, "1", 1, 0); }}; Epoll epoll; if (auto result = epoll.Open(); !result) { return Error() << "Could not create epoll: " << result.error(); } if (auto result = epoll.RegisterHandler(property_set_fd, handle_property_set_fd); !result) { return Error() << "Could not register epoll handler for property fd: " << result.error(); } // No-op function, just used to break from loop. if (auto result = epoll.RegisterHandler(reader, [] {}); !result) { return Error() << "Could not register epoll handler for ending thread:" << result.error(); } while (!end) { epoll.Wait({}); } thread.join(); return result; } } // namespace init } // namespace android init/property_service.h +0 −10 Original line number Diff line number Diff line Loading @@ -18,11 +18,9 @@ #include <sys/socket.h> #include <functional> #include <string> #include "epoll.h" #include "result.h" namespace android { namespace init { Loading @@ -39,13 +37,5 @@ void property_load_boot_defaults(bool load_debug_prop); void load_persist_props(); void StartPropertyService(Epoll* epoll); template <typename F, typename... Args> Result<int> CallFunctionAndHandleProperties(F&& f, Args&&... args) { Result<int> CallFunctionAndHandlePropertiesImpl(const std::function<int()>& f); auto func = [&] { return f(args...); }; return CallFunctionAndHandlePropertiesImpl(func); } } // namespace init } // namespace android Loading
init/builtins.cpp +6 −21 Original line number Diff line number Diff line Loading @@ -640,12 +640,7 @@ static Result<void> do_mount_all(const BuiltinArguments& args) { if (!ReadFstabFromFile(fstab_file, &fstab)) { return Error() << "Could not read fstab"; } auto mount_fstab_return_code = CallFunctionAndHandleProperties(fs_mgr_mount_all, &fstab, mount_mode); if (!mount_fstab_return_code) { return Error() << "Could not call fs_mgr_mount_all(): " << mount_fstab_return_code.error(); } 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 && SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) { Loading @@ -656,7 +651,7 @@ static Result<void> 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(); } Loading @@ -672,13 +667,8 @@ static Result<void> do_umount_all(const BuiltinArguments& args) { return Error() << "Could not read fstab"; } auto result = CallFunctionAndHandleProperties(fs_mgr_umount_all, &fstab); if (!result) { return Error() << "Could not call fs_mgr_mount_all() " << result.error(); } if (*result != 0) { return Error() << "fs_mgr_mount_all() failed: " << *result; if (auto result = fs_mgr_umount_all(&fstab); result != 0) { return Error() << "umount_fstab() failed " << result; } return {}; } Loading @@ -689,13 +679,8 @@ static Result<void> do_swapon_all(const BuiltinArguments& args) { return Error() << "Could not read fstab '" << args[1] << "'"; } auto result = CallFunctionAndHandleProperties(fs_mgr_swapon_all, fstab); if (!result) { return Error() << "Could not call fs_mgr_swapon_all() " << result.error(); } if (*result == 0) { return Error() << "fs_mgr_swapon_all() failed."; if (!fs_mgr_swapon_all(fstab)) { return Error() << "fs_mgr_swapon_all() failed"; } return {}; Loading
init/property_service.cpp +1 −40 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> #include <atomic> #include <map> #include <memory> #include <mutex> Loading @@ -53,7 +52,6 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <property_info_parser/property_info_parser.h> #include <property_info_serializer/property_info_serializer.h> #include <selinux/android.h> Loading @@ -61,6 +59,7 @@ #include <selinux/selinux.h> #include "debug_ramdisk.h" #include "epoll.h" #include "init.h" #include "persistent_properties.h" #include "property_type.h" Loading @@ -77,7 +76,6 @@ using android::base::StartsWith; using android::base::StringPrintf; using android::base::Timer; using android::base::Trim; using android::base::unique_fd; using android::base::WriteStringToFile; using android::properties::BuildTrie; using android::properties::ParsePropertyInfoFile; Loading Loading @@ -1004,42 +1002,5 @@ void StartPropertyService(Epoll* epoll) { } } Result<int> CallFunctionAndHandlePropertiesImpl(const std::function<int()>& f) { unique_fd reader; unique_fd writer; if (!Socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, &reader, &writer)) { return ErrnoError() << "Could not create socket pair"; } int result = 0; std::atomic<bool> end = false; auto thread = std::thread{[&f, &result, &end, &writer] { result = f(); end = true; send(writer, "1", 1, 0); }}; Epoll epoll; if (auto result = epoll.Open(); !result) { return Error() << "Could not create epoll: " << result.error(); } if (auto result = epoll.RegisterHandler(property_set_fd, handle_property_set_fd); !result) { return Error() << "Could not register epoll handler for property fd: " << result.error(); } // No-op function, just used to break from loop. if (auto result = epoll.RegisterHandler(reader, [] {}); !result) { return Error() << "Could not register epoll handler for ending thread:" << result.error(); } while (!end) { epoll.Wait({}); } thread.join(); return result; } } // namespace init } // namespace android
init/property_service.h +0 −10 Original line number Diff line number Diff line Loading @@ -18,11 +18,9 @@ #include <sys/socket.h> #include <functional> #include <string> #include "epoll.h" #include "result.h" namespace android { namespace init { Loading @@ -39,13 +37,5 @@ void property_load_boot_defaults(bool load_debug_prop); void load_persist_props(); void StartPropertyService(Epoll* epoll); template <typename F, typename... Args> Result<int> CallFunctionAndHandleProperties(F&& f, Args&&... args) { Result<int> CallFunctionAndHandlePropertiesImpl(const std::function<int()>& f); auto func = [&] { return f(args...); }; return CallFunctionAndHandlePropertiesImpl(func); } } // namespace init } // namespace android