drgn/contrib/find_struct_file.py
Omar Sandoval bbaf608af0 contrib: add find_struct_file.py
I used this to find some missing sockets that weren't showing up in lsof
or ss.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-10-13 16:39:17 -07:00

24 lines
648 B
Python
Executable File

#!/usr/bin/env drgn
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later
"""Find what process is using a struct file *, given as an address."""
import sys
from drgn import Object
from drgn.helpers.linux.fs import for_each_file
from drgn.helpers.linux.pid import for_each_task
file = Object(prog, "struct file *", int(sys.argv[1], 0))
for task in for_each_task(prog):
for fd, file2 in for_each_file(task):
if file2 == file:
break
else:
continue
break
else:
print("Not found:(")
print(f"PID {task.pid.value_()} COMM {task.comm.string_().decode()} FD {fd}")