assert(pid >= 0);
- if (pid == 0 || pid == getpid_cached()) {
+ if (pid == 0)
+ pid = getpid_cached();
+ if (pid == 1) /* PID 1 has no parent, shortcut this case */
+ return -EADDRNOTAVAIL;
+
+ if (pid == getpid_cached()) {
if (ret)
*ret = getppid();
return 0;
}
- if (pid == 1) /* PID 1 has no parent, shortcut this case */
- return -EADDRNOTAVAIL;
-
p = procfs_file_alloca(pid, "stat");
r = read_one_line_file(p, &line);
if (r == -ENOENT)
p = strrchr(line, ')');
if (!p)
return -EIO;
-
p++;
if (sscanf(p, " "
&ppid) != 1)
return -EIO;
- /* If ppid is zero the process has no parent. Which might be the case for PID 1 but also for
- * processes originating in other namespaces that are inserted into a pidns. Return a recognizable
- * error in this case. */
+ /* If ppid is zero the process has no parent. Which might be the case for PID 1 (caught above)
+ * but also for processes originating in other namespaces that are inserted into a pidns.
+ * Return a recognizable error in this case. */
if (ppid == 0)
return -EADDRNOTAVAIL;