lmkd: Fix killed process name reporting

Fix termination of killed process name in proc_get_name function. While at
it also fix the coding style in the function.

Test: lmkd_unit_test
Bug: 141780598
Change-Id: I3f99b3e37b9a9d0750ece94f08f0b50ac839dacb
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index f06717d..bf0ae4d 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -1321,8 +1321,9 @@
     /* gid containing AID_READPROC required */
     snprintf(path, PATH_MAX, "/proc/%d/cmdline", pid);
     fd = open(path, O_RDONLY | O_CLOEXEC);
-    if (fd == -1)
+    if (fd == -1) {
         return NULL;
+    }
     ret = read_all(fd, line, sizeof(line) - 1);
     close(fd);
     if (ret < 0) {
@@ -1330,8 +1331,11 @@
     }
 
     cp = strchr(line, ' ');
-    if (cp)
+    if (cp) {
         *cp = '\0';
+    } else {
+        line[ret] = '\0';
+    }
 
     return line;
 }