[igt-dev] [PATCH i-g-t] lib: Don't assert if fd path is unreachable

Kamil Konieczny kamil.konieczny at linux.intel.com
Mon Jun 5 18:17:53 UTC 2023


From: Chris Wilson <chris.p.wilson at intel.com>

Processes come and go, access to the /proc/$tid/fd/ is unreliable. Don't
assert when dumping the debug info of what the process has open if that
process is already destroyed.

Cc: Sai Gowtham Ch <sai.gowtham.ch at intel.com>
Signed-off-by: Chris Wilson <chris.p.wilson at intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 lib/igt_aux.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index f2b9671e3..386e25783 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1451,16 +1451,18 @@ igt_show_stat(const pid_t tid, const char *cmd, int *state, const char *fn)
 static void
 __igt_lsof_fds(const pid_t tid, const char *cmd, int *state, char *proc_path, const char *dir)
 {
+	/* default fds or kernel threads */
+	static const char *default_fds[] = { "/dev/pts", "/dev/null" };
 	struct dirent *d;
 	struct stat st;
 	char path[PATH_MAX];
 	char *fd_lnk;
+	DIR *dp;
 
-	/* default fds or kernel threads */
-	const char *default_fds[] = { "/dev/pts", "/dev/null" };
+	dp = opendir(proc_path);
+	if (!dp)
+		return;
 
-	DIR *dp = opendir(proc_path);
-	igt_assert(dp);
 again:
 	while ((d = readdir(dp))) {
 		char *copy_fd_lnk;
@@ -1780,7 +1782,8 @@ __igt_lsof_audio_and_kill_proc(const pid_t tid, const char *cmd, const uid_t eui
 	dp = opendir(proc_path);
 	if (!dp && errno == ENOENT)
 		return 0;
-	igt_assert(dp);
+	if (!dp)
+		return 1;
 
 	while ((d = readdir(dp))) {
 		if (*d->d_name == '.')
-- 
2.39.2



More information about the igt-dev mailing list