Skip to content

Using liblsof on Darwin/MacOS, the name field is not populated for regular files #346

@neek78

Description

@neek78

Describe the bug
When running on Darwin/MacOS, lsof_file.name seems to always be NULL for regular files. When running command line lsof, the name field is populated correctly. lsof_file.name seems to be correctly populated on (at least) Linux.

To Reproduce
Steps to reproduce the behavior:

1 Run lsof_gather() against any process with an open regular file.
2. Examine lsof_file.name

Expected behavior
lsof_file.name to be populated

Environment (please complete the following information):

  • Kernel: Darwin
  • OS: MacOS 26.3
  • lsof Version: Current Git Master (63c2646)
  • Origin: Built from Git.

Additional context
It seems that void enter_vnode_info() never calls enter_nm() for regular files, as Namech is never populated.

When running in cmdline mode (ie not using liblsof directly), the name is outputted via a cache. I.e. via this mechanism -

#if defined(HASPRIVNMCACHE)
    if (HASPRIVNMCACHE(ctx, Lf)) {
        ps++;
        goto print_nma;
    }
#endif /* defined(HASPRIVNMCACHE) */

The following seems to fix the problem, but I have no idea if it's correct.

--- a/lib/dialects/darwin/dfile.c
+++ b/lib/dialects/darwin/dfile.c
@@ -205,14 +205,12 @@ void enter_vnode_info(
     /*
      * Enter name characters.
      */
+    if(!Namech[0]) {
+        snpf(Namech, Namechl, "%s", Lf->V_path);
+    }
+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions