lmkd: Fix lmkd-test to work with relative paths

This change allows lmkd-test to work correctly when it's started
using absolute as well as relative path.

Change-Id: Ida58d13d66a224119a363f59cc59289f0167d3c9
This commit is contained in:
Suren Baghdasaryan 2018-03-09 16:45:26 -08:00
parent 40b694d5df
commit 58dfc89613
1 changed files with 5 additions and 10 deletions

View File

@ -110,14 +110,9 @@ std::string getTextAround(const std::string& text, size_t pos,
} }
bool getExecPath(std::string &path) { bool getExecPath(std::string &path) {
char buf[PATH_MAX + 1]; // exec path as utf8z c_str().
int ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); // std::string contains _all_ nul terminated argv[] strings.
if (ret < 0) { return android::base::ReadFileToString("/proc/self/cmdline", &path);
return false;
}
buf[ret] = '\0';
path = buf;
return true;
} }
/* Child synchronization primitives */ /* Child synchronization primitives */
@ -314,8 +309,8 @@ TEST(lmkd, check_for_oom) {
if (getuid() != static_cast<unsigned>(AID_ROOT)) { if (getuid() != static_cast<unsigned>(AID_ROOT)) {
// if not root respawn itself as root and capture output // if not root respawn itself as root and capture output
std::string command = StringPrintf( std::string command = StringPrintf(
"%s=true su root %s 2>&1", LMKDTEST_RESPAWN_FLAG, "%s=true su root %s --gtest_filter=lmkd.check_for_oom 2>&1",
test_path.c_str()); LMKDTEST_RESPAWN_FLAG, test_path.c_str());
std::string test_output = readCommand(command); std::string test_output = readCommand(command);
GTEST_LOG_(INFO) << test_output; GTEST_LOG_(INFO) << test_output;
} else { } else {