Ticket #17950: patch-launchd-part2.diff

File patch-launchd-part2.diff, 5.4 KB (added by mtalexander (Mike Alexander), 15 years ago)

Patch for changes to launchd support.

  • dbus-server-launchd.c

    old new  
    2929
    3030#include "dbus-server-socket.h"
    3131#include "dbus-server-launchd.h"
     32#include "dbus-transport-protected.h"
     33#include "dbus-transport-unix.h"
    3234
    3335/**
    3436 * @defgroup DBusServerLaunchd DBusServer implementations for Launchd
     
    5658  launch_data_t sockets_dict, checkin_response;
    5759  launch_data_t checkin_request;
    5860  launch_data_t listening_fd_array, listening_fd;
     61  dbus_bool_t supported, retval;
    5962
    6063  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
    6164
     
    6467      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
    6568      return NULL;
    6669    }
    67   if (!_dbus_string_append (&address, "launchd:key="))
     70 
     71  if (strcmp (socket_key, "session") != 0)
    6872    {
    69       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
     73      dbus_set_error (error, DBUS_ERROR_FAILED, "Not server socket %s\n", socket_key);
    7074      goto l_failed_0;
    7175    }
    72   if (!_dbus_string_append (&address, socket_key))
     76  supported = FALSE;
     77  retval = _dbus_lookup_session_address (&supported, &address, error);
     78  if ( !(supported && retval) )
    7379    {
    74       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
     80      if (!dbus_error_is_set(error))
     81        {
     82          dbus_set_error(error, DBUS_ERROR_FAILED,
     83                         "Unable to get session socket address\n");
     84        }
    7585      goto l_failed_0;
    7686    }
    7787
     
    146156  return NULL;
    147157}
    148158
     159/**
     160 * Opens launchd transport types.
     161 *
     162 * @param entry the address entry to try opening
     163 * @param transport_p return location for the opened transport
     164 * @param error error to be set
     165 * @returns result of the attempt
     166 */
     167DBusTransportOpenResult
     168_dbus_transport_open_launchd (DBusAddressEntry  *entry,
     169                              DBusTransport    **transport_p,
     170                              DBusError         *error)
     171{
     172  const char *method, *path;
     173 
     174  method = dbus_address_entry_get_method (entry);
     175  _dbus_assert (method != NULL);
     176
     177  if (strcmp (method, "launchd") == 0)
     178    {
     179      const char *socket_key = dbus_address_entry_get_value (entry, "key");
     180      DBusString address, prefix;
     181      dbus_bool_t supported, retval;
     182      int prefixlen;
     183     
     184      _dbus_verbose ("Opening launchd transport\n");
     185
     186      if (socket_key == NULL)
     187        {
     188          _dbus_set_bad_address (error, "launchd", "key", NULL);
     189          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
     190        }
     191     
     192      if (strcmp (socket_key, "session") != 0)
     193        {
     194          _dbus_set_bad_address (error, NULL, NULL,
     195                                 "launchd key must be 'session'\n");
     196          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
     197        }
     198     
     199      if (!_dbus_string_init (&address))
     200        {
     201          dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
     202          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
     203        }
     204 
     205      supported = FALSE;
     206      retval = _dbus_lookup_session_address (&supported, &address, error);
     207      _dbus_string_init_const (&prefix, "unix:path=");
     208      prefixlen = _dbus_string_get_length(&prefix);
     209      if ( !(supported && retval) ||
     210           !_dbus_string_equal_substring (&address, 0, prefixlen, &prefix, 0))
     211        {
     212          if (!dbus_error_is_set(error))
     213            {
     214              dbus_set_error(error, DBUS_ERROR_FAILED,
     215                             "Unable to get session socket address\n");
     216            }
     217          goto l_failed_1;
     218        }
     219      path = _dbus_string_get_const_data_len ( &address, prefixlen,
     220                                               _dbus_string_get_length( &address) - prefixlen );
     221      *transport_p = _dbus_transport_new_for_domain_socket ( path, FALSE, error );
     222     
     223      if (*transport_p == NULL)
     224        {
     225          _DBUS_ASSERT_ERROR_IS_SET (error);
     226          goto l_failed_1;
     227        }
     228     
     229      _dbus_verbose ("Opened launchd socket at %s\n", path);
     230
     231      _dbus_string_free (&address);
     232      _dbus_string_free (&prefix);
     233
     234      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
     235      return DBUS_TRANSPORT_OPEN_OK;
     236       
     237       
     238      l_failed_1:
     239      _dbus_string_free (&prefix);
     240
     241      l_failed_0:
     242      _dbus_string_free (&address);
     243   
     244      return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
     245    }
     246  else
     247    {
     248      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
     249      return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
     250    }
     251}
     252
    149253/** @} */
    150254
  • dbus-transport-protected.h

    old new  
    138138                                                                DBusTransport    **transport_p,
    139139                                                                DBusError         *error);
    140140
     141DBusTransportOpenResult _dbus_transport_open_launchd (DBusAddressEntry  *entry,
     142                                                      DBusTransport    **transport_p,
     143                                                      DBusError         *error);
     144
    141145DBUS_END_DECLS
    142146
    143147#endif /* DBUS_TRANSPORT_PROTECTED_H */
  • dbus-transport.c

    old new  
    333333  { _dbus_transport_open_socket },
    334334  { _dbus_transport_open_platform_specific },
    335335  { _dbus_transport_open_autolaunch }
     336#ifdef DBUS_ENABLE_LAUNCHD
     337  , {_dbus_transport_open_launchd }
     338#endif
    336339#ifdef DBUS_BUILD_TESTS
    337340  , { _dbus_transport_open_debug_pipe }
    338341#endif