Loading cmds/dumpstate/DumpstateUtil.cpp +18 −7 Original line number Diff line number Diff line Loading @@ -48,11 +48,26 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) { sigemptyset(&child_mask); sigaddset(&child_mask, SIGCHLD); // block SIGCHLD before we check if a process has exited if (sigprocmask(SIG_BLOCK, &child_mask, &old_mask) == -1) { printf("*** sigprocmask failed: %s\n", strerror(errno)); return false; } // if the child has exited already, handle and reset signals before leaving pid_t child_pid = waitpid(pid, status, WNOHANG); if (child_pid != pid) { if (child_pid > 0) { printf("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid); sigprocmask(SIG_SETMASK, &old_mask, nullptr); return false; } } else { sigprocmask(SIG_SETMASK, &old_mask, nullptr); return true; } // wait for a SIGCHLD timespec ts; ts.tv_sec = MSEC_TO_SEC(timeout_ms); ts.tv_nsec = (timeout_ms % 1000) * 1000000; Loading @@ -76,7 +91,7 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) { return false; } pid_t child_pid = waitpid(pid, status, WNOHANG); child_pid = waitpid(pid, status, WNOHANG); if (child_pid != pid) { if (child_pid != -1) { printf("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid); Loading Loading @@ -232,7 +247,6 @@ int DumpFileToFd(int out_fd, const std::string& title, const std::string& path) dprintf(out_fd, "*** Error dumping %s (%s): %s\n", path.c_str(), title.c_str(), strerror(err)); } fsync(out_fd); return -1; } return DumpFileFromFdToFd(title, path, fd.get(), out_fd, PropertiesHelper::IsDryRun()); Loading Loading @@ -280,7 +294,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri if (!title.empty()) { dprintf(fd, "------ %s (%s) ------\n", title.c_str(), command); fsync(fd); } const std::string& logging_message = options.LoggingMessage(); Loading @@ -299,14 +312,13 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri // There is no title, but we should still print a dry-run message dprintf(fd, "%s: skipped on dry run\n", command_string.c_str()); } fsync(fd); return 0; } const char* path = args[0]; uint64_t start = Nanotime(); pid_t pid = fork(); pid_t pid = vfork(); /* handle error case */ if (pid < 0) { Loading @@ -323,7 +335,7 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri strerror(errno)); } MYLOGE("*** could not drop root before running %s: %s\n", command, strerror(errno)); return -1; _exit(EXIT_FAILURE); } if (options.ShouldCloseAllFileDescriptorsOnExec()) { Loading Loading @@ -376,7 +388,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri /* handle parent case */ int status; bool ret = waitpid_with_timeout(pid, options.TimeoutInMs(), &status); fsync(fd); uint64_t elapsed = Nanotime() - start; if (!ret) { Loading cmds/installd/Android.bp +2 −5 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ package { cc_defaults { name: "installd_defaults", cpp_std: "c++2a", cflags: [ "-Wall", "-Werror", Loading Loading @@ -42,7 +41,6 @@ cc_defaults { "libbinder", "libcrypto", "libcutils", "libext2_uuid", "liblog", "liblogwrap", "libprocessgroup", Loading @@ -53,6 +51,7 @@ cc_defaults { ], static_libs: [ "libasync_safe", "libext2_uuid", ], export_shared_lib_headers: [ "libbinder", Loading Loading @@ -241,8 +240,6 @@ cc_library_static { cc_binary { name: "otapreopt", cpp_std: "c++2a", cflags: [ "-Wall", "-Werror", Loading @@ -266,13 +263,13 @@ cc_binary { "libasync_safe", "libdiskusage", "libotapreoptparameters", "libext2_uuid", ], shared_libs: [ "libbase", "libcrypto", "libcutils", "libext2_uuid", "liblog", "liblogwrap", "libprocessgroup", Loading cmds/installd/tests/Android.bp +62 −19 Original line number Diff line number Diff line Loading @@ -8,54 +8,56 @@ package { default_applicable_licenses: ["frameworks_native_license"], } cc_defaults { name: "installd_tests_defaults", cc_test { name: "installd_utils_test", test_suites: ["device-tests"], clang: true, cpp_std: "c++2a", srcs: ["installd_utils_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libext2_uuid", "libutils", "libcutils", ], static_libs: [ "liblog", ], } cc_test { name: "installd_utils_test", defaults: ["installd_tests_defaults"], srcs: ["installd_utils_test.cpp"], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "liblog", ], test_config: "installd_utils_test.xml", } cc_test { name: "installd_cache_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_cache_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "libziparchive", "liblog", "liblogwrap", ], test_config: "installd_cache_test.xml", Loading @@ -78,21 +80,31 @@ cc_test { cc_test { name: "installd_service_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_service_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "packagemanager_aidl-cpp", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "libziparchive", "liblog", "liblogwrap", ], test_config: "installd_service_test.xml", Loading @@ -115,19 +127,29 @@ cc_test { cc_test { name: "installd_dexopt_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_dexopt_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "liblog", "liblogwrap", "libziparchive", "libz", Loading @@ -152,21 +174,42 @@ cc_test { cc_test { name: "installd_otapreopt_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_otapreopt_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libutils", "server_configurable_flags", ], static_libs: [ "liblog", "libotapreoptparameters", ], } cc_test { name: "installd_file_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_file_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libutils", ], static_libs: [ "libext2_uuid", "libinstalld", "liblog", ], } cmds/installd/tests/installd_service_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ static bool find_file(const char* path, Pred&& pred) { } static bool exists_renamed_deleted_dir() { return find_file(kTestPath, [](std::string_view name, bool is_dir) { return find_file(kTestPath, [](const std::string& name, bool is_dir) { return is_dir && is_renamed_deleted_dir(name); }); } Loading cmds/installd/tests/installd_utils_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -555,6 +555,24 @@ TEST_F(UtilsTest, MatchExtension_Invalid) { EXPECT_EQ(0, MatchExtension("docx")); } TEST_F(UtilsTest, TestIsRenamedDeletedDir) { EXPECT_FALSE(is_renamed_deleted_dir("")); EXPECT_FALSE(is_renamed_deleted_dir("1")); EXPECT_FALSE(is_renamed_deleted_dir("=")); EXPECT_FALSE(is_renamed_deleted_dir("==")); EXPECT_FALSE(is_renamed_deleted_dir("d==")); EXPECT_FALSE(is_renamed_deleted_dir("ed==")); EXPECT_FALSE(is_renamed_deleted_dir("ted==")); EXPECT_FALSE(is_renamed_deleted_dir("eted==")); EXPECT_FALSE(is_renamed_deleted_dir("leted==")); EXPECT_FALSE(is_renamed_deleted_dir("eleted==")); EXPECT_FALSE(is_renamed_deleted_dir("deleted==")); EXPECT_FALSE(is_renamed_deleted_dir("=deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("==deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("123==deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("5b14b6458a44==deleted==")); } TEST_F(UtilsTest, TestRollbackPaths) { EXPECT_EQ("/data/misc_ce/0/rollback/239/com.foo", create_data_misc_ce_rollback_package_path(nullptr, 0, 239, "com.foo")); Loading Loading
cmds/dumpstate/DumpstateUtil.cpp +18 −7 Original line number Diff line number Diff line Loading @@ -48,11 +48,26 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) { sigemptyset(&child_mask); sigaddset(&child_mask, SIGCHLD); // block SIGCHLD before we check if a process has exited if (sigprocmask(SIG_BLOCK, &child_mask, &old_mask) == -1) { printf("*** sigprocmask failed: %s\n", strerror(errno)); return false; } // if the child has exited already, handle and reset signals before leaving pid_t child_pid = waitpid(pid, status, WNOHANG); if (child_pid != pid) { if (child_pid > 0) { printf("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid); sigprocmask(SIG_SETMASK, &old_mask, nullptr); return false; } } else { sigprocmask(SIG_SETMASK, &old_mask, nullptr); return true; } // wait for a SIGCHLD timespec ts; ts.tv_sec = MSEC_TO_SEC(timeout_ms); ts.tv_nsec = (timeout_ms % 1000) * 1000000; Loading @@ -76,7 +91,7 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_ms, int* status) { return false; } pid_t child_pid = waitpid(pid, status, WNOHANG); child_pid = waitpid(pid, status, WNOHANG); if (child_pid != pid) { if (child_pid != -1) { printf("*** Waiting for pid %d, got pid %d instead\n", pid, child_pid); Loading Loading @@ -232,7 +247,6 @@ int DumpFileToFd(int out_fd, const std::string& title, const std::string& path) dprintf(out_fd, "*** Error dumping %s (%s): %s\n", path.c_str(), title.c_str(), strerror(err)); } fsync(out_fd); return -1; } return DumpFileFromFdToFd(title, path, fd.get(), out_fd, PropertiesHelper::IsDryRun()); Loading Loading @@ -280,7 +294,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri if (!title.empty()) { dprintf(fd, "------ %s (%s) ------\n", title.c_str(), command); fsync(fd); } const std::string& logging_message = options.LoggingMessage(); Loading @@ -299,14 +312,13 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri // There is no title, but we should still print a dry-run message dprintf(fd, "%s: skipped on dry run\n", command_string.c_str()); } fsync(fd); return 0; } const char* path = args[0]; uint64_t start = Nanotime(); pid_t pid = fork(); pid_t pid = vfork(); /* handle error case */ if (pid < 0) { Loading @@ -323,7 +335,7 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri strerror(errno)); } MYLOGE("*** could not drop root before running %s: %s\n", command, strerror(errno)); return -1; _exit(EXIT_FAILURE); } if (options.ShouldCloseAllFileDescriptorsOnExec()) { Loading Loading @@ -376,7 +388,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri /* handle parent case */ int status; bool ret = waitpid_with_timeout(pid, options.TimeoutInMs(), &status); fsync(fd); uint64_t elapsed = Nanotime() - start; if (!ret) { Loading
cmds/installd/Android.bp +2 −5 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ package { cc_defaults { name: "installd_defaults", cpp_std: "c++2a", cflags: [ "-Wall", "-Werror", Loading Loading @@ -42,7 +41,6 @@ cc_defaults { "libbinder", "libcrypto", "libcutils", "libext2_uuid", "liblog", "liblogwrap", "libprocessgroup", Loading @@ -53,6 +51,7 @@ cc_defaults { ], static_libs: [ "libasync_safe", "libext2_uuid", ], export_shared_lib_headers: [ "libbinder", Loading Loading @@ -241,8 +240,6 @@ cc_library_static { cc_binary { name: "otapreopt", cpp_std: "c++2a", cflags: [ "-Wall", "-Werror", Loading @@ -266,13 +263,13 @@ cc_binary { "libasync_safe", "libdiskusage", "libotapreoptparameters", "libext2_uuid", ], shared_libs: [ "libbase", "libcrypto", "libcutils", "libext2_uuid", "liblog", "liblogwrap", "libprocessgroup", Loading
cmds/installd/tests/Android.bp +62 −19 Original line number Diff line number Diff line Loading @@ -8,54 +8,56 @@ package { default_applicable_licenses: ["frameworks_native_license"], } cc_defaults { name: "installd_tests_defaults", cc_test { name: "installd_utils_test", test_suites: ["device-tests"], clang: true, cpp_std: "c++2a", srcs: ["installd_utils_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libext2_uuid", "libutils", "libcutils", ], static_libs: [ "liblog", ], } cc_test { name: "installd_utils_test", defaults: ["installd_tests_defaults"], srcs: ["installd_utils_test.cpp"], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "liblog", ], test_config: "installd_utils_test.xml", } cc_test { name: "installd_cache_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_cache_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "libziparchive", "liblog", "liblogwrap", ], test_config: "installd_cache_test.xml", Loading @@ -78,21 +80,31 @@ cc_test { cc_test { name: "installd_service_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_service_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "packagemanager_aidl-cpp", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "libziparchive", "liblog", "liblogwrap", ], test_config: "installd_service_test.xml", Loading @@ -115,19 +127,29 @@ cc_test { cc_test { name: "installd_dexopt_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_dexopt_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libbinder", "libcrypto", "libcutils", "libprocessgroup", "libselinux", "libutils", "server_configurable_flags", ], static_libs: [ "libasync_safe", "libdiskusage", "libext2_uuid", "libinstalld", "liblog", "liblogwrap", "libziparchive", "libz", Loading @@ -152,21 +174,42 @@ cc_test { cc_test { name: "installd_otapreopt_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_otapreopt_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libutils", "server_configurable_flags", ], static_libs: [ "liblog", "libotapreoptparameters", ], } cc_test { name: "installd_file_test", defaults: ["installd_tests_defaults"], test_suites: ["device-tests"], clang: true, srcs: ["installd_file_test.cpp"], cflags: [ "-Wall", "-Werror", ], shared_libs: [ "libbase", "libcutils", "libutils", ], static_libs: [ "libext2_uuid", "libinstalld", "liblog", ], }
cmds/installd/tests/installd_service_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ static bool find_file(const char* path, Pred&& pred) { } static bool exists_renamed_deleted_dir() { return find_file(kTestPath, [](std::string_view name, bool is_dir) { return find_file(kTestPath, [](const std::string& name, bool is_dir) { return is_dir && is_renamed_deleted_dir(name); }); } Loading
cmds/installd/tests/installd_utils_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -555,6 +555,24 @@ TEST_F(UtilsTest, MatchExtension_Invalid) { EXPECT_EQ(0, MatchExtension("docx")); } TEST_F(UtilsTest, TestIsRenamedDeletedDir) { EXPECT_FALSE(is_renamed_deleted_dir("")); EXPECT_FALSE(is_renamed_deleted_dir("1")); EXPECT_FALSE(is_renamed_deleted_dir("=")); EXPECT_FALSE(is_renamed_deleted_dir("==")); EXPECT_FALSE(is_renamed_deleted_dir("d==")); EXPECT_FALSE(is_renamed_deleted_dir("ed==")); EXPECT_FALSE(is_renamed_deleted_dir("ted==")); EXPECT_FALSE(is_renamed_deleted_dir("eted==")); EXPECT_FALSE(is_renamed_deleted_dir("leted==")); EXPECT_FALSE(is_renamed_deleted_dir("eleted==")); EXPECT_FALSE(is_renamed_deleted_dir("deleted==")); EXPECT_FALSE(is_renamed_deleted_dir("=deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("==deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("123==deleted==")); EXPECT_TRUE(is_renamed_deleted_dir("5b14b6458a44==deleted==")); } TEST_F(UtilsTest, TestRollbackPaths) { EXPECT_EQ("/data/misc_ce/0/rollback/239/com.foo", create_data_misc_ce_rollback_package_path(nullptr, 0, 239, "com.foo")); Loading