summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2010-08-27 18:12:59 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2010-08-27 18:12:59 +0200
commite4dcdc4ab232bcbbe61a2026c16e647d9302cdd2 (patch)
tree341f54122649a950ac7cb09c46fb80b483064ff9
parent83184d008ba23724fd30996440534c0633a0d0aa (diff)
gudev: fix crash if netlink is not available
gudev_client_new() assumes that priv->monitor is never NULL, but this happens on older kernels. Let's not crash client programs because of that. https://launchpad.net/bugs/581527
-rw-r--r--extras/gudev/gudevclient.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/extras/gudev/gudevclient.c b/extras/gudev/gudevclient.c
index fa31f70bf5..f5f7a198db 100644
--- a/extras/gudev/gudevclient.c
+++ b/extras/gudev/gudevclient.c
@@ -93,6 +93,8 @@ monitor_event (GIOChannel *source,
GUdevDevice *device;
struct udev_device *udevice;
+ if (client->priv->monitor == NULL)
+ goto out;
udevice = udev_monitor_receive_device (client->priv->monitor);
if (udevice == NULL)
goto out;
@@ -216,17 +218,21 @@ g_udev_client_constructed (GObject *object)
*s = '\0';
}
- udev_monitor_filter_add_match_subsystem_devtype (client->priv->monitor, subsystem, devtype);
+ if (client->priv->monitor != NULL)
+ udev_monitor_filter_add_match_subsystem_devtype (client->priv->monitor, subsystem, devtype);
g_free (subsystem);
}
/* listen to events, and buffer them */
- udev_monitor_enable_receiving (client->priv->monitor);
-
- channel = g_io_channel_unix_new (udev_monitor_get_fd (client->priv->monitor));
- client->priv->watch_id = g_io_add_watch (channel, G_IO_IN, monitor_event, client);
- g_io_channel_unref (channel);
+ if (client->priv->monitor != NULL)
+ {
+ udev_monitor_enable_receiving (client->priv->monitor);
+ channel = g_io_channel_unix_new (udev_monitor_get_fd (client->priv->monitor));
+ client->priv->watch_id = g_io_add_watch (channel, G_IO_IN, monitor_event, client);
+ g_io_channel_unref (channel);
+ } else
+ client->priv->watch_id = NULL;
}
if (G_OBJECT_CLASS (g_udev_client_parent_class)->constructed != NULL)