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

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Wed Jun 7 06:31:26 UTC 2023


On Mon, Jun 05, 2023 at 08:17:53PM +0200, Kamil Konieczny wrote:
> 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);

Ok, asserting on missing process is not good idea. I would just
add some igt_warn() or igt_debug() about missing process in this case.
Regardless decision to add this or not:

Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

--
Zbigniew

>  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