From: Mykola Golub Date: Thu, 5 Nov 2020 17:46:19 +0000 (+0000) Subject: rbd-nbd: don't look for cmdline in /proc/[tid] subdirectories X-Git-Tag: v16.1.0~585^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=746ac7265dd4835998f2d47803d23dc017e0ed69;p=ceph.git rbd-nbd: don't look for cmdline in /proc/[tid] subdirectories 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 --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index a4fb7c10101..eee700a5ee8 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -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 args;