hal/hald/linux2 osspec.c,1.12,1.13

David Zeuthen david at freedesktop.org
Mon Feb 14 10:20:07 PST 2005


Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv18090/hald/linux2

Modified Files:
	osspec.c 
Log Message:
2005-02-14  David Zeuthen  <davidz at redhat.com>

	* configure.in: Require dbus >= 0.30

2005-02-11  John (J5) Palmieri  <johnp at redhat.com>

	* hald/device.c, hald/device_info.c, hald/property.c, hald/property.h,
        tools/hal_set_property.c, tools/hal_get_property.c: 
        s/HAL_PROPERTY_TYPE_NIL/HAL_PROPERTY_TYPE_INVALID

	* hald/hald_dbus.c: ported to new dbus-0.30 API
	(foreach_property_append): implemented real string lists 
        and got rid of the \tval\tval\tval\t hack

	* libhal/libhal.c: ported to new dbus-0.30 API
        s/HAL_PROPERTY_TYPE_NIL/HAL_PROPERTY_TYPE_INVALID
	(libhal_get_string_array_from_iter): new helper function to create
        string arrays from dbus arrays
	(libhal_property_fill_value_from_variant): new helper function
        that fills in properties from variants.  Used when getting
        a hash of properties from hald
        
	* libhal/libhal.h: s/HAL_PROPERTY_TYPE_NIL/HAL_PROPERTY_TYPE_INVALID
        HAL_PROPERTY_TYPE_INVALID = DBUS_TYPE_INVALID

	* hald/hald_test_libhal.c: ported to new dbus-0.30 API
        Added success messages and more detailed failed messages

	* hald/util.c (hal_util_compute_udi): Change all illegal characters
	to underscores '_'

	* tools/device-manager/DeviceManager.py
	(DeviceManager::__init__, add_device_signal_recv): 
	change add_signal_receiver calls to add expand_args=False parameter.
	(DeviceManager::device_changed, gdl_changed): changed handlers
	to conform with the new way we call signal handlers



Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/osspec.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- osspec.c	10 Feb 2005 17:03:57 -0000	1.12
+++ osspec.c	14 Feb 2005 18:20:05 -0000	1.13
@@ -233,6 +233,62 @@
 	return TRUE;
 }
 
+
+#define VALID_NLMSG(h, s) ((NLMSG_OK (h, s) && \
+                           s >= sizeof (struct nlmsghdr) && \
+                           s >= h->nlmsg_len))
+
+static gboolean
+netlink_detection_data_ready (GIOChannel *channel, GIOCondition cond,
+			   gpointer user_data)
+{
+	int fd;
+	int bytes_read;
+	guint total_read = 0;
+	struct sockaddr_nl nladdr;
+	socklen_t nladdrlen = sizeof(nladdr);
+	char buf[1024];
+
+	HAL_INFO (("data!", buf));
+
+	if (cond & ~(G_IO_IN | G_IO_PRI)) {
+		HAL_ERROR (("Error occurred on netlink socket"));
+		return TRUE;
+	}
+
+	fd = g_io_channel_unix_get_fd (channel);
+
+	do {
+		errno = 0;
+		bytes_read = recvfrom (fd,
+				   buf + total_read,
+				   sizeof (buf) - total_read,
+				   MSG_DONTWAIT,
+				   (struct sockaddr*)&nladdr, &nladdrlen);
+		if (nladdrlen != sizeof(nladdr)) {
+			HAL_ERROR(("Bad address size reading netlink socket"));
+			return TRUE;
+		}
+		if (nladdr.nl_pid) {
+			HAL_ERROR(("Spoofed packet received on netlink socket"));
+			return TRUE;
+		}
+		if (bytes_read > 0)
+			total_read += bytes_read;
+	} while (bytes_read > 0 || errno == EINTR);
+
+	if (bytes_read < 0 && errno != EAGAIN) {
+		HAL_ERROR (("Error reading data off netlink socket"));
+		return TRUE;
+	}
+
+	if (total_read > 0) {
+		HAL_INFO (("total_read=%d buf='%s'", total_read, buf));
+	}
+
+	return TRUE;
+}
+
 void
 osspec_init (void)
 {
@@ -243,6 +299,9 @@
 	GIOChannel *channel;	
 	const int on = 1;
 	guint sigio_iochn_listener_source_id;
+	static int netlink_fd = -1;
+	struct sockaddr_nl netlink_addr;
+	GIOChannel *netlink_channel;
 
 	/* setup socket for listening from datagrams from the hal.hotplug helper */
 	memset(&saddr, 0x00, sizeof(saddr));
@@ -294,6 +353,26 @@
 	sigio_iochn_listener_source_id = g_io_add_watch (sigio_iochn, G_IO_IN, sigio_iochn_data, NULL);
 	signal (SIGIO, sigio_handler);
 
+	/* hook up to netlink socket to receive events from the *Kernel Events Layer* */
+	netlink_fd = socket (PF_NETLINK, SOCK_DGRAM, 15/*NETLINK_KOBJECT_UEVENT*/);
+
+	if (netlink_fd < 0) {
+		DIE (("Unable to create netlink socket"));
+	}
+
+	memset (&netlink_addr, 0, sizeof (netlink_addr));
+	netlink_addr.nl_family = AF_NETLINK;
+	netlink_addr.nl_pid = getpid ();
+	netlink_addr.nl_groups = 0xffffffff;15;//RTMGRP_LINK;//1 << 15 /*NETLINK_KOBJECT_UEVENT*/;
+
+	if (bind (netlink_fd, (struct sockaddr *) &netlink_addr, sizeof (netlink_addr)) < 0) {
+		DIE (("Unable to bind to netlink socket"));
+	}
+
+	netlink_channel = g_io_channel_unix_new (netlink_fd);
+
+	g_io_add_watch (netlink_channel, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_NVAL,
+			netlink_detection_data_ready, NULL);
 
 	/* Load various hardware id databases */
 	ids_init ();




More information about the hal-commit mailing list