Skip to content

Commit ce96381

Browse files
committed
[linux] fix: memory-mapped file, stat: No such file or directory
In old linux kernel (e.g. linux-2.6) which does not have this feature: Commit 6b4e306aa3dc ("ns: proc files for namespace naming policy."), means this path "/proc/self/ns" is not existed. Since lsof-4.96.0 with Commit dbad150 (" [linux] obtain correct information of memory-mapped file."), compare_mntns() would misunderstand it is in a different mount namespace if "/proc/self/ns" is not existed, returns -1, go through map_files lookup, and finally lead to lsof gets failed with error message "stat: No such file or directory". If "/proc/self/ns" or its underlying path is not existed, compare_mntns() returns 0 instead of -1, in order to go through stat_directly as old days. Signed-off-by: Jones Syue <jones_syue@askey.com>
1 parent bbf320c commit ce96381

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/dialects/linux/dproc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,14 +1370,14 @@ static int compare_mntns(int pid) /* pid of the target process */
13701370
int ret;
13711371

13721372
if (stat("/proc/self/ns/mnt", &sb_self))
1373-
return -1;
1373+
return 0;
13741374

13751375
ret = snprintf(nspath, sizeof(nspath), "/proc/%d/ns/mnt", pid);
13761376
if (ret >= sizeof(nspath) || ret <= 0)
1377-
return -1;
1377+
return 0;
13781378

13791379
if (stat(nspath, &sb_target))
1380-
return -1;
1380+
return 0;
13811381

13821382
if (sb_self.st_ino != sb_target.st_ino)
13831383
return -1;

0 commit comments

Comments
 (0)