Make it work without requiring the kernel to be CONFIG_SWAP=y
authorDavid Zeuthen <zeuthen@gmail.com>
Thu, 27 Sep 2012 17:14:15 +0000 (13:14 -0400)
committerDavid Zeuthen <zeuthen@gmail.com>
Thu, 27 Sep 2012 17:14:15 +0000 (13:14 -0400)
https://bugs.freedesktop.org/show_bug.cgi?id=50142

Signed-off-by: David Zeuthen <zeuthen@gmail.com>
src/udisksmountmonitor.c

index 36e1476..b56ed2a 100644 (file)
@@ -322,7 +322,11 @@ udisks_mount_monitor_constructed (GObject *object)
     }
   else
     {
-      g_error ("No /proc/swaps file: %s", error->message);
+      if (!(error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT))
+        {
+          udisks_warning ("Error opening /proc/swaps file: %s (%s, %d)",
+                          error->message, g_quark_to_string (error->domain), error->code);
+        }
       g_error_free (error);
     }
 
@@ -518,15 +522,25 @@ udisks_mount_monitor_get_swaps (UDisksMountMonitor  *monitor,
   gchar *contents;
   gchar **lines;
   guint n;
+  GError *local_error = NULL;
 
   ret = FALSE;
   contents = NULL;
   lines = NULL;
 
-  if (!g_file_get_contents ("/proc/swaps", &contents, NULL, error))
+  if (!g_file_get_contents ("/proc/swaps", &contents, NULL, &local_error))
     {
-      g_prefix_error (error, "Error reading /proc/self/mountinfo: ");
-      goto out;
+      if (local_error->domain == G_FILE_ERROR && local_error->code == G_FILE_ERROR_NOENT)
+        {
+          g_clear_error (&local_error);
+          ret = TRUE;
+          goto out;
+        }
+      else
+        {
+          g_propagate_prefixed_error (error, local_error, "Error reading /proc/self/mountinfo: ");
+          goto out;
+        }
     }
 
   lines = g_strsplit (contents, "\n", 0);