1a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
2dbecdeabb20e0ce11121819c63373f0afba57c58Marcus Brinkmann#include <config.h>
3a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters#include "../test-utils.h"
4a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
5a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersstatic DBusLoop *loop;
6a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
7a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersstatic void
8a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersdie (const char *message)
9a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters{
10a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  fprintf (stderr, "*** test-shutdown: %s", message);
11a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  exit (1);
12a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters}
13a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
14a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersstatic void
153c89788fa483ebda858ab66797e2834af94b798fKjartan Maraasopen_destroy_shared_session_bus_connection (void)
16a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters{
17a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  DBusError error;
18a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  DBusConnection *connection;
19a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  char *session_addr_no_guid;
20a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  char *comma;
21a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
22a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  dbus_error_init (&error);
23a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
24a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  session_addr_no_guid = strdup (getenv ("DBUS_SESSION_BUS_ADDRESS"));
25a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  comma = strchr (session_addr_no_guid, ',');
26a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  if (comma == NULL)
27a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters    die ("Couldn't find GUID in session bus address");
28a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  *comma = '\0';
29a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
30a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  connection = dbus_connection_open (session_addr_no_guid, &error);
31a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  free (session_addr_no_guid);
32a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  if (connection == NULL)
33a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters    die ("Failed to open connection to temp session bus\n");
34a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
35a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  loop = _dbus_loop_new ();
36a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  if (loop == NULL)
37a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters    die ("No memory\n");
38a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
39a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  if (!test_connection_setup (loop, connection))
40a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters    die ("No memory\n");
41a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
42a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  test_connection_shutdown (loop, connection);
43a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
44a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  _dbus_loop_unref (loop);
45a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
46a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  dbus_connection_unref (connection);
47a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters}
48a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
49a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersint
50a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Waltersmain (int    argc,
51a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters      char **argv)
52a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters{
53a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  open_destroy_shared_session_bus_connection ();
54a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
55a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  dbus_shutdown ();
56a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
57a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  open_destroy_shared_session_bus_connection ();
58a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
59a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  dbus_shutdown ();
60a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
61a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  open_destroy_shared_session_bus_connection ();
62a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
63a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  dbus_shutdown ();
64a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
65a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  _dbus_verbose ("*** Test shutdown exiting\n");
66a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters
67a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters  return 0;
68a73a79a155e97a3bd0d3ce5001ca6b9db803eeebColin Walters}
69