From b673179cc22f795bb10ba70b09f62e5d6e0c422b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 21 Dec 2011 21:24:03 +0100 Subject: [PATCH] Fix of relative path root in service files on windows. Use directory of dbus-daemon executable as base path for relative pathes in dbus service file. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=44030 --- dbus/dbus-spawn-win.c | 47 +++++++++++++++++++++++++++++++++++++++++------ dbus/dbus-sysdeps-win.c | 35 +++++++++++++++++++++++++++++++++++ dbus/dbus-sysdeps-win.h | 1 + 3 Dateien geändert, 77 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-) diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index cd8ca66..bf5ca71 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -545,6 +545,7 @@ spawn_program (char* name, char** argv, char** envp) STARTUPINFOA si; char *arg_string, *env_string; BOOL result; + char exe_path[MAX_PATH]; #ifdef DBUS_WINCE if (argv && argv[0]) @@ -559,14 +560,48 @@ spawn_program (char* name, char** argv, char** envp) env_string = build_env_string(envp); +#ifndef DBUS_WINCE + // handle relative pathes + if (strlen(name) > 2 && name[0] != '\\' && name[0] != '/' && name[1] != ':') + { + char app_path[MAX_PATH+1]; + DBusString app_name; + LPSTR lpFile; + + _dbus_string_init (&app_name); + _dbus_verbose ("spawning relative path '%s'\n", name); + + if (!_dbus_get_executable_path (app_path, sizeof (app_path))) + { + _dbus_verbose ("failed to get executable path\n"); + return INVALID_HANDLE_VALUE; + } + _dbus_verbose ("got as executable path %s\n", app_path); + + _dbus_string_append (&app_name, name); + + if (!SearchPathA (app_path, + _dbus_string_get_data (&app_name), + NULL, + sizeof (exe_path), exe_path, + &lpFile)) + { + _dbus_string_free (&app_name); + _dbus_verbose ("could not find executable\n"); + return INVALID_HANDLE_VALUE; + } + _dbus_verbose ("found executable %s\n", exe_path); + _dbus_string_free (&app_name); + } + else +#endif + strncpy (exe_path, name, MAX_PATH); + memset (&si, 0, sizeof (si)); si.cb = sizeof (si); -#ifdef DBUS_WINCE - result = CreateProcessA (name, arg_string, NULL, NULL, FALSE, 0, -#else - result = CreateProcessA (NULL, arg_string, NULL, NULL, FALSE, 0, -#endif - (LPVOID)env_string, NULL, &si, &pi); + _dbus_verbose ("running exe=%s args=%s env=%s\n", exe_path, arg_string, env_string); + result = CreateProcessA (exe_path, arg_string, NULL, NULL, FALSE, 0, + (LPVOID)env_string, NULL, &si, &pi); free (arg_string); if (env_string) free (env_string); diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 20ecb4e..0329470 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3458,6 +3458,41 @@ _dbus_get_install_root(char *prefix, int len) return TRUE; } + +/** + * return the absolute path of the current executable + * + * @param path buffer for returned path + * @param len length of buffer + * @returns #FALSE on failure + */ +dbus_bool_t +_dbus_get_executable_path(char *path, int len) +{ + //To find the path, we cut the filename + DWORD pathLength; + char *lastSlash; + + SetLastError(0); + pathLength = GetModuleFileNameA(NULL, path, len); + if (pathLength == 0 || GetLastError() != 0) + { + *path = '\0'; + return FALSE; + } + + lastSlash = _mbsrchr(path, '\\'); + if (lastSlash == NULL) + { + *path = '\0'; + return FALSE; + } + + //cut off file name + lastSlash[1] = 0; + return TRUE; +} + /** find config file either from installation or build root according to the following path layout diff --git a/dbus/dbus-sysdeps-win.h b/dbus/dbus-sysdeps-win.h index 5e7f1e4..2db38ab 100644 --- a/dbus/dbus-sysdeps-win.h +++ b/dbus/dbus-sysdeps-win.h @@ -84,6 +84,7 @@ dbus_bool_t _dbus_get_config_file_name(DBusString *config_file, char *s); dbus_bool_t _dbus_get_install_root(char *prefix, int len); +dbus_bool_t _dbus_get_executable_path(char *path, int len); void _dbus_threads_windows_init_global (void); void _dbus_threads_windows_ensure_ctor_linked (void); -- 1.7.10.4