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>
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;