public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: "L. Hanisch" <dvb@flensrocker.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Subject: Re: [media-ctl][PATCH] libmediactl: engage udev to get devname
Date: Tue, 30 Aug 2011 22:20:59 +0200	[thread overview]
Message-ID: <4E5D462B.50702@flensrocker.de> (raw)
In-Reply-To: <4a6d0bf1e50189da0c02e2326c3413d9088926c1.1313410776.git.andriy.shevchenko@linux.intel.com>

Hi,

Am 15.08.2011 14:20, schrieb Andy Shevchenko:
> Signed-off-by: Andy Shevchenko<andriy.shevchenko@linux.intel.com>
> ---
>   configure.in    |   10 ++++++++
>   src/Makefile.am |    2 +
>   src/media.c     |   66 ++++++++++++++++++++++++++----------------------------
>   3 files changed, 44 insertions(+), 34 deletions(-)
>
> diff --git a/configure.in b/configure.in
> index fd4c70c..63432ba 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -12,6 +12,16 @@ AC_PROG_CC
>   AC_PROG_LIBTOOL
>
>   # Checks for libraries.
> +PKG_CHECK_MODULES(libudev, libudev, have_libudev=yes, have_libudev=no)
> +
> +if test x$have_libudev = xyes; then
> +    LIBUDEV_CFLAGS="$lbudev_CFLAGS"

  Just reading it, shouldn't it be
  LIBUDEV_CFLAGS="$libudev_CFLAGS"

Regards,
Lars.

> +    LIBUDEV_LIBS="$libudev_LIBS"
> +    AC_SUBST(LIBUDEV_CFLAGS)
> +    AC_SUBST(LIBUDEV_LIBS)
> +else
> +    AC_MSG_ERROR([libudev is required])
> +fi
>
>   # Kernel headers path.
>   AC_ARG_WITH(kernel-headers,
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 267ea83..52628d2 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -5,6 +5,8 @@ mediactl_includedir=$(includedir)/mediactl
>   mediactl_include_HEADERS = media.h subdev.h
>
>   bin_PROGRAMS = media-ctl
> +media_ctl_CFLAGS = $(LIBUDEV_CFLAGS)
> +media_ctl_LDFLAGS = $(LIBUDEV_LIBS)
>   media_ctl_SOURCES = main.c options.c options.h tools.h
>   media_ctl_LDADD = libmediactl.la libv4l2subdev.la
>
> diff --git a/src/media.c b/src/media.c
> index e3cab86..000d750 100644
> --- a/src/media.c
> +++ b/src/media.c
> @@ -31,6 +31,8 @@
>   #include<linux/videodev2.h>
>   #include<linux/media.h>
>
> +#include<libudev.h>
> +
>   #include "media.h"
>   #include "tools.h"
>
> @@ -247,15 +249,20 @@ static int media_enum_links(struct media_device *media)
>
>   static int media_enum_entities(struct media_device *media)
>   {
> +	struct udev *udev;
> +	dev_t devnum;
> +	struct udev_device *device;
>   	struct media_entity *entity;
> -	struct stat devstat;
>   	unsigned int size;
> -	char devname[32];
> -	char sysname[32];
> -	char target[1024];
> -	char *p;
> +	const char *p;
>   	__u32 id;
> -	int ret;
> +	int ret = 0;
> +
> +	udev = udev_new();
> +	if (udev == NULL) {
> +		printf("unable to allocate memory for context\n");
> +		return -ENOMEM;
> +	}
>
>   	for (id = 0; ; id = entity->info.id) {
>   		size = (media->entities_count + 1) * sizeof(*media->entities);
> @@ -268,9 +275,9 @@ static int media_enum_entities(struct media_device *media)
>
>   		ret = ioctl(media->fd, MEDIA_IOC_ENUM_ENTITIES,&entity->info);
>   		if (ret<  0) {
> -			if (errno == EINVAL)
> -				break;
> -			return -errno;
> +			if (errno != EINVAL)
> +				ret = -errno;
> +			break;
>   		}
>
>   		/* Number of links (for outbound links) plus number of pads (for
> @@ -281,8 +288,10 @@ static int media_enum_entities(struct media_device *media)
>
>   		entity->pads = malloc(entity->info.pads * sizeof(*entity->pads));
>   		entity->links = malloc(entity->max_links * sizeof(*entity->links));
> -		if (entity->pads == NULL || entity->links == NULL)
> -			return -ENOMEM;
> +		if (entity->pads == NULL || entity->links == NULL) {
> +			ret = -ENOMEM;
> +			break;
> +		}
>
>   		media->entities_count++;
>
> @@ -291,32 +300,21 @@ static int media_enum_entities(struct media_device *media)
>   		    media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV)
>   			continue;
>
> -		sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
> -			entity->info.v4l.minor);
> -		ret = readlink(sysname, target, sizeof(target));
> -		if (ret<  0)
> -			continue;
> -
> -		target[ret] = '\0';
> -		p = strrchr(target, '/');
> -		if (p == NULL)
> -			continue;
> -
> -		sprintf(devname, "/dev/%s", p + 1);
> -		ret = stat(devname,&devstat);
> -		if (ret<  0)
> -			continue;
> +		devnum = makedev(entity->info.v4l.major, entity->info.v4l.minor);
> +		printf("looking up device: %u:%u\n", major(devnum), minor(devnum));
> +		device = udev_device_new_from_devnum(udev, 'c', devnum);
> +		if (device) {
> +			p = udev_device_get_devnode(device);
> +			if (p)
> +				snprintf(entity->devname, sizeof(entity->devname),
> +					 "%s", p);
> +		}
>
> -		/* Sanity check: udev might have reordered the device nodes.
> -		 * Make sure the major/minor match. We should really use
> -		 * libudev.
> -		 */
> -		if (major(devstat.st_rdev) == entity->info.v4l.major&&
> -		    minor(devstat.st_rdev) == entity->info.v4l.minor)
> -			strcpy(entity->devname, devname);
> +		udev_device_unref(device);
>   	}
>
> -	return 0;
> +	udev_unref(udev);
> +	return ret;
>   }
>
>   struct media_device *media_open(const char *name, int verbose)

      parent reply	other threads:[~2011-08-30 20:32 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-15 12:20 [media-ctl][PATCH] libmediactl: engage udev to get devname Andy Shevchenko
2011-08-15 14:52 ` Laurent Pinchart
2011-08-16  7:20   ` Andy Shevchenko
2011-08-16 10:28   ` [media-ctl][PATCHv2 1/4] libmediactl: restruct error path Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 2/4] libmediactl: split media_get_devname from media_enum_entities Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 3/4] libmediactl: use udev conditionally to get a devname Andy Shevchenko
2011-08-30 19:01       ` Laurent Pinchart
2011-09-02  8:39         ` [media-ctl][PATCHv3 1/3] libmediactl: restruct error path Andy Shevchenko
2011-09-02  8:39           ` [media-ctl][PATCHv3 2/3] libmediactl: split media_get_devname_sysfs from media_enum_entities Andy Shevchenko
2011-09-02  8:39           ` [media-ctl][PATCHv3 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-08-30 19:14       ` [media-ctl][PATCHv2 3/4] libmediactl: use udev conditionally to get a devname Laurent Pinchart
2011-09-02  8:42         ` Andy Shevchenko
2011-09-02 11:17           ` Laurent Pinchart
2011-09-02 11:21             ` Andy Shevchenko
2011-09-02 11:26               ` Laurent Pinchart
2011-09-02 13:09                 ` [media-ctl][PATCHv4 1/3] libmediactl: restruct error path Andy Shevchenko
2011-09-02 13:09                   ` [media-ctl][PATCHv4 2/3] libmediactl: split media_get_devname_sysfs from media_enum_entities Andy Shevchenko
2011-09-02 13:09                   ` [media-ctl][PATCHv4 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-09-05 10:31                     ` Laurent Pinchart
2011-09-05 14:48                       ` Andy Shevchenko
2011-09-05 14:57                         ` Laurent Pinchart
2011-09-05 15:24                           ` [media-ctl][PATCHv5 1/5] libmediactl: restruct error path Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 2/5] libmediactl: split media_get_devname_sysfs from media_enum_entities Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 3/5] libmediactl: get the device name via udev Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 4/5] libmediactl: simplify code by introducing close_and_free inliner Andy Shevchenko
2011-09-05 15:24                             ` [media-ctl][PATCHv5 5/5] libmediactl: get rid of memset via using calloc Andy Shevchenko
2011-09-06 10:25                             ` [media-ctl][PATCHv5 1/5] libmediactl: restruct error path Laurent Pinchart
2011-09-06 10:46                               ` Andy Shevchenko
2011-09-06 10:50                                 ` Andy Shevchenko
2011-09-06 11:30                                   ` Laurent Pinchart
2011-09-06  8:14                           ` [media-ctl][PATCHv4 3/3] libmediactl: get the device name via udev Andy Shevchenko
2011-08-16 10:28     ` [media-ctl][PATCHv2 4/4] libmediactl: pass verbose to media_get_devname Andy Shevchenko
2011-08-30 20:20 ` L. Hanisch [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E5D462B.50702@flensrocker.de \
    --to=dvb@flensrocker.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox