Loading cmds/dumpstate/DumpstateUtil.cpp +0 −28 Original line number Original line Diff line number Diff line Loading @@ -378,34 +378,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri return status; return status; } } int GetPidByName(const std::string& ps_name) { DIR* proc_dir; struct dirent* ps; unsigned int pid; std::string cmdline; if (!(proc_dir = opendir("/proc"))) { MYLOGE("Can't open /proc\n"); return -1; } while ((ps = readdir(proc_dir))) { if (!(pid = atoi(ps->d_name))) { continue; } android::base::ReadFileToString("/proc/" + std::string(ps->d_name) + "/cmdline", &cmdline); if (cmdline.find(ps_name) == std::string::npos) { continue; } else { closedir(proc_dir); return pid; } } MYLOGE("can't find the pid\n"); closedir(proc_dir); return -1; } } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android cmds/dumpstate/DumpstateUtil.h +0 −6 Original line number Original line Diff line number Diff line Loading @@ -205,12 +205,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri */ */ int DumpFileToFd(int fd, const std::string& title, const std::string& path); int DumpFileToFd(int fd, const std::string& title, const std::string& path); /* * Finds the process id by process name. * |ps_name| the process name we want to search for */ int GetPidByName(const std::string& ps_name); } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android Loading cmds/dumpstate/tests/dumpstate_test.cpp +0 −20 Original line number Original line Diff line number Diff line Loading @@ -1406,14 +1406,6 @@ class DumpstateUtilTest : public DumpstateBaseTest { return status; return status; } } // Find out the pid of the process_name int FindPidOfProcess(const std::string& process_name) { CaptureStderr(); int status = GetPidByName(process_name); err = GetCapturedStderr(); return status; } int fd; int fd; // 'fd` output and `stderr` from the last command ran. // 'fd` output and `stderr` from the last command ran. Loading Loading @@ -1763,18 +1755,6 @@ TEST_F(DumpstateUtilTest, DumpFileOnDryRun) { EXPECT_THAT(out, EndsWith("skipped on dry run\n")); EXPECT_THAT(out, EndsWith("skipped on dry run\n")); } } TEST_F(DumpstateUtilTest, FindingPidWithExistingProcess) { // init process always has pid 1. EXPECT_EQ(1, FindPidOfProcess("init")); EXPECT_THAT(err, IsEmpty()); } TEST_F(DumpstateUtilTest, FindingPidWithNotExistingProcess) { // find the process with abnormal name. EXPECT_EQ(-1, FindPidOfProcess("abcdef12345-543")); EXPECT_THAT(err, StrEq("can't find the pid\n")); } } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android Loading
cmds/dumpstate/DumpstateUtil.cpp +0 −28 Original line number Original line Diff line number Diff line Loading @@ -378,34 +378,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri return status; return status; } } int GetPidByName(const std::string& ps_name) { DIR* proc_dir; struct dirent* ps; unsigned int pid; std::string cmdline; if (!(proc_dir = opendir("/proc"))) { MYLOGE("Can't open /proc\n"); return -1; } while ((ps = readdir(proc_dir))) { if (!(pid = atoi(ps->d_name))) { continue; } android::base::ReadFileToString("/proc/" + std::string(ps->d_name) + "/cmdline", &cmdline); if (cmdline.find(ps_name) == std::string::npos) { continue; } else { closedir(proc_dir); return pid; } } MYLOGE("can't find the pid\n"); closedir(proc_dir); return -1; } } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android
cmds/dumpstate/DumpstateUtil.h +0 −6 Original line number Original line Diff line number Diff line Loading @@ -205,12 +205,6 @@ int RunCommandToFd(int fd, const std::string& title, const std::vector<std::stri */ */ int DumpFileToFd(int fd, const std::string& title, const std::string& path); int DumpFileToFd(int fd, const std::string& title, const std::string& path); /* * Finds the process id by process name. * |ps_name| the process name we want to search for */ int GetPidByName(const std::string& ps_name); } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android Loading
cmds/dumpstate/tests/dumpstate_test.cpp +0 −20 Original line number Original line Diff line number Diff line Loading @@ -1406,14 +1406,6 @@ class DumpstateUtilTest : public DumpstateBaseTest { return status; return status; } } // Find out the pid of the process_name int FindPidOfProcess(const std::string& process_name) { CaptureStderr(); int status = GetPidByName(process_name); err = GetCapturedStderr(); return status; } int fd; int fd; // 'fd` output and `stderr` from the last command ran. // 'fd` output and `stderr` from the last command ran. Loading Loading @@ -1763,18 +1755,6 @@ TEST_F(DumpstateUtilTest, DumpFileOnDryRun) { EXPECT_THAT(out, EndsWith("skipped on dry run\n")); EXPECT_THAT(out, EndsWith("skipped on dry run\n")); } } TEST_F(DumpstateUtilTest, FindingPidWithExistingProcess) { // init process always has pid 1. EXPECT_EQ(1, FindPidOfProcess("init")); EXPECT_THAT(err, IsEmpty()); } TEST_F(DumpstateUtilTest, FindingPidWithNotExistingProcess) { // find the process with abnormal name. EXPECT_EQ(-1, FindPidOfProcess("abcdef12345-543")); EXPECT_THAT(err, StrEq("can't find the pid\n")); } } // namespace dumpstate } // namespace dumpstate } // namespace os } // namespace os } // namespace android } // namespace android