From 51c26ace6bdb4184391794e112e60c721ef32c54 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 4 Dec 2009 14:55:31 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Bug=2024446=20=E2=80=94=20Add=20--helper-dir=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add daemon option --helper-dir to specify helper directory. This is useful for running the daemon from the local build tree for testing (--helper-dir src/helpers). Remove explicit PACKAGE_LIBEXEC_DIR from job invocations, since job_new() already searches $PATH and the daemon sets $PATH to a known-good value. So --helper-dir only prepends the custom directory to $PATH. --- src/device.c | 28 ++++++++++++++-------------- src/main.c | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/device.c b/src/device.c index a1e0b7a..2381ea8 100644 --- a/src/device.c +++ b/src/device.c @@ -5311,7 +5311,7 @@ device_filesystem_mount_authorized_cb (Daemon *daemon, { n = 0; snprintf (uid_buf, sizeof uid_buf, "%d", caller_uid); - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-fstab-mounter"; + argv[n++] = "udisks-helper-fstab-mounter"; argv[n++] = "mount"; argv[n++] = device->priv->device_file; argv[n++] = uid_buf; @@ -5637,7 +5637,7 @@ device_filesystem_unmount_authorized_cb (Daemon *daemon, { n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-fstab-mounter"; + argv[n++] = "udisks-helper-fstab-mounter"; if (force_unmount) argv[n++] = "force_unmount"; else @@ -6099,7 +6099,7 @@ device_drive_detach_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-drive-detach"; + argv[n++] = "udisks-helper-drive-detach"; argv[n++] = device->priv->device_file; argv[n++] = device->priv->native_path; argv[n++] = NULL; @@ -6352,7 +6352,7 @@ device_partition_delete_authorized_cb (Daemon *daemon, part_number_as_string = g_strdup_printf ("%d", device->priv->partition_number); n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-delete-partition"; + argv[n++] = "udisks-helper-delete-partition"; argv[n++] = enclosing_device->priv->device_file; argv[n++] = device->priv->device_file; argv[n++] = offset_as_string; @@ -6739,7 +6739,7 @@ device_filesystem_create_internal (Device *device, g_free (s); n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-mkfs"; + argv[n++] = "udisks-helper-mkfs"; argv[n++] = (char *) fstype; argv[n++] = device->priv->device_file; argv[n++] = device->priv->device_is_partition_table ? "1" : "0"; @@ -7190,7 +7190,7 @@ device_partition_create_authorized_cb (Daemon *daemon, flags_as_string = g_strjoinv (",", flags); n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-create-partition"; + argv[n++] = "udisks-helper-create-partition"; argv[n++] = device->priv->device_file; ; argv[n++] = offset_as_string; @@ -7425,7 +7425,7 @@ device_partition_modify_authorized_cb (Daemon *daemon, flags_as_string = g_strjoinv (",", flags); n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-modify-partition"; + argv[n++] = "udisks-helper-modify-partition"; argv[n++] = enclosing_device->priv->device_file; argv[n++] = offset_as_string; argv[n++] = size_as_string; @@ -7664,7 +7664,7 @@ device_partition_table_create_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-create-partition-table"; + argv[n++] = "udisks-helper-create-partition-table"; argv[n++] = device->priv->device_file; argv[n++] = (char *) scheme; for (m = 0; options[m] != NULL; m++) @@ -8856,7 +8856,7 @@ device_drive_ata_smart_refresh_data_authorized_cb (Daemon *daemon, else { n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-ata-smart-collect"; + argv[n++] = "udisks-helper-ata-smart-collect"; argv[n++] = device->priv->device_file; argv[n++] = nowakeup ? "1" : "0"; argv[n++] = NULL; @@ -8977,7 +8977,7 @@ device_drive_ata_smart_initiate_selftest_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-ata-smart-selftest"; + argv[n++] = "udisks-helper-ata-smart-selftest"; argv[n++] = device->priv->device_file; argv[n++] = (char *) test; argv[n++] = NULL; @@ -9191,7 +9191,7 @@ device_linux_md_check_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-linux-md-check"; + argv[n++] = "udisks-helper-linux-md-check"; argv[n++] = device->priv->device_file; argv[n++] = device->priv->native_path; for (m = 0; options[m] != NULL; m++) @@ -9588,7 +9588,7 @@ device_linux_md_remove_component_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-linux-md-remove-component"; + argv[n++] = "udisks-helper-linux-md-remove-component"; argv[n++] = device->priv->device_file; argv[n++] = slave->priv->device_file; for (m = 0; options[m] != NULL; m++) @@ -10852,7 +10852,7 @@ device_drive_poll_media_authorized_cb (Daemon *daemon, char *argv[16]; n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-drive-poll"; + argv[n++] = "udisks-helper-drive-poll"; argv[n++] = device->priv->device_file; argv[n++] = NULL; @@ -11187,7 +11187,7 @@ device_drive_benchmark_authorized_cb (Daemon *daemon, } n = 0; - argv[n++] = PACKAGE_LIBEXEC_DIR "/udisks-helper-drive-benchmark"; + argv[n++] = "udisks-helper-drive-benchmark"; argv[n++] = device->priv->device_file; argv[n++] = do_write_benchmark ? "1" : "0"; argv[n++] = NULL; diff --git a/src/main.c b/src/main.c index 66b0d7d..3f0c8ab 100644 --- a/src/main.c +++ b/src/main.c @@ -137,11 +137,15 @@ main (int argc, GOptionContext *context; DBusGProxy *system_bus_proxy; DBusGConnection *bus; + static char *helper_dir = NULL; + char *path; int ret; static gboolean replace; static GOptionEntry entries[] = { { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, "Replace existing daemon", NULL }, + { "helper-dir", 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING, + &helper_dir, "Directory for helper tools", NULL }, { NULL } }; ret = 1; @@ -155,13 +159,6 @@ main (int argc, goto out; } - /* run with a controlled path */ - if (!g_setenv ("PATH", PACKAGE_LIBEXEC_DIR ":/sbin:/bin:/usr/sbin:/usr/bin", TRUE)) - { - g_warning ("Couldn't set PATH"); - goto out; - } - /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */ if (!g_setenv ("GIO_USE_VFS", "local", TRUE)) { @@ -174,6 +171,19 @@ main (int argc, g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); + /* run with a controlled path */ + if (helper_dir != NULL) + path = g_strdup_printf ("%s:" PACKAGE_LIBEXEC_DIR ":/sbin:/bin:/usr/sbin:/usr/bin", helper_dir); + else + path = g_strdup (PACKAGE_LIBEXEC_DIR ":/sbin:/bin:/usr/sbin:/usr/bin"); + + if (!g_setenv ("PATH", path, TRUE)) + { + g_warning ("Couldn't set PATH"); + goto out; + } + g_free (path); + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (bus == NULL) { -- 1.6.5