* 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.
This commit is contained in:
Ralf Habacker 2007-06-01 22:05:42 +00:00
parent 8d3dbfb103
commit 378053ba59
4 changed files with 151 additions and 0 deletions

View file

@ -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

View file

@ -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)
{

View file

@ -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.
*

View file

@ -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 */