]> git.sven.stormbind.net Git - sven/jattach.git/blobdiff - src/posix/psutil.c
New upstream version 2.2
[sven/jattach.git] / src / posix / psutil.c
index 9beea88f54b095c09db0b33a34985a12d9c4b0d5..d0287f598e2955c4c418be2a1e3cc24b735d5634 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2021 Andrei Pangin
+ * Copyright jattach authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -93,15 +93,14 @@ static int alt_lookup_nspid(int pid) {
                 // Check if /proc/<container-pid>/sched points back to <host-pid>
                 snprintf(path, sizeof(path), "/proc/%d/root/proc/%s/sched", pid, entry->d_name);
                 if (sched_get_host_pid(path) == pid) {
-                    closedir(dir);
-                    return atoi(entry->d_name);
+                    pid = atoi(entry->d_name);
+                    break;
                 }
             }
         }
         closedir(dir);
     }
 
-    // Could not find container pid; return host pid as the last resort
     return pid;
 }