Commit 412538b3 authored by Simon McVittie's avatar Simon McVittie

Export dbus_setenv() as a utility function

It's sufficiently portable that GLib has an equivalent, and I really
don't want to have to either open-code it in dbus-run-session or
link dbus-run-session statically. We have enough statically-linked
rubbish already.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39196Reviewed-by: Colin Walters's avatarColin Walters <walters@verbum.org>
parent 30fa2e1a
......@@ -40,6 +40,7 @@
#include <pwd.h>
#include <grp.h>
#include <dbus/dbus-misc.h>
#include <dbus/dbus-shell.h>
#include <dbus/dbus-marshal-validate.h>
......@@ -156,8 +157,8 @@ clear_environment (DBusError *error)
}
/* Ensure the bus is set to system */
_dbus_setenv ("DBUS_STARTER_ADDRESS", DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
_dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system");
dbus_setenv ("DBUS_STARTER_ADDRESS", DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system");
#endif
return TRUE;
......
......@@ -30,6 +30,7 @@
#include "selinux.h"
#include <dbus/dbus-list.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-misc.h>
#include <dbus/dbus-sysdeps.h>
#include <string.h>
......@@ -3417,10 +3418,10 @@ test_default_session_servicedirs (void)
}
#ifdef DBUS_UNIX
if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
#endif
if (!_dbus_get_standard_session_servicedirs (&dirs))
......@@ -3550,10 +3551,10 @@ test_default_system_servicedirs (void)
}
#ifdef DBUS_UNIX
if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
#endif
if (!_dbus_get_standard_system_servicedirs (&dirs))
......
......@@ -34,6 +34,7 @@
#include "signals.h"
#include "test.h"
#include <dbus/dbus-internals.h>
#include <dbus/dbus-misc.h>
#include <string.h>
#ifdef HAVE_UNIX_FD_PASSING
......@@ -4466,7 +4467,7 @@ setenv_TEST_LAUNCH_HELPER_CONFIG(const DBusString *test_data_dir,
_dbus_verbose ("Setting TEST_LAUNCH_HELPER_CONFIG to '%s'\n",
_dbus_string_get_const_data (&full));
_dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full));
dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full));
_dbus_string_free (&full);
......
......@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-misc.h>
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
......@@ -122,8 +123,8 @@ main (int argc, char **argv)
return 1;
/* use a config file that will actually work... */
_dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG",
_dbus_string_get_const_data (&config_file));
dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG",
_dbus_string_get_const_data (&config_file));
_dbus_string_free (&config_file);
......
......@@ -28,6 +28,7 @@
#include "dbus-internals.h"
#include "dbus-message.h"
#include "dbus-marshal-validate.h"
#include "dbus-misc.h"
#include "dbus-threads-internal.h"
#include "dbus-connection-internal.h"
#include "dbus-string.h"
......@@ -293,10 +294,10 @@ init_connections_unlocked (void)
* the above code will work right
*/
if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
if (!dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
return FALSE;
if (!_dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
if (!dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
return FALSE;
if (!_dbus_register_shutdown_func (addresses_shutdown_func,
......
......@@ -44,6 +44,10 @@ void dbus_get_version (int *major_version_p,
int *minor_version_p,
int *micro_version_p);
DBUS_EXPORT
dbus_bool_t dbus_setenv (const char *variable,
const char *value);
/** @} */
DBUS_END_DECLS
......
......@@ -40,6 +40,7 @@
#include <launch.h>
#include <errno.h>
#include "dbus-misc.h"
#include "dbus-server-socket.h"
/* put other private launchd functions here */
......@@ -176,7 +177,7 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)
else
{
display = launch_data_get_string(environment_param);
_dbus_setenv ("DISPLAY", display);
dbus_setenv ("DISPLAY", display);
}
}
}
......
......@@ -29,6 +29,7 @@
#include "dbus-protocol.h"
#include "dbus-string.h"
#include "dbus-list.h"
#include "dbus-misc.h"
/* NOTE: If you include any unix/windows-specific headers here, you are probably doing something
* wrong and should be putting some code in dbus-sysdeps-unix.c or dbus-sysdeps-win.c.
......@@ -92,6 +93,8 @@ _dbus_abort (void)
}
/**
* @ingroup DBusMisc
*
* Wrapper for setenv(). If the value is #NULL, unsets
* the environment variable.
*
......@@ -100,13 +103,16 @@ _dbus_abort (void)
* we can not rely on internal implementation details of
* the underlying libc library.
*
* This function is not thread-safe, because altering the environment
* in Unix is not thread-safe in general.
*
* @param varname name of environment variable
* @param value value of environment variable
* @returns #TRUE on success.
* @param value value of environment variable, or #NULL to unset
* @returns #TRUE on success, #FALSE if not enough memory.
*/
dbus_bool_t
_dbus_setenv (const char *varname,
const char *value)
dbus_setenv (const char *varname,
const char *value)
{
_dbus_assert (varname != NULL);
......
......@@ -89,8 +89,6 @@ void _dbus_abort (void) _DBUS_GNUC_NORETURN;
dbus_bool_t _dbus_check_setuid (void);
const char* _dbus_getenv (const char *varname);
dbus_bool_t _dbus_setenv (const char *varname,
const char *value);
dbus_bool_t _dbus_clearenv (void);
char ** _dbus_get_environment (void);
......
......@@ -8,7 +8,6 @@
#endif
#include <dbus/dbus.h>
#include "dbus/dbus-sysdeps.h"
int
main (int argc, char *argv[])
......@@ -16,7 +15,7 @@ main (int argc, char *argv[])
DBusConnection *conn = NULL;
DBusError error;
_dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
dbus_error_init (&error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment