From 8a9e8099f38941e182db9de35c0ac8469714efd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fridrich=20=C5=A0trba?= Date: Wed, 21 Apr 2010 09:54:38 +0200 Subject: [PATCH] Relocate the DBUS_PREFIX for "exec" variable and for position of service files --- bus/activation.c | 20 ++++++++++-- configure.in | 8 ++++- dbus/dbus-sysdeps-unix.c | 14 ++++++++ dbus/dbus-sysdeps-win.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 110 insertions(+), 7 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index 54296c1..b9133c4 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -248,6 +248,16 @@ bus_activation_entry_unref (BusActivationEntry *entry) dbus_free (entry); } +/* + * replaces the term DBUS_PREFIX in configure_time_path by the + * current dbus installation directory. On unix this function is a noop + * + * @param configure_time_path + * @return real path + */ +const char * +_dbus_replace_install_prefix (const char *configure_time_path); + static dbus_bool_t update_desktop_file_entry (BusActivation *activation, BusServiceDirectory *s_dir, @@ -255,7 +265,7 @@ update_desktop_file_entry (BusActivation *activation, BusDesktopFile *desktop_file, DBusError *error) { - char *name, *exec, *user; + char *name, *exec, *user, *exec_tmp; BusActivationEntry *entry; DBusStat stat_buf; DBusString file_path; @@ -266,6 +276,7 @@ update_desktop_file_entry (BusActivation *activation, name = NULL; exec = NULL; user = NULL; + exec_tmp = NULL; entry = NULL; dbus_error_init (&tmp_error); @@ -300,7 +311,7 @@ update_desktop_file_entry (BusActivation *activation, if (!bus_desktop_file_get_string (desktop_file, DBUS_SERVICE_SECTION, DBUS_SERVICE_EXEC, - &exec, + &exec_tmp, error)) goto failed; @@ -329,6 +340,9 @@ update_desktop_file_entry (BusActivation *activation, entry = _dbus_hash_table_lookup_string (s_dir->entries, _dbus_string_get_const_data (filename)); + + exec = strdup (_dbus_windows_replace_prefix (exec_tmp)); + if (entry == NULL) /* New file */ { /* FIXME we need a better-defined algorithm for which service file to @@ -417,7 +431,7 @@ update_desktop_file_entry (BusActivation *activation, failed: dbus_free (name); - dbus_free (exec); + dbus_free (exec_tmp); dbus_free (user); _dbus_string_free (&file_path); diff --git a/configure.in b/configure.in index 74f6f5e..4bc50e7 100644 --- a/configure.in +++ b/configure.in @@ -1335,6 +1335,7 @@ AC_MSG_RESULT(yes) #### find the actual value for $prefix that we'll end up with ## (I know this is broken and should be done in the Makefile, but ## that's a major pain and almost nobody actually seems to care) +AS_AC_EXPAND(EXPANDED_PREFIX, "$prefix") AS_AC_EXPAND(EXPANDED_LOCALSTATEDIR, "$localstatedir") AS_AC_EXPAND(EXPANDED_SYSCONFDIR, "$sysconfdir") AS_AC_EXPAND(EXPANDED_BINDIR, "$bindir") @@ -1430,6 +1431,11 @@ fi AC_SUBST(DBUS_USER) AC_DEFINE_UNQUOTED(DBUS_USER,"$DBUS_USER", [User for running the system BUS daemon]) +#### Prefix to install into +DBUS_PREFIX=$EXPANDED_PREFIX +AC_SUBST(DBUS_PREFIX) +AC_DEFINE_UNQUOTED(DBUS_PREFIX,"$DBUS_PREFIX", [Prefix for installing DBUS]) + #### Direcotry to install data files into DBUS_DATADIR=$EXPANDED_DATADIR AC_SUBST(DBUS_DATADIR) @@ -1581,7 +1587,7 @@ echo " D-Bus $VERSION ============== - prefix: ${prefix} + prefix: ${EXPANDED_PREFIX} exec_prefix: ${exec_prefix} libdir: ${EXPANDED_LIBDIR} libexecdir: ${EXPANDED_LIBEXECDIR} diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index fc27d51..30cf090 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3583,4 +3583,18 @@ _dbus_socket_can_pass_unix_fd(int fd) { #endif } + +/* + * replaces the term DBUS_PREFIX in configure_time_path by the + * current dbus installation directory. On unix this function is a noop + * + * @param configure_time_path + * @return real path + */ +const char * +_dbus_replace_install_prefix (const char *configure_time_path) +{ + return configure_time_path; +} + /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 16c6f69..eb5282b 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -2060,6 +2060,57 @@ _dbus_delete_file (const DBusString *filename, return TRUE; } +/* Forward declaration of prototype used in next function */ +static dbus_bool_t +_dbus_get_install_root(char *prefix, int len); + +/* + * replaces the term DBUS_PREFIX in configure_time_path by the + * current dbus installation directory. On unix this function is a noop + * + * @param configure_time_path + * @return real path + */ +const char * +_dbus_windows_replace_prefix (const char *configure_time_path); + +const char * +_dbus_windows_replace_prefix (const char *configure_time_path) +{ + static char retval[1000]; +#ifndef DBUS_PREFIX + strcat (retval, configure_time_path); +#else + static char runtime_prefix[1000]; + int len = 1000; + int i; + + if (!configure_time_path) + return NULL; + + if ((!_dbus_get_install_root(runtime_prefix, len) || + strncmp (configure_time_path, DBUS_PREFIX "/", + strlen (DBUS_PREFIX) + 1))) { + strcat (retval, configure_time_path); + return retval; + } + + strcpy (retval, runtime_prefix); + strcat (retval, configure_time_path + strlen (DBUS_PREFIX) + 1); + + /* Somehow, in some situations, backslashes get collapsed in the string. + * Since windows C library accepts both forward and backslashes as + * path separators, convert all backslashes to forward slashes. + */ + + for(i = 0; retval[i] != '\0'; i++) { + if(retval[i] == '\\') + retval[i] = '/'; + } +#endif + return retval; +} + #if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_BUILD_TESTS) #if defined(_MSC_VER) || defined(DBUS_WINCE) @@ -2683,6 +2734,21 @@ _dbus_make_file_world_readable(const DBusString *filename, return TRUE; } +/** + * return the relocated DATADIR + * + * @returns relocated DATADIR static string + */ + +static const char * +_dbus_windows_get_datadir (void) +{ + return _dbus_windows_replace_prefix(DBUS_DATADIR); +} + +#undef DBUS_DATADIR +#define DBUS_DATADIR _dbus_windows_get_datadir () + #define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services" #define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services" @@ -2697,7 +2763,7 @@ _dbus_make_file_world_readable(const DBusString *filename, * * and * - * DBUS_DATADIR + * relocated DBUS_DATADIR * * @param dirs the directory list we are returning * @returns #FALSE on OOM @@ -2727,8 +2793,11 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) } } #else - if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR _DBUS_PATH_SEPARATOR)) - goto oom; + if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR)) + goto oom; + + if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR)) + goto oom; #endif common_progs = _dbus_getenv ("CommonProgramFiles"); -- 1.7.0.3