[RFC PATCH] Initial libudev input-hotplug support

Adam Jackson ajax at nwnk.net
Mon Oct 5 11:13:39 PDT 2009


On Tue, 2009-09-29 at 23:54 +0200, Julien Cristau wrote:

> - what's the recommended way to avoid races between the 'enumerate' and
>   'monitor' parts?

I suspect the answer is "turn on monitor, then enumerate, then read plug
events from the monitor", and no-op adding a device you've already
added.

> +	config_info = xalloc(strlen(syspath) + 6); /* "udev:" + \0 */
> +	if (!config_info)
> +		goto unwind;
> +	sprintf(config_info, "udev:%s", syspath);

We have the moral equivalent of glibc's asprintf():

        config_info = Xprintf("udev:%s", syspath);
        if (!config_info)
                goto unwind;

Which we should really use uniformly, it's a lot harder to get wrong.

> +static struct udev_monitor *udev_monitor;
> +static OsTimerPtr udev_timer;
> +
> +static CARD32
> +connect_timer(OsTimerPtr timer, CARD32 time, pointer arg) {
> +	int fd;
> +	struct udev_enumerate *enumerate;

Bad { placement, but...

> +int
> +config_udev_init(void) {
> +	struct udev *udev;
> +
> +	udev = udev_new();
> +	udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
> +	if (!udev_monitor)
> +		return 0;
> +	udev_timer = TimerSet(NULL, 0, 1, connect_timer, NULL);
> +	if (!udev_timer)
> +		return 0;
> +	return 1;
> +}

I don't think the timer should be needed for libudev.  All
udev_monitor_new_from_netlink() does aside from malloc() is open a
netlink socket.  If that fails you have a plethora of more serious
problems already.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.x.org/archives/xorg-devel/attachments/20091005/0e988f79/attachment.pgp 


More information about the xorg-devel mailing list