@@ -101,6 +101,7 @@ class LinuxUtilities(interfaces.configuration.VersionableInterface):
101101
102102 _version = (2 , 3 , 1 )
103103 _required_framework_version = (2 , 0 , 0 )
104+ deleted = " (deleted)"
104105
105106 framework .require_interface_version (* _required_framework_version )
106107
@@ -168,6 +169,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
168169 # vfsmnt can be the vfsmount object itself (>=3.3) or a vfsmount * (<3.3)
169170 return ""
170171
172+ inode = dentry .d_inode
171173 path_reversed = []
172174 smeared = False
173175 while (
@@ -191,6 +193,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
191193
192194 parent = dentry .d_parent
193195 dname = dentry .d_name .name_as_str ()
196+
194197 # empty dentry names are most likely
195198 # the result of smearing
196199 if not dname :
@@ -204,6 +207,9 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
204207 # path would be /foo/bar/baz, but bar is missing due to smear the results
205208 # returned here will show /foo//baz. Note the // for the missing dname.
206209 return f"<potentially smeared> { path } "
210+ print (path , inode .i_nlink )
211+ if inode and inode .is_readable () and inode .is_valid () and inode .i_nlink == 0 :
212+ path += LinuxUtilities .deleted
207213 return path
208214
209215 @classmethod
@@ -260,7 +266,7 @@ def _get_new_sock_pipe_path(cls, context, task, filp) -> str:
260266 pre_name = name .dereference ().cast (
261267 "string" , max_length = 255 , errors = "replace"
262268 )
263- return "/" + pre_name + " ( deleted)"
269+ return "/" + pre_name + LinuxUtilities . deleted
264270 else :
265271 pre_name = ""
266272
@@ -301,7 +307,7 @@ def _get_new_sock_pipe_path(cls, context, task, filp) -> str:
301307 return f"{ pre_name } :[{ inode .i_ino :d} ]"
302308
303309 @classmethod
304- def path_for_file (cls , context , task , filp ) -> str :
310+ def path_for_file (cls , context , task , filp , files_only ) -> str :
305311 """Returns a file (or sock pipe) pathname relative to the task's root directory.
306312
307313 A 'file' structure doesn't have enough information to properly restore its
@@ -340,7 +346,7 @@ def path_for_file(cls, context, task, filp) -> str:
340346 except exceptions .InvalidAddressException :
341347 dname_is_valid = False
342348
343- if dname_is_valid :
349+ if dname_is_valid and not files_only :
344350 ret = LinuxUtilities ._get_new_sock_pipe_path (context , task , filp )
345351 else :
346352 ret = LinuxUtilities ._get_path_file (task , filp )
@@ -353,6 +359,7 @@ def files_descriptors_for_process(
353359 context : interfaces .context .ContextInterface ,
354360 symbol_table : str ,
355361 task : interfaces .objects .ObjectInterface ,
362+ files_only : bool = False ,
356363 ):
357364 try :
358365 files = task .files
@@ -376,7 +383,9 @@ def files_descriptors_for_process(
376383
377384 for fd_num , filp in enumerate (fds ):
378385 if filp and filp .is_readable ():
379- full_path = LinuxUtilities .path_for_file (context , task , filp )
386+ full_path = LinuxUtilities .path_for_file (
387+ context , task , filp , files_only
388+ )
380389
381390 yield fd_num , filp , full_path
382391
0 commit comments