fix a loop into the glib that monitor output from a plugin.
author"Luc Saillard <luc@saillard.org>"
Tue Jun 17 16:50:58 2008 +0200 (2 months ago)
changeset 887aacee387a38
parent 8788a11d40d460
child 895d69e920e89b
fix a loop into the glib that monitor output from a plugin.
When a plugin leave, minihal takes 100% of cpu time, because i think one
reference remais in the glib loop. Now clear everything and test everything
(and i hope in the right order)
src/device.c
src/sysfs.c
src/udev.c
--- a/src/device.c Mon Jun 16 15:56:53 2008 +0200
+++ b/src/device.c Tue Jun 17 16:50:58 2008 +0200
@@ -281,10 +281,13 @@ device_stop(struct device_t *device)
{
trace("%s\n", device->sysfspath);
- /* Umount all partitions attached to this device */
- device_umount_attached_devices(device);
-
- umount_device(device->devname);
+ if (device->type == DEVICE_BLOCK_TYPE_DISK || device->type == DEVICE_BLOCK_TYPE_CDROM)
+ {
+ /* Umount all partitions attached to this device */
+ device_umount_attached_devices(device);
+
+ umount_device(device->devname);
+ }
if (device->pid)
{
@@ -299,16 +302,21 @@ device_stop(struct device_t *device)
device->pid = 0;
}
if (device->watch)
- g_source_remove(device->watch);
- g_source_remove(device->watch_io_out);
+ {
+ g_source_remove(device->watch);
+ device->watch = 0;
+ }
if (device->io_out)
{
g_io_channel_shutdown(device->io_out, TRUE, NULL);
- g_io_channel_unref(device->io_out);
+ device->io_out = 0;
+ }
+ if (device->watch_io_out)
+ {
+ g_source_remove(device->watch_io_out);
+ device->watch_io_out = 0;
}
g_spawn_close_pid(device->pid);
- device->watch = 0;
- device->watch_io_out = 0;
}
}
@@ -341,14 +349,14 @@ device_free(struct device_t *device)
{
trace("%s\n", device->sysfspath);
+ if (device->watch)
+ g_source_remove(device->watch);
+ if (device->watch_io_out)
+ g_source_remove(device->watch_io_out);
+ if (device->io_out)
+ g_io_channel_shutdown(device->io_out, TRUE, NULL);
if (device->pid)
- {
- if (device->watch)
- g_source_remove(device->watch);
- g_source_remove(device->watch_io_out);
- g_io_channel_shutdown(device->io_out, TRUE, NULL);
- g_spawn_close_pid(device->pid);
- }
+ g_spawn_close_pid(device->pid);
if (device->string_buffer)
g_string_free(device->string_buffer, TRUE);
@@ -941,6 +949,7 @@ device_dispatch_messages(struct device_t
if (dev->ops->read)
dev->ops->read(dev, buffer->str);
+ trace("[%s]: %s\n", dev->devname, buffer->str);
g_string_erase(buffer, 0, msglen);
}
@@ -1047,6 +1056,7 @@ device_launch_plugin(struct device_t *de
g_io_channel_set_encoding(device->io_out, NULL, NULL);
g_io_channel_set_close_on_unref(device->io_out, TRUE);
device->watch_io_out = g_io_add_watch(device->io_out, G_IO_IN, (GIOFunc)device_io_read, device);
+ g_io_channel_unref(device->io_out); /* pass ownership of the channel to the watch */
device->string_buffer = g_string_sized_new(256);
return TRUE;
--- a/src/sysfs.c Mon Jun 16 15:56:53 2008 +0200
+++ b/src/sysfs.c Tue Jun 17 16:50:58 2008 +0200
@@ -631,6 +631,7 @@ sysfs_coldplug_scan_net_devices(void)
DIR *dir;
struct dirent *entry;
struct device_t *dev;
+ char *type_string;
dir = opendir("/sys/class/net");
if (dir == NULL)
@@ -654,6 +655,23 @@ sysfs_coldplug_scan_net_devices(void)
trace("sysfs_path = %s\n", sysfs_path);
+ /* Nor with interface that is not ethernet */
+ type_string = sysfs_get_file_content(sysfs_path, "type");
+ if (type_string == NULL)
+ {
+ trace("%s/type is not readable: %s\n", sysfs_path, strerror(errno));
+ continue;
+ }
+
+ /* Only keep ethernet device (not lo 722, or wlan master device 801 ...) */
+ if (strcmp(type_string, "1"))
+ {
+ g_free(type_string);
+ trace("Interface %s is not an ethernet device: %s\n", entry->d_name, strerror(errno));
+ continue;
+ }
+ g_free(type_string);
+
/* We are interesting only by usb keyboard */
dev = device_new(DEVICE_NET_ETHERNET, sysfs_path, entry->d_name);
device_watch(dev);
--- a/src/udev.c Mon Jun 16 15:56:53 2008 +0200
+++ b/src/udev.c Tue Jun 17 16:50:58 2008 +0200
@@ -395,8 +395,8 @@ hotplug_add_sysfs_net(HotplugEvent *even
/* Only keep ethernet device (not lo 722, or wlan master device 801 ...) */
if (strcmp(type_string, "1"))
{
- g_free(type_string);
- return;
+ g_free(type_string);
+ return;
}
g_free(type_string);