2010-03-19 12:36:49 +01:00
|
|
|
#include <config.h>
|
2003-04-07 01:07:13 +00:00
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
2009-11-30 15:59:40 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2009-07-10 19:22:54 -04:00
|
|
|
#include <unistd.h>
|
2009-11-30 15:59:40 +01:00
|
|
|
#endif
|
2003-04-07 01:07:13 +00:00
|
|
|
|
|
|
|
|
static DBusLoop *loop;
|
2003-04-10 05:12:19 +00:00
|
|
|
static dbus_bool_t already_quit = FALSE;
|
2006-10-01 17:21:03 +00:00
|
|
|
static dbus_bool_t hello_from_self_reply_received = FALSE;
|
2003-04-07 23:28:16 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
quit (void)
|
|
|
|
|
{
|
|
|
|
|
if (!already_quit)
|
|
|
|
|
{
|
|
|
|
|
_dbus_loop_quit (loop);
|
|
|
|
|
already_quit = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-03 05:22:49 +00:00
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
static void
|
|
|
|
|
die (const char *message)
|
|
|
|
|
{
|
2004-06-07 19:27:51 +00:00
|
|
|
fprintf (stderr, "*** test-service: %s", message);
|
2003-04-03 21:56:22 +00:00
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-15 15:21:43 +00:00
|
|
|
static void
|
|
|
|
|
check_hello_from_self_reply (DBusPendingCall *pcall,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
2006-08-14 19:11:35 +00:00
|
|
|
DBusMessage *echo_message, *echo_reply = NULL;
|
2005-07-15 15:21:43 +00:00
|
|
|
DBusError error;
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
|
|
|
|
|
int type;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
|
|
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
die("no memory");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo_message = (DBusMessage *)user_data;
|
|
|
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply (pcall);
|
|
|
|
|
|
|
|
|
|
type = dbus_message_get_type (reply);
|
|
|
|
|
|
|
|
|
|
if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN)
|
|
|
|
|
{
|
|
|
|
|
const char *s;
|
2006-10-01 17:21:03 +00:00
|
|
|
printf ("Reply from HelloFromSelf received\n");
|
2005-07-15 15:21:43 +00:00
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (echo_message,
|
|
|
|
|
&error,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
echo_reply = dbus_message_new_error (echo_message,
|
|
|
|
|
error.name,
|
|
|
|
|
error.message);
|
|
|
|
|
|
|
|
|
|
if (echo_reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
echo_reply = dbus_message_new_method_return (echo_message);
|
|
|
|
|
if (echo_reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (echo_reply,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
die ("No memory");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, echo_reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (echo_reply);
|
|
|
|
|
}
|
|
|
|
|
else if (type == DBUS_MESSAGE_TYPE_ERROR)
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error_from_message (&error, reply);
|
|
|
|
|
printf ("Error type in reply: %s\n", error.message);
|
|
|
|
|
|
|
|
|
|
if (strcmp (error.name, DBUS_ERROR_NO_MEMORY) != 0)
|
|
|
|
|
{
|
|
|
|
|
echo_reply = dbus_message_new_error (echo_reply,
|
|
|
|
|
error.name,
|
|
|
|
|
error.message);
|
|
|
|
|
|
|
|
|
|
if (echo_reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, echo_reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (echo_reply);
|
|
|
|
|
}
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-10-01 17:21:03 +00:00
|
|
|
_dbus_assert_not_reached ("Unexpected message received\n");
|
2005-07-15 15:21:43 +00:00
|
|
|
|
2006-10-01 17:21:03 +00:00
|
|
|
hello_from_self_reply_received = TRUE;
|
2005-07-15 15:21:43 +00:00
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
dbus_message_unref (echo_message);
|
|
|
|
|
dbus_pending_call_unref (pcall);
|
2006-09-06 22:00:07 +00:00
|
|
|
dbus_connection_unref (connection);
|
2005-07-15 15:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
handle_run_hello_from_self (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message)
|
|
|
|
|
{
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusMessage *reply, *self_message;
|
|
|
|
|
DBusPendingCall *pcall;
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("sending reply to Echo method\n");
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (message,
|
|
|
|
|
&error,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
reply = dbus_message_new_error (message,
|
|
|
|
|
error.name,
|
|
|
|
|
error.message);
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
printf ("Sending HelloFromSelf\n");
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("*** Sending message to self\n");
|
|
|
|
|
self_message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
|
|
|
|
|
"/org/freedesktop/TestSuite",
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"HelloFromSelf");
|
|
|
|
|
|
|
|
|
|
if (self_message == NULL)
|
|
|
|
|
die ("No memory");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send_with_reply (connection, self_message, &pcall, -1))
|
|
|
|
|
die("No memory");
|
|
|
|
|
|
|
|
|
|
dbus_message_ref (message);
|
|
|
|
|
if (!dbus_pending_call_set_notify (pcall, check_hello_from_self_reply, (void *)message, NULL))
|
|
|
|
|
die("No memory");
|
|
|
|
|
|
|
|
|
|
printf ("Sent HelloFromSelf\n");
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
static DBusHandlerResult
|
2003-04-07 02:01:53 +00:00
|
|
|
handle_echo (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message)
|
2003-04-03 21:56:22 +00:00
|
|
|
{
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
char *s;
|
2003-10-21 05:46:52 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("sending reply to Echo method\n");
|
2003-04-03 21:56:22 +00:00
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (message,
|
|
|
|
|
&error,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_error (message,
|
|
|
|
|
error.name,
|
|
|
|
|
error.message);
|
2003-04-03 21:56:22 +00:00
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
2003-08-12 02:43:50 +00:00
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
2003-04-03 21:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_method_return (message);
|
2003-04-03 21:56:22 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
2003-04-08 15:52:51 +00:00
|
|
|
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
if (!dbus_message_append_args (reply,
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
DBUS_TYPE_STRING, &s,
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-04-03 21:56:22 +00:00
|
|
|
die ("No memory");
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
|
|
|
|
|
fprintf (stderr, "Echo service echoed string: \"%s\"\n", s);
|
2003-04-03 21:56:22 +00:00
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
2003-04-03 21:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
2009-05-11 23:29:52 +01:00
|
|
|
static DBusHandlerResult
|
|
|
|
|
handle_delay_echo (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message)
|
|
|
|
|
{
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("sleeping for a short time\n");
|
|
|
|
|
|
2009-11-30 15:59:40 +01:00
|
|
|
_dbus_sleep_milliseconds (50);
|
2009-05-11 23:29:52 +01:00
|
|
|
|
|
|
|
|
_dbus_verbose ("sending reply to DelayEcho method\n");
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (message,
|
|
|
|
|
&error,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
reply = dbus_message_new_error (message,
|
|
|
|
|
error.name,
|
|
|
|
|
error.message);
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return (message);
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (reply,
|
|
|
|
|
DBUS_TYPE_STRING, &s,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
die ("No memory");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
fprintf (stderr, "DelayEcho service echoed string: \"%s\"\n", s);
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-21 05:46:52 +00:00
|
|
|
static void
|
|
|
|
|
path_unregistered_func (DBusConnection *connection,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
/* connection was finalized */
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 02:01:53 +00:00
|
|
|
static DBusHandlerResult
|
2003-10-21 05:46:52 +00:00
|
|
|
path_message_func (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
2003-08-18 22:43:30 +00:00
|
|
|
if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"Echo"))
|
2003-04-07 02:01:53 +00:00
|
|
|
return handle_echo (connection, message);
|
2009-05-11 23:29:52 +01:00
|
|
|
else if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"DelayEcho"))
|
|
|
|
|
return handle_delay_echo (connection, message);
|
2003-08-18 22:43:30 +00:00
|
|
|
else if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
2003-10-21 05:46:52 +00:00
|
|
|
"Exit"))
|
|
|
|
|
{
|
|
|
|
|
quit ();
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"EmitFoo"))
|
|
|
|
|
{
|
|
|
|
|
/* Emit the Foo signal */
|
|
|
|
|
DBusMessage *signal;
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
double v_DOUBLE;
|
2003-10-21 05:46:52 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("emitting signal Foo\n");
|
|
|
|
|
|
|
|
|
|
signal = dbus_message_new_signal ("/org/freedesktop/TestSuite",
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"Foo");
|
|
|
|
|
if (signal == NULL)
|
|
|
|
|
die ("No memory\n");
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
|
|
|
|
|
v_DOUBLE = 42.6;
|
2003-10-21 05:46:52 +00:00
|
|
|
if (!dbus_message_append_args (signal,
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
DBUS_TYPE_DOUBLE, &v_DOUBLE,
|
2003-10-21 05:46:52 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
die ("No memory");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, signal, NULL))
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
2005-07-15 15:21:43 +00:00
|
|
|
|
|
|
|
|
else if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"RunHelloFromSelf"))
|
|
|
|
|
{
|
|
|
|
|
return handle_run_hello_from_self (connection, message);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call (message,
|
|
|
|
|
"org.freedesktop.TestSuite",
|
|
|
|
|
"HelloFromSelf"))
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
2006-10-01 17:21:03 +00:00
|
|
|
printf ("Received the HelloFromSelf message\n");
|
2005-07-15 15:21:43 +00:00
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return (message);
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("No memory");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("No memory");
|
2006-08-30 01:27:44 +00:00
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
2005-07-15 15:21:43 +00:00
|
|
|
}
|
2003-10-21 05:46:52 +00:00
|
|
|
else
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusObjectPathVTable
|
|
|
|
|
echo_vtable = {
|
|
|
|
|
path_unregistered_func,
|
|
|
|
|
path_message_func,
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
2004-06-05 16:32:00 +00:00
|
|
|
|
|
|
|
|
static const char* echo_path = "/org/freedesktop/TestSuite" ;
|
2003-10-21 05:46:52 +00:00
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
filter_func (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
if (dbus_message_is_signal (message,
|
2005-02-17 21:19:49 +00:00
|
|
|
DBUS_INTERFACE_LOCAL,
|
2003-10-21 05:46:52 +00:00
|
|
|
"Disconnected"))
|
2003-04-07 02:01:53 +00:00
|
|
|
{
|
2003-04-07 23:28:16 +00:00
|
|
|
quit ();
|
2003-08-12 02:43:50 +00:00
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
2003-04-07 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-08-12 02:43:50 +00:00
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
2003-04-07 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
int
|
|
|
|
|
main (int argc,
|
|
|
|
|
char **argv)
|
|
|
|
|
{
|
|
|
|
|
DBusError error;
|
2003-04-03 21:56:22 +00:00
|
|
|
int result;
|
2005-07-15 15:21:43 +00:00
|
|
|
DBusConnection *connection;
|
2009-12-14 18:12:24 -05:00
|
|
|
const char *name;
|
|
|
|
|
dbus_bool_t do_fork;
|
|
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
|
{
|
|
|
|
|
name = "org.freedesktop.DBus.TestSuiteEchoService";
|
|
|
|
|
do_fork = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
name = argv[1];
|
2009-12-18 16:45:50 +01:00
|
|
|
#ifndef DBUS_WIN
|
2009-12-14 18:12:24 -05:00
|
|
|
do_fork = strcmp (argv[2], "fork") == 0;
|
2010-01-28 17:09:15 -05:00
|
|
|
#else
|
|
|
|
|
do_fork = FALSE;
|
|
|
|
|
#endif
|
2009-12-14 18:12:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The bare minimum for simulating a program "daemonizing"; the intent
|
|
|
|
|
* is to test services which move from being legacy init scripts to
|
|
|
|
|
* activated services.
|
|
|
|
|
* https://bugzilla.redhat.com/show_bug.cgi?id=545267
|
|
|
|
|
*/
|
2009-12-18 16:45:50 +01:00
|
|
|
#ifndef DBUS_WIN
|
|
|
|
|
if (do_fork)
|
2009-12-14 18:12:24 -05:00
|
|
|
{
|
|
|
|
|
pid_t pid = fork ();
|
|
|
|
|
if (pid != 0)
|
|
|
|
|
exit (0);
|
|
|
|
|
sleep (1);
|
|
|
|
|
}
|
2009-12-18 16:45:50 +01:00
|
|
|
#endif
|
2009-12-14 18:12:24 -05:00
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
dbus_error_init (&error);
|
2005-01-18 20:42:15 +00:00
|
|
|
connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
|
2003-04-03 05:22:49 +00:00
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
2003-10-21 05:46:52 +00:00
|
|
|
fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
|
|
|
|
|
error.message);
|
2003-04-03 05:22:49 +00:00
|
|
|
dbus_error_free (&error);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 01:07:13 +00:00
|
|
|
loop = _dbus_loop_new ();
|
|
|
|
|
if (loop == NULL)
|
|
|
|
|
die ("No memory\n");
|
|
|
|
|
|
|
|
|
|
if (!test_connection_setup (loop, connection))
|
|
|
|
|
die ("No memory\n");
|
2003-04-03 21:56:22 +00:00
|
|
|
|
2003-08-31 03:25:24 +00:00
|
|
|
if (!dbus_connection_add_filter (connection,
|
|
|
|
|
filter_func, NULL, NULL))
|
2003-04-03 21:56:22 +00:00
|
|
|
die ("No memory");
|
|
|
|
|
|
2003-10-21 05:46:52 +00:00
|
|
|
if (!dbus_connection_register_object_path (connection,
|
|
|
|
|
echo_path,
|
|
|
|
|
&echo_vtable,
|
2005-04-24 14:04:16 +00:00
|
|
|
(void*) 0xdeadbeef))
|
2003-10-21 05:46:52 +00:00
|
|
|
die ("No memory");
|
2003-09-22 05:45:59 +00:00
|
|
|
|
2005-04-24 14:04:16 +00:00
|
|
|
{
|
|
|
|
|
void *d;
|
|
|
|
|
if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
|
|
|
|
|
die ("No memory");
|
|
|
|
|
if (d != (void*) 0xdeadbeef)
|
|
|
|
|
die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
|
|
|
|
|
}
|
2009-12-14 18:12:24 -05:00
|
|
|
|
|
|
|
|
result = dbus_bus_request_name (connection, name,
|
2005-01-18 20:42:15 +00:00
|
|
|
0, &error);
|
2003-04-03 21:56:22 +00:00
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
2004-06-05 16:32:00 +00:00
|
|
|
fprintf (stderr, "Error %s\n", error.message);
|
2003-04-11 04:52:29 +00:00
|
|
|
_dbus_verbose ("*** Failed to acquire service: %s\n",
|
|
|
|
|
error.message);
|
2003-04-03 21:56:22 +00:00
|
|
|
dbus_error_free (&error);
|
2003-04-07 23:28:16 +00:00
|
|
|
exit (1);
|
2003-04-03 21:56:22 +00:00
|
|
|
}
|
2005-07-15 15:21:43 +00:00
|
|
|
|
2003-04-10 05:12:19 +00:00
|
|
|
_dbus_verbose ("*** Test service entering main loop\n");
|
2003-04-07 01:07:13 +00:00
|
|
|
_dbus_loop_run (loop);
|
2005-07-15 15:21:43 +00:00
|
|
|
|
2003-04-07 23:28:16 +00:00
|
|
|
test_connection_shutdown (loop, connection);
|
2003-08-31 03:25:24 +00:00
|
|
|
|
|
|
|
|
dbus_connection_remove_filter (connection, filter_func, NULL);
|
2003-04-07 23:28:16 +00:00
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
dbus_connection_unref (connection);
|
2003-04-07 01:07:13 +00:00
|
|
|
|
|
|
|
|
_dbus_loop_unref (loop);
|
|
|
|
|
loop = NULL;
|
2003-04-03 21:56:22 +00:00
|
|
|
|
|
|
|
|
dbus_shutdown ();
|
2003-04-07 23:28:16 +00:00
|
|
|
|
2003-04-09 20:31:21 +00:00
|
|
|
_dbus_verbose ("*** Test service exiting\n");
|
2003-04-03 05:22:49 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|