From 139144ee92b50e1fe71a918338c40f3c205c9577 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 9 Jun 2010 08:37:09 +0200 Subject: [PATCH 1/1] Added dbus client config api. --- cmake/dbus/CMakeLists.txt | 2 + dbus/Makefile.am | 2 + dbus/dbus-bus.c | 3 +- dbus/dbus-config.c | 139 +++++++++++++++++++++++++++++++++++++++++ dbus/dbus-config.h | 70 +++++++++++++++++++++ dbus/dbus-internals.c | 7 +- dbus/dbus-memory.c | 15 +++-- dbus/dbus-sysdeps-unix.c | 9 ++- dbus/dbus-sysdeps-util-unix.c | 2 +- dbus/dbus-sysdeps-win.c | 9 ++- dbus/dbus-sysdeps.c | 3 +- dbus/dbus-test.c | 3 +- 12 files changed, 242 insertions(+), 22 deletions(-) create mode 100644 dbus/dbus-config.c create mode 100644 dbus/dbus-config.h diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index 2a9f07c..2b3ebd0 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -124,6 +124,7 @@ endif(UNIX) ### daemon or test programs (all symbols in here should ### be underscore-prefixed) set (DBUS_SHARED_SOURCES + ${DBUS_DIR}/dbus-config.c ${DBUS_DIR}/dbus-dataslot.c ${DBUS_DIR}/dbus-file.c ${DBUS_DIR}/dbus-hash.c @@ -158,6 +159,7 @@ set (DBUS_SHARED_HEADERS ### to be unless they move to DBUS_SHARED_SOURCES later) set (DBUS_UTIL_SOURCES ${DBUS_DIR}/dbus-auth-util.c + ${DBUS_DIR}/dbus-config.h ${DBUS_DIR}/dbus-credentials-util.c ${DBUS_DIR}/dbus-mainloop.c ${DBUS_DIR}/dbus-marshal-byteswap-util.c diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 906b4c7..41eed0f 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -184,6 +184,8 @@ DBUS_LIB_SOURCES= \ ### daemon or test programs (all symbols in here should ### be underscore-prefixed) DBUS_SHARED_SOURCES= \ + dbus-config.c \ + dbus-config.h \ dbus-dataslot.c \ dbus-dataslot.h \ dbus-file.c \ diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 92ec20e..d160a2d 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -24,6 +24,7 @@ #include #include "dbus-bus.h" +#include "dbus-config.h" #include "dbus-protocol.h" #include "dbus-internals.h" #include "dbus-message.h" @@ -278,7 +279,7 @@ init_connections_unlocked (void) if (bus_connection_addresses[DBUS_BUS_STARTER] != NULL) { - s = _dbus_getenv ("DBUS_STARTER_BUS_TYPE"); + s = _dbus_config_starter_bus_type(); if (s != NULL) { diff --git a/dbus/dbus-config.c b/dbus/dbus-config.c new file mode 100644 index 0000000..70b5509 --- /dev/null +++ b/dbus/dbus-config.c @@ -0,0 +1,139 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-config.c client config api implementation + * + * Copyright (C) 2010 Ralf Habacker + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "dbus-config.h" +#include "dbus-sysdeps.h" + +char * +_dbus_config_block_on_abort() +{ + return _dbus_getenv ("DBUS_BLOCK_ON_ABORT"); +} + +char * +_dbus_config_common_program_files() +{ + return _dbus_getenv ("CommonProgramFiles"); +} + +char * +_dbus_config_datadir() +{ + return _dbus_getenv ("DBUS_DATADIR"); +} + +char * +_dbus_config_debug_output() +{ + return _dbus_getenv ("DBUS_DEBUG_OUTPUT"); +} + +char * +_dbus_config_disable_mem_pools() +{ + return _dbus_getenv ("DBUS_DISABLE_MEM_POOLS"); +} + +char * +_dbus_config_homedrive() +{ + return _dbus_getenv("HOMEDRIVE"); +} + +char * +_dbus_config_homepath() +{ + return _dbus_getenv("HOMEPATH"); +} + +char * +_dbus_config_fatal_warnings() +{ + return _dbus_getenv ("DBUS_FATAL_WARNINGS"); +} + +char * +_dbus_config_malloc_fail_nth() +{ + return _dbus_getenv ("DBUS_MALLOC_FAIL_NTH"); +} + +char * +_dbus_config_malloc_fail_greater_than() +{ + return _dbus_getenv ("DBUS_MALLOC_FAIL_GREATER_THAN"); +} + +char * +_dbus_config_malloc_guards() +{ + return _dbus_getenv ("DBUS_MALLOC_GUARDS"); +} + +char * +_dbus_config_malloc_backtraces() +{ + return _dbus_getenv ("DBUS_MALLOC_BACKTRACES"); +} + +char * +_dbus_config_starter_bus_type() +{ + return _dbus_getenv ("DBUS_STARTER_BUS_TYPE"); +} + +char * +_dbus_config_test_malloc_failures() +{ + return _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES"); +} + +char * +_dbus_config_test_homedir() +{ + return _dbus_getenv ("DBUS_TEST_HOMEDIR"); +} + +char * +_dbus_config_test_data() +{ + return _dbus_getenv ("DBUS_TEST_DATA"); +} + +char * +_dbus_config_xdg_data_home() +{ + return _dbus_getenv ("XDG_DATA_HOME"); +} + +char * +_dbus_config_xdg_data_dirs() +{ + return _dbus_getenv ("XDG_DATA_DIRS"); +} + +char * +_dbus_config_verbose() +{ + return _dbus_getenv ("DBUS_VERBOSE"); +} diff --git a/dbus/dbus-config.h b/dbus/dbus-config.h new file mode 100644 index 0000000..e93e2fa --- /dev/null +++ b/dbus/dbus-config.h @@ -0,0 +1,70 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-config.h client config api header + * + * Copyright (C) 2010 Ralf Habacker + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef DBUS_CONFIG_H +#define DBUS_CONFIG_H + +// session bus address +// system bus address +// activation bus address + +char * +_dbus_config_block_on_abort(); +char * +_dbus_config_common_program_files(); +char * +_dbus_config_datadir(); +char * +_dbus_config_debug_output(); +char * +_dbus_config_disable_mem_pools(); +char * +_dbus_config_fatal_warnings(); +char * +_dbus_config_homedrive(); +char * +_dbus_config_homepath(); +char * +_dbus_config_malloc_backtraces(); +char * +_dbus_config_malloc_fail_nth(); +char * +_dbus_config_malloc_fail_greater_than(); +char * +_dbus_config_malloc_guards(); +char * +_dbus_config_starter_bus_type(); +char * +_dbus_config_test_malloc_failures(); +char * +_dbus_config_test_homedir(); +char * +_dbus_config_test_data(); +char * +_dbus_config_verbose(); +char * +_dbus_config_xdg_data_home(); +char * +_dbus_config_xdg_data_dirs(); + +#endif diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 1ab6731..ad0c932 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -22,6 +22,7 @@ */ #include +#include "dbus-config.h" #include "dbus-internals.h" #include "dbus-protocol.h" #include "dbus-marshal-basic.h" @@ -207,7 +208,7 @@ init_warnings(void) if (!warn_initted) { const char *s; - s = _dbus_getenv ("DBUS_FATAL_WARNINGS"); + s = _dbus_config_fatal_warnings(); if (s && *s) { if (*s == '0') @@ -313,7 +314,7 @@ _dbus_verbose_init (void) { if (!verbose_initted) { - const char *p = _dbus_getenv ("DBUS_VERBOSE"); + const char *p = _dbus_config_verbose(); verbose = p != NULL && *p == '1'; verbose_initted = TRUE; #ifdef DBUS_USE_OUTPUT_DEBUG_STRING @@ -1003,7 +1004,7 @@ _dbus_test_oom_handling (const char *description, _dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n", description, approx_mallocs); - setting = _dbus_getenv ("DBUS_TEST_MALLOC_FAILURES"); + setting = _dbus_config_test_malloc_failures(); if (setting != NULL) { DBusString str; diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index a37759c..6754240 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -22,6 +22,7 @@ */ #include +#include "dbus-config.h" #include "dbus-memory.h" #include "dbus-internals.h" #include "dbus-sysdeps.h" @@ -128,33 +129,33 @@ _dbus_initialize_malloc_debug (void) { debug_initialized = TRUE; - if (_dbus_getenv ("DBUS_MALLOC_FAIL_NTH") != NULL) + if (_dbus_config_malloc_fail_nth() != NULL) { - fail_nth = atoi (_dbus_getenv ("DBUS_MALLOC_FAIL_NTH")); + fail_nth = atoi (_dbus_config_malloc_fail_nth()); fail_alloc_counter = fail_nth; _dbus_verbose ("Will fail malloc every %d times\n", fail_nth); } - if (_dbus_getenv ("DBUS_MALLOC_FAIL_GREATER_THAN") != NULL) + if (_dbus_config_malloc_fail_greater_than() != NULL) { - fail_size = atoi (_dbus_getenv ("DBUS_MALLOC_FAIL_GREATER_THAN")); + fail_size = atoi (_dbus_config_malloc_fail_greater_than()); _dbus_verbose ("Will fail mallocs over %ld bytes\n", (long) fail_size); } - if (_dbus_getenv ("DBUS_MALLOC_GUARDS") != NULL) + if (_dbus_config_malloc_guards() != NULL) { guards = TRUE; _dbus_verbose ("Will use malloc guards\n"); } - if (_dbus_getenv ("DBUS_DISABLE_MEM_POOLS") != NULL) + if (_dbus_config_disable_mem_pools() != NULL) { disable_mem_pools = TRUE; _dbus_verbose ("Will disable memory pools\n"); } - if (_dbus_getenv ("DBUS_MALLOC_BACKTRACES") != NULL) + if (_dbus_config_malloc_backtraces() != NULL) { backtrace_on_fail_alloc = TRUE; _dbus_verbose ("Will backtrace on failing a malloc\n"); diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index ebe9bdd..72078d0 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -24,6 +24,7 @@ #include +#include "dbus-config.h" #include "dbus-internals.h" #include "dbus-sysdeps.h" #include "dbus-sysdeps-unix.h" @@ -3255,8 +3256,8 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) if (!_dbus_string_init (&servicedir_path)) return FALSE; - xdg_data_home = _dbus_getenv ("XDG_DATA_HOME"); - xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS"); + xdg_data_home = _dbus_config_xdg_data_home(); + xdg_data_dirs = _dbus_config_xdg_data_dirs(); if (xdg_data_dirs != NULL) { @@ -3343,7 +3344,7 @@ _dbus_get_standard_system_servicedirs (DBusList **dirs) if (!_dbus_string_init (&servicedir_path)) return FALSE; - xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS"); + xdg_data_dirs = _dbus_config_xdg_data_dirs(); if (xdg_data_dirs != NULL) { @@ -3457,7 +3458,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, { const char *override; - override = _dbus_getenv ("DBUS_TEST_HOMEDIR"); + override = _dbus_config_test_homedir(); if (override != NULL && *override != '\0') { _dbus_string_set_length (&homedir, 0); diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index 6c50f17..78b331d 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -115,7 +115,7 @@ _dbus_become_daemon (const DBusString *pidfile, dup2 (dev_null_fd, 0); dup2 (dev_null_fd, 1); - s = _dbus_getenv ("DBUS_DEBUG_OUTPUT"); + s = _dbus_config_debug_output(); if (s == NULL || *s == '\0') dup2 (dev_null_fd, 2); else diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 0f4e1cd..8e80cde 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -36,6 +36,7 @@ #endif #endif +#include "dbus-config.h" #include "dbus-internals.h" #include "dbus-config-parser.h" #include "dbus-sysdeps.h" @@ -2803,7 +2804,7 @@ _dbus_get_standard_session_servicedirs (DBusList **dirs) #ifdef DBUS_WINCE { /* On Windows CE, we adjust datadir dynamically to installation location. */ - const char *data_dir = _dbus_getenv ("DBUS_DATADIR"); + const char *data_dir = _dbus_config_datadir(); if (data_dir != NULL) { @@ -3141,13 +3142,13 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, if (!_dbus_string_init (&homedir)) return FALSE; - homedrive = _dbus_getenv("HOMEDRIVE"); + homedrive = _dbus_config_homedrive(); if (homedrive != NULL && *homedrive != '\0') { _dbus_string_append(&homedir,homedrive); } - homepath = _dbus_getenv("HOMEPATH"); + homepath = _dbus_config_homepath(); if (homepath != NULL && *homepath != '\0') { _dbus_string_append(&homedir,homepath); @@ -3157,7 +3158,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, { const char *override; - override = _dbus_getenv ("DBUS_TEST_HOMEDIR"); + override = _dbus_config_test_homedir(); if (override != NULL && *override != '\0') { _dbus_string_set_length (&homedir, 0); diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index bab516d..fd1ebd6 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -23,6 +23,7 @@ */ #include +#include "dbus-config.h" #include "dbus-internals.h" #include "dbus-sysdeps.h" #include "dbus-threads.h" @@ -83,7 +84,7 @@ _dbus_abort (void) _dbus_print_backtrace (); - s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT"); + s = _dbus_config_block_on_abort(); if (s && *s) { /* don't use _dbus_warn here since it can _dbus_abort() */ diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c index 99becb0..561b0b9 100644 --- a/dbus/dbus-test.c +++ b/dbus/dbus-test.c @@ -22,6 +22,7 @@ */ #include +#include "dbus-config.h" #include "dbus-test.h" #include "dbus-sysdeps.h" #include "dbus-internals.h" @@ -103,7 +104,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *speci die ("debug threads init"); if (test_data_dir == NULL) - test_data_dir = _dbus_getenv ("DBUS_TEST_DATA"); + test_data_dir = _dbus_config_test_data(); if (test_data_dir != NULL) printf ("Test data in %s\n", test_data_dir); -- 1.7.0.2.msysgit.0