]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-nbd: don't look for cmdline in /proc/[tid] subdirectories
authorMykola Golub <mgolub@suse.com>
Thu, 5 Nov 2020 17:46:19 +0000 (17:46 +0000)
committerMykola Golub <mgolub@suse.com>
Tue, 10 Nov 2020 17:15:59 +0000 (17:15 +0000)
The proc fs contains both /proc/[pid] and /proc/[tid]
subdirectories. The /proc/[tid] subdirectories are not visible
when listing /proc. But when checking pid for reattached process,
get_mapped_info directly tries to open /proc/[pid]/cmdline, and
it may actually be tid belonging to some other rbd-nbd
process. Try to avoid this by checking /proc/[pid]/comm first --
for pid we expect to find "rbd-nbd" here.

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/tools/rbd_nbd/rbd-nbd.cc

index a4fb7c10101fb3710e3bd261ed5b4d9ef92dd8ed..eee700a5ee8f20de0d675d1c125e8b4cc5614488 100644 (file)
@@ -827,8 +827,19 @@ private:
     m_mapped_info_cache[pid] = {};
 
     int r;
-    std::string path = "/proc/" + stringify(pid) + "/cmdline";
+    std::string path = "/proc/" + stringify(pid) + "/comm";
     std::ifstream ifs;
+    std::string comm;
+    ifs.open(path.c_str(), std::ifstream::in);
+    if (!ifs.is_open())
+      return -1;
+    ifs >> comm;
+    if (comm != "rbd-nbd") {
+      return -EINVAL;
+    }
+    ifs.close();
+
+    path = "/proc/" + stringify(pid) + "/cmdline";
     std::string cmdline;
     std::vector<const char*> args;