Commit 3c8db267 authored by Anders Carlsson's avatar Anders Carlsson

2003-02-17 Anders Carlsson <andersca@codefactory.se>

	* bus/activation.c: (bus_activation_init), (child_setup),
	(bus_activation_activate_service):
	* bus/activation.h:
	* bus/main.c: (main):
	Set DBUS_ADDRESS environment variable.

	* dbus/dbus-errors.c: (dbus_set_error):
	Don't use va_copy since that's a C99 feature.

	* dbus/dbus-sysdeps.c: (_dbus_setenv), (do_exec),
	(_dbus_spawn_async):
	* dbus/dbus-sysdeps.h:
	Add child_setup_func to _dbus_spawn_async.

	* doc/dbus-specification.sgml:
	Update specification.

	* test/spawn-test.c: (setup_func), (main):
	Fix test.
parent 8faf99b1
2003-02-17 Anders Carlsson <andersca@codefactory.se>
* bus/activation.c: (bus_activation_init), (child_setup),
(bus_activation_activate_service):
* bus/activation.h:
* bus/main.c: (main):
Set DBUS_ADDRESS environment variable.
* dbus/dbus-errors.c: (dbus_set_error):
Don't use va_copy since that's a C99 feature.
* dbus/dbus-sysdeps.c: (_dbus_setenv), (do_exec),
(_dbus_spawn_async):
* dbus/dbus-sysdeps.h:
Add child_setup_func to _dbus_spawn_async.
* doc/dbus-specification.sgml:
Update specification.
* test/spawn-test.c: (setup_func), (main):
Fix test.
2003-02-17 Alexander Larsson <alexl@redhat.com>
* dbus/dbus-connection.c (_dbus_connection_handler_destroyed_locked):
......
......@@ -34,6 +34,7 @@
#define DBUS_SERVICE_EXEC "Exec"
static DBusHashTable *activation_entries = NULL;
static char *server_address = NULL;
typedef struct
{
......@@ -174,10 +175,14 @@ load_directory (const char *directory)
void
bus_activation_init (const char **directories)
bus_activation_init (const char *address,
const char **directories)
{
int i;
/* FIXME: We should split up the server addresses. */
BUS_HANDLE_OOM (server_address = _dbus_strdup (address));
BUS_HANDLE_OOM (activation_entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
(DBusFreeFunction)bus_activation_entry_free));
......@@ -191,6 +196,13 @@ bus_activation_init (const char **directories)
}
}
static void
child_setup (void *data)
{
/* FIXME: Check return value in case of OOM */
_dbus_setenv ("DBUS_ADDRESS", server_address);
}
dbus_bool_t
bus_activation_activate_service (const char *service_name,
DBusError *error)
......@@ -212,7 +224,9 @@ bus_activation_activate_service (const char *service_name,
argv[0] = entry->exec;
argv[1] = NULL;
if (!_dbus_spawn_async (argv, error))
if (!_dbus_spawn_async (argv,
child_setup, NULL,
error))
return FALSE;
return TRUE;
......
......@@ -26,7 +26,8 @@
#include <dbus/dbus.h>
void bus_activation_init (const char **paths);
void bus_activation_init (const char *address,
const char **paths);
dbus_bool_t bus_activation_activate_service (const char *service_name,
DBusError *error);
......
......@@ -82,6 +82,15 @@ main (int argc, char **argv)
return 1;
}
server = dbus_server_listen (argv[1], &result);
if (server == NULL)
{
_dbus_warn ("Failed to start server on %s: %s\n",
argv[1], dbus_result_to_string (result));
return 1;
}
if (argc < 3)
{
_dbus_warn ("No service location given, not activating activation\n");
......@@ -90,15 +99,7 @@ main (int argc, char **argv)
{
char *paths[] = { argv[2], NULL };
bus_activation_init (paths);
}
server = dbus_server_listen (argv[1], &result);
if (server == NULL)
{
_dbus_warn ("Failed to start server on %s: %s\n",
argv[1], dbus_result_to_string (result));
return 1;
bus_activation_init (argv[1], paths);
}
setup_server (server);
......
......@@ -238,13 +238,14 @@ dbus_set_error (DBusError *error,
va_start (args, format);
va_copy (args2, args);
/* Measure the message length */
message_length = vsnprintf (&c, 1,format, args) + 1;
message = dbus_malloc (message_length);
va_end (args);
va_start (args, format);
vsprintf (message, format, args2);
if (!message)
......
......@@ -66,6 +66,19 @@ _dbus_abort (void)
_exit (1); /* in case someone manages to ignore SIGABRT */
}
/**
* Wrapper for setenv().
*
* @param varname name of environment variable
* @param value value of environment variable
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_setenv (const char *varname, const char *value)
{
return (setenv (varname, value, TRUE) == 0);
}
/**
* Wrapper for getenv().
*
......@@ -1564,12 +1577,18 @@ read_ints (int fd,
}
static void
do_exec (int child_err_report_fd,
char **argv)
do_exec (int child_err_report_fd,
char **argv,
DBusSpawnChildSetupFunc child_setup,
void *user_data)
{
#ifdef DBUS_BUILD_TESTS
int i, max_open;
#endif
if (child_setup)
(* child_setup) (user_data);
#ifdef DBUS_BUILD_TESTS
max_open = sysconf (_SC_OPEN_MAX);
......@@ -1593,8 +1612,10 @@ do_exec (int child_err_report_fd,
}
dbus_bool_t
_dbus_spawn_async (char **argv,
DBusError *error)
_dbus_spawn_async (char **argv,
DBusSpawnChildSetupFunc child_setup,
void *user_data,
DBusError *error)
{
int pid = -1, grandchild_pid;
int child_err_report_pipe[2] = { -1, -1 };
......@@ -1643,7 +1664,8 @@ _dbus_spawn_async (char **argv,
else if (grandchild_pid == 0)
{
do_exec (child_err_report_pipe[1],
argv);
argv,
child_setup, user_data);
}
else
{
......
......@@ -49,7 +49,8 @@ DBUS_BEGIN_DECLS;
void _dbus_abort (void);
const char* _dbus_getenv (const char *varname);
dbus_bool_t _dbus_setenv (const char *varname,
const char *value);
int _dbus_read (int fd,
DBusString *buffer,
......@@ -148,8 +149,14 @@ dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
int n_bytes);
const char *_dbus_errno_to_string (int errnum);
dbus_bool_t _dbus_spawn_async (char **argv,
DBusError *error);
typedef void (* DBusSpawnChildSetupFunc) (void *user_data);
dbus_bool_t _dbus_spawn_async (char **argv,
DBusSpawnChildSetupFunc child_setup,
void *user_data,
DBusError *error);
void _dbus_disable_sigpipe (void);
......
This diff is collapsed.
......@@ -5,6 +5,12 @@
#undef DBUS_COMPILATION
#include <stdio.h>
static void
setup_func (void *data)
{
printf ("entering setup func.\n");
}
int
main (int argc, char **argv)
{
......@@ -24,7 +30,7 @@ main (int argc, char **argv)
argv_copy [i] = argv[i + 1];
argv_copy[argc - 1] = NULL;
if (!_dbus_spawn_async (argv_copy, &error))
if (!_dbus_spawn_async (argv_copy, setup_func, NULL, &error))
{
fprintf (stderr, "Could not launch application: \"%s\"\n",
error.message);
......
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