[Utopia] [patch] Allow one to enable g-v-m's mount command at compile time



Hi,

  Attaches patch allows some to specify the mount and umount programs at
  compile time.  Using the same substitutions as the commands given in the gui.

  This is usefull for Debian and Ubuntu, which use pmount-hal %h and pmount %d
  as mount and umount programs.

  Sjoerd
-- 
It is contrary to reasoning to say that there is a vacuum or space in
which there is absolutely nothing.
		-- Descartes
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-volume-manager/configure.in,v
retrieving revision 1.73
diff -u -r1.73 configure.in
--- configure.in	30 Oct 2004 15:10:51 -0000	1.73
+++ configure.in	17 Nov 2004 17:20:03 -0000
@@ -8,12 +8,21 @@
 AC_PROG_CC
 
 
-AC_PATH_PROG(mount_path, mount, no)
-AC_PATH_PROG(umount_path, umount, no)
+AC_PATH_PROG(mount_program, mount, no)
+mount_program="${mount_program} %d"
+AC_PATH_PROG(umount_program, umount, no)
+umount_program="${umount_program} %d"
 AC_PATH_PROG(nautilus_path, nautilus, no)
 
-AC_DEFINE_UNQUOTED([BIN_MOUNT], ["${mount_path}"], [path to mount])
-AC_DEFINE_UNQUOTED([BIN_UMOUNT], ["${umount_path}"], [path to umount])
+AC_ARG_WITH(mount-program, 
+            [  --with-mount-program=program Program to run to mount a device],
+            mount_program="$withval",)
+AC_ARG_WITH(mount-program, 
+            [  --with-umount-program=program Program to run to umount a device],
+            umount_program="$withval",)
+
+AC_DEFINE_UNQUOTED([BIN_MOUNT], ["${mount_program}"], [mount program])
+AC_DEFINE_UNQUOTED([BIN_UMOUNT], ["${umount_program}"], [umount program])
 AC_DEFINE_UNQUOTED([BIN_NAUTILUS], ["${nautilus_path}"], [nautilus command])
 
 
Index: src/manager.c
===================================================================
RCS file: /cvs/gnome/gnome-volume-manager/src/manager.c,v
retrieving revision 1.35
diff -u -r1.35 manager.c
--- src/manager.c	25 Oct 2004 19:12:11 -0000	1.35
+++ src/manager.c	17 Nov 2004 17:20:04 -0000
@@ -141,20 +141,20 @@
 				 gvm_config_changed, NULL, NULL, NULL);
 }
 
-/*
- * gvm_run_command - run the given command, replacing %d with the device node,
- * %h with the HAL UDI and %m with the given path. Bails out if the command
- * requires a given %d,%h or %m and this is NULL.
+/* parses the given command into a command string. It replaces %d with the 
+ * device node, * %h with the HAL UDI and %m with the given path. 
+ *
+ * Returns NULL f the command * requires a given %d,%h or %m and this is NULL.
  */
-static void
-gvm_run_command (const char *device, const char *command, 
-		 const char *path, const char *udi)
-{
-	char *argv[4];
+
+static gchar *
+gvm_parse_command(const char *device, const char *command, 
+                  const char *path, const char *udi) {
 	gchar *new_command;
 	GError *error = NULL;
 	GString *exec = g_string_new (NULL);
 	char *p, *q;
+  gchar *result;
 
 	/* perform s/%d/device/, s/%m/path/ and s/%h/udi/ */
 	new_command = g_strdup (command);
@@ -190,26 +190,69 @@
 		}
 	}
 	g_string_append (exec, q);
+  result = exec->str;
 
-	argv[0] = "/bin/sh";
-	argv[1] = "-c";
-	argv[2] = exec->str;
-	argv[3] = NULL;
-
-	g_spawn_async (g_get_home_dir (), argv, NULL, 0, NULL, NULL,
-		       NULL, &error);
-	if (error)
-		warn ("failed to exec %s: %s\n", exec->str, error->message);
-
-	g_string_free (exec, TRUE);
+	g_string_free (exec, FALSE);
 	g_free (new_command);
-	return;
+	return result;
 
 error:
 	warn ("command '%s' required unavailable parameter; " 
 	      "%%d='%s' %%m='%s' %%h='%s'\n", command, device, path, udi);
 	g_string_free (exec, TRUE);
 	g_free (new_command);	
+  return NULL;
+}
+
+/*
+ * gvm_run_command - run the given command, replacing %d with the device node,
+ * %h with the HAL UDI and %m with the given path. Bails out if the command
+ * requires a given %d,%h or %m and this is NULL.
+ */
+static void
+gvm_run_command (const char *device, const char *command, 
+		 const char *path, const char *udi)
+{
+  char *cmd;
+  GError *error = NULL;
+
+  cmd = gvm_parse_command(device, command, path, udi);
+  if (cmd == NULL) {
+    return;
+  }
+	if (!g_spawn_command_line_async (cmd, &error)) 
+		warn ("failed to exec %s: %s\n", cmd, error->message);
+
+	g_free (cmd);
+	return;
+}
+
+/*
+ * gvm_run_command_sync - run the given command, replacing %d with the device
+ * node, %h with the HAL UDI and %m with the given path. Bails out if the
+ * command requires a given %d,%h or %m and this is NULL.
+ *
+ * Returns the exitcode of the command if run and -1 if failed
+ */
+static gint 
+gvm_run_command_sync (const char *device, const char *command, 
+		 const char *path, const char *udi)
+{
+  char *cmd;
+  gint exit_status;
+  GError *error = NULL;
+
+  cmd = gvm_parse_command(device, command, path, udi);
+  if (cmd == NULL) {
+    return -1;
+  }
+	if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) {
+		warn ("failed to exec %s: %s\n", cmd, error->message);
+	  g_free (cmd);
+    return -1;
+  }
+	g_free (cmd);
+  return exit_status;
 }
 
 /*
@@ -455,23 +498,9 @@
  * @return TRUE iff the mount was succesful
  */
 static gboolean
-gvm_device_mount (char *device)
+gvm_device_mount (const char *udi, const char *device)
 {
-	char *argv[3];
-	GError *error = NULL;
-	gint exit_status;
-
-	argv[0] = BIN_MOUNT;
-	argv[1] = device;
-	argv[2] = NULL;
-
-	if (!g_spawn_sync (g_get_home_dir (), argv, NULL, 0, NULL,
-			   NULL, NULL, NULL, &exit_status, &error)) {
-		warn ("failed to exec " BIN_MOUNT ": %s\n", error->message);
-		return FALSE;
-	}
-
-	return (exit_status == 0);
+  return (gvm_run_command_sync(device , BIN_MOUNT, NULL, udi) == 0);
 }
 
 /*
@@ -483,23 +512,8 @@
  * @return TRUE iff the mount was succesful
  */
 static gboolean
-gvm_device_unmount (char *device)
-{
-	char *argv[3];
-	GError *error = NULL;
-	gint exit_status;
-
-	argv[0] = BIN_UMOUNT;
-	argv[1] = device;
-	argv[2] = NULL;
-
-	if (!g_spawn_sync (g_get_home_dir (), argv, NULL, 0, NULL,
-			   NULL, NULL, NULL, &exit_status, &error)) {
-		warn ("failed to exec " BIN_MOUNT ": %s\n", error->message);
-		return FALSE;
-	}
-
-	return (exit_status == 0);
+gvm_device_unmount (const char *udi, const char *device) {
+  return (gvm_run_command_sync(device, BIN_UMOUNT, NULL, udi) == 0);
 }
 
 /*
@@ -556,7 +570,7 @@
 
 	switch (action) {
 	case MOUNT:
-		gvm_device_mount (device);
+		gvm_device_mount (udi, device);
 		mounted_volumes_policy_queue = g_slist_append (mounted_volumes_policy_queue, g_strdup (udi));
 		break;
 	case PLAY:
@@ -633,7 +647,7 @@
 		gvm_ask_mixed (udi);
 	} else if (has_data) {
 		if (config.automount_media) {
-			gvm_device_mount (device);
+			gvm_device_mount (udi, device);
 			mounted_volumes_policy_queue = g_slist_append (mounted_volumes_policy_queue, g_strdup (udi));
 		}
 	} else if (is_blank) {
@@ -691,7 +705,7 @@
 		dbg ("Added: %s\n", device);
 		
 		if (config.automount_drives) {
-			gvm_device_mount (device);
+			gvm_device_mount (udi, device);
 			mounted_volumes_policy_queue = g_slist_append (mounted_volumes_policy_queue, g_strdup (udi));
 		}
 	}
@@ -755,7 +769,7 @@
 	dbg ("Added: %s\n", device);
 	
 	if (config.automount_drives) {
-		gvm_device_mount (device);
+		gvm_device_mount (udi, device);
 		mounted_volumes_policy_queue = g_slist_append (mounted_volumes_policy_queue, g_strdup (udi));
 	}
 	
@@ -835,7 +849,7 @@
 
 		policy_udi = g_slist_find_custom (mounted_volumes_policy_queue, 
 						  udi, 
-						  g_ascii_strcasecmp);
+						  (GCompareFunc)g_ascii_strcasecmp);
 		if (policy_udi != NULL) {
 			g_free (policy_udi->data);
 			mounted_volumes_policy_queue = g_slist_delete_link (mounted_volumes_policy_queue, 
@@ -973,7 +987,7 @@
 
 			dbg ("mount_all: mounting %s\n", device_file);
 
-			gvm_device_mount (device_file);
+			gvm_device_mount (udi, device_file);
 
 			hal_free_string (device_file);
 		} else
@@ -1007,7 +1021,7 @@
 
 			dbg ("unmount_all: unmounting %s\n", device_file);
 
-			gvm_device_unmount (device_file);
+			gvm_device_unmount (udi, device_file);
 			hal_free_string (device_file);
 		} else {
 			warn ("no device_file for udi=%s\n", udi);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]