[PATCH v2 1/6] Split printdev() into functions for printing and getting information about fd

Dmitry V. Levin ldv at altlinux.org
Sat Mar 12 15:22:17 UTC 2022


On Sat, Mar 12, 2022 at 03:02:04AM +0900, Masatake YAMATO wrote:
[...]
> diff --git a/src/util.c b/src/util.c
> index d0de13ada..6e61333f1 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -631,33 +631,60 @@ printsocket(struct tcb *tcp, int fd, const char *path)
>  	return false;
>  }
>  
> -static bool
> -printdev(struct tcb *tcp, int fd, const char *path)
> +static struct finfo *
> +get_finfo_for_dev(const char *path, struct finfo *finfo)
>  {
>  	strace_stat_t st;
>  
> -	if (path[0] != '/')
> -		return false;
> +	finfo->type = finfo_unset;
> +	finfo->path = path;
>  
> -	if (stat_file(path, &st)) {
> -		debug_func_perror_msg("stat(\"%s\")", path);
> -		return false;
> +	if (finfo->path[0] != '/')
> +		goto out;
> +
> +	if (stat_file(finfo->path, &st)) {
> +		debug_func_perror_msg("stat(\"%s\")", finfo->path);
> +		goto out;
>  	}
>  
>  	switch (st.st_mode & S_IFMT) {
>  	case S_IFBLK:
> +		finfo->type = finfo_dev_blk;
> +		break;
>  	case S_IFCHR:
> +		finfo->type = finfo_dev_chr;
> +		break;
> +	default:
> +		goto out;
> +	}
> +
> +	finfo->dev.major = major(st.st_rdev);
> +	finfo->dev.minor = minor(st.st_rdev);
> +
> + out:
> +	return finfo;
> +}

Do you think "goto out" is any better than a simple "return finfo"?


-- 
ldv


More information about the Strace-devel mailing list