[PATCH] don't die if /proc/mdstat doesn't exist

Daniel Drake dsd at gentoo.org
Fri Jun 22 14:54:58 PDT 2007


The recent commit to add MD support causes HAL to exit early during
startup if /proc/mdstat isn't watchable.

This breaks HAL on my system which runs a kernel without MD support at
all, so /proc/mdstat doesn't exist.

Allow the NOENT error but continue to bail out on other conditions.
---
 hald/linux/osspec.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index f70f056..9fc2ce3 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -297,6 +297,8 @@ GIOChannel *get_mdstat_channel (void)
 void
 osspec_privileged_init (void)
 {
+	GError *err = NULL;
+
         file_monitor = hal_file_monitor_new ();
         if (file_monitor == NULL) {
                 DIE (("Cannot initialize file monitor"));
@@ -305,10 +307,20 @@ osspec_privileged_init (void)
 	/* watch /proc/mdstat for md changes
 	 * kernel 2.6.19 throws a POLLPRI event for every change
 	 */
-	mdstat_channel = g_io_channel_new_file ("/proc/mdstat", "r", NULL);
-	if (mdstat_channel == NULL)
-		DIE (("Unable to read /proc/mdstat"));
-	g_io_add_watch (mdstat_channel, G_IO_PRI, mdstat_changed_event, NULL);
+	mdstat_channel = g_io_channel_new_file ("/proc/mdstat", "r", &err);
+	if (mdstat_channel != NULL) {
+		g_io_add_watch (mdstat_channel, G_IO_PRI, mdstat_changed_event, NULL);
+	} else {
+		if (err != NULL)
+			HAL_WARNING (("Unable to open /proc/mdstat: %s", err->message));
+
+		/* if its not a reasonable error, abort */
+		if (!g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+			DIE (("Unable to read /proc/mdstat"));
+	}
+	
+	if (err != NULL)
+		g_error_free (err);
 }
 
 void
-- 
1.5.2.2



More information about the hal mailing list