dumpstate: Properly handle unfound pid
The function GetPidByName() returns -1 if we can't find the
pid. But since we had 'pid' as unsigned, this became a huge
positive number for us, and we didn't fail the "pid > 0" check
as expected.
We switch 'pid' to a signed int, so now this logic flows as
expected.
Test: Grab a bugreport on a device without /system/bin/anrd and confirm we no longer get the "Failed to find" error in logcat.
Change-Id: I83bcbbe3f189a705fd0ad83ae600c45196048a3f
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 0ac3e93..4ede29f 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -401,7 +401,7 @@
// 2. send a SIGUSR1 to its pid which will dump anrd's trace.
// 3. wait until the trace generation completes and add to the zip file.
static bool dump_anrd_trace() {
- unsigned int pid;
+ int pid;
char buf[50], path[PATH_MAX];
struct dirent *trace;
struct stat st;
@@ -428,7 +428,7 @@
}
// send SIGUSR1 to the anrd to generate a trace.
- sprintf(buf, "%u", pid);
+ sprintf(buf, "%d", pid);
if (RunCommand("ANRD_DUMP", {"kill", "-SIGUSR1", buf},
CommandOptions::WithTimeout(1).Build())) {
MYLOGE("anrd signal timed out. Please manually collect trace\n");