summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2007-06-01 22:05:42 +0000
committerRalf Habacker <ralf.habacker@freenet.de>2007-06-01 22:05:42 +0000
commit378053ba594cca44e1bc9e069eab91b0a0954308 (patch)
tree3c4398ba82d8d1675837f19f0642d84a5abb97f4
parent8d3dbfb1039778584e6476ec0ffadef882360160 (diff)
* bus/main.c (main): uses _dbus_get_config_file_name() to detect session.conf location on win32.
* dbus-sysdeps-win.h (_dbus_get_config_file_name,_dbus_file_exists): new prototyp, undefined interface after including windows.h because t makes trouble when a paramater is named interface. * dbus-sysdeps-win.c (_dbus_get_install_root,_dbus_get_config_file_name,_dbus_file_exists): new functions.
-rw-r--r--ChangeLog12
-rw-r--r--bus/main.c9
-rw-r--r--dbus/dbus-sysdeps-util-win.c123
-rw-r--r--dbus/dbus-sysdeps-win.h7
4 files changed, 151 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 452a67c9..bce20826 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-05-31 Ralf Habacker <ralf.habacker@freenet.de>
+
+ * bus/main.c (main): uses _dbus_get_config_file_name() to detect
+ session.conf location on win32.
+
+ * dbus-sysdeps-win.h (_dbus_get_config_file_name,_dbus_file_exists):
+ new prototyp, undefined interface after including windows.h because
+ it makes trouble when a paramater is named interface.
+
+ * dbus-sysdeps-win.c (_dbus_get_install_root,
+ _dbus_get_config_file_name,_dbus_file_exists): new functions.
+
2007-05-27 Ralf Habacker <ralf.habacker@freenet.de>
* bus/policy.c,dbus/dbus-internals.c: fixed inconsistant line endings
diff --git a/bus/main.c b/bus/main.c
index bf471484..421bd8bf 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -24,6 +24,9 @@
#include "driver.h"
#include <dbus/dbus-internals.h>
#include <dbus/dbus-watch.h>
+#ifdef DBUS_WIN
+#include <dbus/dbus-sysdeps-win.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -296,8 +299,14 @@ main (int argc, char **argv)
{
check_two_config_files (&config_file, "session");
+#ifdef DBUS_WIN
+ if (!_dbus_get_config_file_name (&config_file,"session.conf"))
+ exit (1);
+ /* don't know how to map DBUS_SESSION_CONFIG_FILE to the function above */
+#else
if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
exit (1);
+#endif
}
else if (strstr (arg, "--config-file=") == arg)
{
diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c
index 1117cef2..81fa0ef4 100644
--- a/dbus/dbus-sysdeps-util-win.c
+++ b/dbus/dbus-sysdeps-util-win.c
@@ -42,6 +42,101 @@
#include <stdlib.h>
#include <fcntl.h>
+#ifdef __MINGW32__
+/* save string functions version
+ using DBusString needs to much time because of uncommon api
+*/
+#define errno_t int
+
+errno_t strcat_s(char *dest, int size, char *src)
+{
+ _dbus_assert(strlen(dest) + strlen(src) +1 <= size);
+ strcat(dest,src);
+ return 0;
+}
+
+errno_t strcpy_s(char *dest, int size, char *src)
+{
+ _dbus_assert(strlen(src) +1 <= size);
+ strcpy(dest,src);
+ return 0;
+}
+#endif
+
+/**
+ * return the absolute path of the dbus installation
+ *
+ * @param s buffer for installation path
+ * @param len length of buffer
+ * @returns #FALSE on failure
+ */
+dbus_bool_t
+_dbus_get_install_root(char *s, int len)
+{
+ char *p = NULL;
+ int ret = GetModuleFileName(NULL,s,len);
+ if ( ret == 0
+ || ret == len && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ *s = '\0';
+ return FALSE;
+ }
+ else if ((p = strstr(s,"\\bin\\")) == NULL)
+ {
+ *(p+1)= '\0';
+ return TRUE;
+ }
+ else
+ {
+ *s = '\0';
+ return FALSE;
+ }
+}
+
+/*
+ find session.conf either from installation or build root according to
+ the following path layout
+ install-root/
+ bin/dbus-daemon[d].exe
+ etc/session.conf
+
+ build-root/
+ bin/dbus-daemon[d].exe
+ bus/session.conf
+*/
+dbus_bool_t
+_dbus_get_config_file_name(DBusString *config_file, char *s)
+{
+ char path[MAX_PATH*2];
+ int path_size = sizeof(path);
+
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+
+ strcat_s(path,path_size,"etc\\");
+ strcat_s(path,path_size,s);
+ if (_dbus_file_exists(path))
+ {
+ // find path from executable
+ if (!_dbus_string_append (config_file, path))
+ return FALSE;
+ }
+ else
+ {
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+ strcat_s(path,path_size,"bus\\");
+ strcat_s(path,path_size,s);
+
+ if (_dbus_file_exists(path))
+ {
+ if (!_dbus_string_append (config_file, path))
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
/**
* Does the chdir, fork, setsid, etc. to become a daemon process.
*
@@ -255,6 +350,34 @@ _dbus_set_signal_handler (int sig,
_dbus_verbose ("_dbus_set_signal_handler() has to be implemented\n");
}
+/** Checks if a file exists
+*
+* @param file full path to the file
+* @returns #TRUE if file exists
+*/
+dbus_bool_t
+_dbus_file_exists (const char *file)
+{
+ HANDLE h = CreateFile(
+ file, /* LPCTSTR lpFileName*/
+ 0, /* DWORD dwDesiredAccess */
+ 0, /* DWORD dwShareMode*/
+ NULL, /* LPSECURITY_ATTRIBUTES lpSecurityAttributes */
+ OPEN_EXISTING, /* DWORD dwCreationDisposition */
+ FILE_ATTRIBUTE_NORMAL, /* DWORD dwFlagsAndAttributes */
+ NULL /* HANDLE hTemplateFile */
+ );
+
+ /* file not found, use local copy of session.conf */
+ if (h != INVALID_HANDLE_VALUE && GetLastError() != ERROR_PATH_NOT_FOUND)
+ {
+ CloseHandle(h);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
/**
* stat() wrapper.
*
diff --git a/dbus/dbus-sysdeps-win.h b/dbus/dbus-sysdeps-win.h
index 300c3285..29d5b0df 100644
--- a/dbus/dbus-sysdeps-win.h
+++ b/dbus/dbus-sysdeps-win.h
@@ -33,6 +33,7 @@
#include <ctype.h>
#include <malloc.h>
#include <windows.h>
+#undef interface
#include <aclapi.h>
#include <lm.h>
@@ -140,6 +141,9 @@ int _dbus_file_write (DBusFile *file,
int start,
int len);
+dbus_bool_t _dbus_file_exists (const char *filename);
+
+
#define FDATA private_data
struct DBusFile
{
@@ -167,6 +171,9 @@ int _dbus_listen_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error);
+dbus_bool_t _dbus_get_config_file_name(DBusString *config_file,
+ char *s);
+
#endif
/** @} end of sysdeps-win.h */