[LTP] [PATCH v2] Add test for UI_GET_NAME ioctl

Cyril Hrubis chrubis@suse.cz
Thu Oct 12 16:05:21 CEST 2023


Hi!
> +static int check_ui_get_sysname_ioctl(int fd)
> +{
> +	char name[256];
> +
> +	SAFE_IOCTL(NULL, fd, UI_GET_SYSNAME(sizeof(name)), name, NULL);
> +
> +	DIR *test_dir;
> +
> +	struct dirent *ent;
> +
> +	test_dir = SAFE_OPENDIR(NULL, "/sys/devices/virtual/input/");
> +
> +	while ((ent = SAFE_READDIR(NULL, test_dir))) {
> +		if (!strcmp(ent->d_name, name))
> +			return 1;
> +		else
> +			continue;
> +	}

Why do we loop over the directory here? Can't we just directly check
that the path /sys/devices/virtual/input/$name/ exists?

I guess that we can as well read the
/sys/devices/virtual/input/$name/dev and match that against fstat() on
the fd.

> +	return 0;
> +}
> +
>  void create_device(int fd)
>  {
>  	int nb;
> @@ -202,7 +225,7 @@ void create_device(int fd)
>  	SAFE_IOCTL(NULL, fd, UI_DEV_CREATE, NULL);
>  
>  	for (nb = 100; nb > 0; nb--) {
> -		if (check_device())
> +		if (check_device() && check_ui_get_sysname_ioctl(fd))

Maybe it would be a bit more readable if we did:

		if (check_device() {
			check_ui_get_sysname_ioctl(fd);
			return;
		}

>  			return;
>  		usleep(10000);
>  	}
> -- 
> 2.35.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list