Ticket #27555: 0004-enable-launchd.patch

File 0004-enable-launchd.patch, 14.3 KB (added by monty19@…, 13 years ago)

New 0004-enable-launchd.patch

  • README.launchd

    diff -urN dbus-1.4.0-old/README.launchd dbus-1.4.0-new/README.launchd
    old new  
     1Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger".
     2dbus uses this service to provide a common session bus address for each user
     3and so deprecates the X11 enabled dbus-launcher.
     4
     5[1] http://developer.apple.com/MacOsX/launchd.html
     6[2] http://launchd.macosforge.org/
     7
     8
     9Setup
     10===
     11
     12Configure with --enable-launchd and --without-x (X11 should not harm but it's
     13simply not necessary any more)
     14After installation, to prevent a reboot, load the dbus session starter into
     15launchd by executing:
     16$ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist
     17
     18You can change the launch agent dir via configure, but it's not recommended.
     19Make sure to execute the above line as the actual user for which you want to
     20use a session bus since launchd manages its agents on a per user basis.
     21
     22
     23How it works
     24===
     25
     26Launchd allocates a socket and provides the unix path to it via the variable
     27DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process
     28spawned by launchd (or dbus-daemon, if stared by launchd) can access it through
     29its own environment. Other processes can query launchd for it by executing:
     30$ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET
     31However, this is normally done by the dbus client lib for you.
     32
     33If launchd start dbus-daemon with a config file containing a "launchd:env=FOO"
     34address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET,
     35the daemon will get the file descriptor from launchd and start listening on it.
     36The environment variable is used to get the actual socket path which is passed
     37to every service spawned by dbus-daemon as a result from autolaunch messages.
     38Please note that it's not possible to start dbus-daemon manually when using a
     39"launchd:" address. Only child processes of launchd can access the above
     40mentioned file descriptor!
     41
     42To create custom buses just set up an other launch agent. As a quick start copy
     43/Library/LaunchAgents/org.freedesktop.dbus-session.plist, change the label
     44to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value,
     45i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set
     46in the config file for your new bus in the <listen> element (see session.config).
     47Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start
     48dbus-daemon with "--config-file=/opt/local/etc/dbus-1/foo.conf" instead of
     49"--session". Now load the new plist onto launchd as described in the setup
     50section of this document.
     51Executing "launchctl export" should now give you two sockets, one in
     52DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET.
     53To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET".
     54
     55Since Mac OS X 10.5 "Leopard" you can also configure launchd to start
     56dbus-daemon on demand as soon as some process connects to the socket. Since
     57it's broken on 10.4 this feature is disabled per default. Look at
     58/Library/LaunchAgents/org.freedesktop.dbus-session.plist to change it.
     59
     60On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used
     61but if it's not set, launchd is queried for the session bus socket.
  • bus/Makefile.am

    diff -urN dbus-1.4.0-old/bus/Makefile.am dbus-1.4.0-new/bus/Makefile.am
    old new  
    99
    1010CONFIG_IN_FILES=                                \
    1111        session.conf.in                         \
    12         system.conf.in
     12        system.conf.in                          \
     13        org.freedesktop.dbus-session.plist.in
    1314
    1415config_DATA=                                    \
    1516        session.conf                            \
    1617        system.conf
    1718
     19if DBUS_ENABLE_LAUNCHD
     20agentdir=$(LAUNCHD_AGENT_DIR)
     21agent_DATA=org.freedesktop.dbus-session.plist
     22endif
     23
    1824if DBUS_USE_LIBXML
    1925XML_SOURCES=config-loader-libxml.c
    2026endif
  • bus/org.freedesktop.dbus-session.plist.in

    diff -urN dbus-1.4.0-old/bus/org.freedesktop.dbus-session.plist.in dbus-1.4.0-new/bus/org.freedesktop.dbus-session.plist.in
    old new  
     1<?xml version="1.0" encoding="UTF-8"?>
     2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
     3<plist version="1.0">
     4<dict>
     5        <key>Label</key>
     6        <string>org.freedesktop.dbus-session</string>
     7
     8        <key>ServiceIPC</key>
     9        <true/>
     10
     11        <!-- bug in 10.4's launchd - on-demand loading does not work -->
     12        <key>OnDemand</key>
     13        <false />
     14
     15        <key>ProgramArguments</key>
     16        <array>
     17                <string>@DBUS_DAEMONDIR@/dbus-daemon</string>
     18                <string>--nofork</string>
     19                <string>--session</string>
     20        </array>
     21
     22        <key>Sockets</key>
     23        <dict>
     24                <key>unix_domain_listener</key>
     25                <dict>
     26                        <key>SecureSocketWithKey</key>
     27                        <string>DBUS_LAUNCHD_SESSION_BUS_SOCKET</string>
     28                </dict>
     29        </dict>
     30</dict>
     31</plist>
     32
  • configure.in

    diff -urN dbus-1.4.0-old/configure.in dbus-1.4.0-new/configure.in
    old new  
    135135AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto)
    136136AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)
    137137AC_ARG_ENABLE(userdb-cache, AS_HELP_STRING([--enable-userdb-cache],[build with userdb-cache support]),enable_userdb_cache=$enableval,enable_userdb_cache=yes)
     138AC_ARG_ENABLE(launchd, AS_HELP_STRING([--enable-launchd],[build with launchd auto-launch support]),enable_launchd=$enableval,enable_launchd=auto)
    138139
    139140AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use]))
    140141AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install]))
     
    144145AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon]))
    145146AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip]))
    146147AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner]))
     148AC_ARG_WITH(launchd-agent-dir, AS_HELP_STRING([--with-launchd-agent-dir=[dirname]],[directory to put the launchd agent (default: /Library/LaunchAgents)]))
    147149AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)]))
    148150AC_ARG_WITH(dbus_daemondir, AS_HELP_STRING([--with-dbus-daemondir=[dirname]],[Directory for installing the DBUS daemon]))
    149151
     
    922924
    923925AM_CONDITIONAL(DBUS_BUS_ENABLE_KQUEUE, test x$have_kqueue = xyes)
    924926
     927# launchd checks
     928if test x$enable_launchd = xno ; then
     929    have_launchd=no
     930else
     931    have_launchd=yes
     932    AC_CHECK_HEADER([launch.h], , have_launchd=no)
     933    AC_PATH_PROG([LAUNCHCTL], [launchctl])
     934    if test "x$LAUNCHCTL" = "x"; then
     935        have_launchd=no
     936    fi
     937
     938    if test x$enable_launchd = xyes && test x$have_launchd = xno ; then
     939        AC_MSG_ERROR([launchd support explicitly enabled but not available])
     940    fi
     941fi
     942
     943dnl check if launchd is enabled
     944if test x$have_launchd = xyes; then
     945    AC_DEFINE(DBUS_ENABLE_LAUNCHD,1,[Use launchd autolaunch])
     946fi
     947
     948AM_CONDITIONAL(DBUS_ENABLE_LAUNCHD, test x$have_launchd = xyes)
     949
     950#### Directory to place launchd agent file
     951if test "x$with_launchd_agent_dir" = "x"; then
     952   LAUNCHD_AGENT_DIR="/Library/LaunchAgents"
     953else
     954   LAUNCHD_AGENT_DIR="$with_launchd_agent_dir"
     955fi
     956
     957AC_SUBST(LAUNCHD_AGENT_DIR)
     958
    925959dnl console owner file
    926960if test x$enable_console_owner_file = xno ; then
    927961    have_console_owner_file=no;
     
    14101444AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus])
    14111445
    14121446# set up the session bus address
    1413 DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
     1447if test x$have_launchd = xyes; then
     1448   DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
     1449else
     1450   DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
     1451fi
    14141452AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS)
    14151453
    14161454#### Set up the pid file
     
    15511589   DBUS_SESSION_SOCKET_DIR=$DEFAULT_SOCKET_DIR
    15521590fi
    15531591AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets])
    1554 AC_SUBST(DBUS_SESSION_SOCKET_DIR)
    15551592
    15561593if test x$dbus_win = xyes; then
    15571594        DBUS_SESSION_BUS_DEFAULT_ADDRESS="nonce-tcp:"
     
    15791616bus/system.conf
    15801617bus/session.conf
    15811618bus/messagebus
     1619bus/org.freedesktop.dbus-session.plist
    15821620bus/messagebus-config
    15831621bus/rc.messagebus
    15841622bus/dbus-daemon.1
     
    16501688        Building Doxygen docs:    ${enable_doxygen_docs}
    16511689        Building XML docs:        ${enable_xml_docs}
    16521690        Building cache support:   ${enable_userdb_cache}
     1691        Building launchd support: ${have_launchd}
    16531692        Gettext libs (empty OK):  ${INTLLIBS}
    16541693        Using XML parser:         ${with_xml}
    16551694        Init scripts style:       ${with_init_scripts}
     
    16631702        Console owner file path:  ${DBUS_CONSOLE_OWNER_FILE}
    16641703        System bus user:          ${DBUS_USER}
    16651704        Session bus services dir: ${EXPANDED_DATADIR}/dbus-1/services
    1666         'make check' socket dir:  ${TEST_SOCKET_DIR}
    1667 "
     1705        'make check' socket dir:  ${TEST_SOCKET_DIR}"
     1706
     1707if test x$have_launchd = xyes; then
     1708        echo "        launchd agent dir:        ${LAUNCHD_AGENT_DIR}"
     1709fi
     1710echo
    16681711
    16691712if test x$enable_tests = xyes; then
    16701713        echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure."
  • dbus/Makefile.am

    diff -urN dbus-1.4.0-old/dbus/Makefile.am dbus-1.4.0-new/dbus/Makefile.am
    old new  
    159159        dbus-server.c                           \
    160160        dbus-server-debug-pipe.c                \
    161161        dbus-server-debug-pipe.h                \
     162        dbus-server-launchd.c                   \
     163        dbus-server-launchd.h                   \
    162164        dbus-server-protected.h                 \
    163165        dbus-server-socket.c                    \
    164166        dbus-server-socket.h                    \
  • dbus/dbus-server-unix.c

    diff -urN dbus-1.4.0-old/dbus/dbus-server-unix.c dbus-1.4.0-new/dbus/dbus-server-unix.c
    old new  
    2525#include "dbus-internals.h"
    2626#include "dbus-server-unix.h"
    2727#include "dbus-server-socket.h"
     28#include "dbus-server-launchd.h"
    2829#include "dbus-transport-unix.h"
    2930#include "dbus-connection-internal.h"
    3031#include "dbus-sysdeps-unix.h"
     
    179180
    180181      return DBUS_SERVER_LISTEN_OK;
    181182    }
     183
     184  else if (strcmp (method, "launchd") == 0)
     185    {
     186      const char *launchd_env_var = dbus_address_entry_get_value (entry, "env");
     187      if (launchd_env_var == NULL)
     188        {
     189          _dbus_set_bad_address (error, "launchd", "env", NULL);
     190          return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
     191        }
     192      *server_p = _dbus_server_new_for_launchd (launchd_env_var, error);
     193
     194      if (*server_p != NULL)
     195        {
     196          _DBUS_ASSERT_ERROR_IS_CLEAR(error);
     197          return DBUS_SERVER_LISTEN_OK;
     198        }
     199      else
     200        {
     201          _DBUS_ASSERT_ERROR_IS_SET(error);
     202          return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
     203        }
     204    }
     205
    182206  else
    183207    {
    184208      /* If we don't handle the method, we return NULL with the
  • dbus/dbus-sysdeps.h

    diff -urN dbus-1.4.0-old/dbus/dbus-sysdeps.h dbus-1.4.0-new/dbus/dbus-sysdeps.h
    old new  
    187187dbus_bool_t _dbus_send_credentials_socket (int              server_fd,
    188188                                           DBusError       *error);
    189189
     190dbus_bool_t _dbus_lookup_launchd_socket (DBusString *socket_path,
     191                                         const char *launchd_env_var,
     192                                         DBusError  *error);
     193
    190194dbus_bool_t _dbus_credentials_add_from_user            (DBusCredentials  *credentials,
    191195                                                        const DBusString *username);
    192196dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials  *credentials);
  • dbus/dbus-transport-unix.c

    diff -urN dbus-1.4.0-old/dbus/dbus-transport-unix.c dbus-1.4.0-new/dbus/dbus-transport-unix.c
    old new  
    170170          return DBUS_TRANSPORT_OPEN_OK;
    171171        }     
    172172    }
     173  else if (strcmp (method, "launchd") == 0)
     174    {
     175      DBusError tmp_error = DBUS_ERROR_INIT;
     176      const char *launchd_env_var = dbus_address_entry_get_value (entry, "env");
     177      const char *launchd_socket;
     178      DBusString socket_path;
     179      dbus_bool_t valid_socket;
     180
     181      if (!_dbus_string_init (&socket_path))
     182        {
     183          _DBUS_SET_OOM (error);
     184          return FALSE;
     185        }
     186
     187      if (launchd_env_var == NULL)
     188        {
     189          _dbus_set_bad_address (error, "launchd", "env", NULL);
     190          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
     191        }
     192
     193      valid_socket = _dbus_lookup_launchd_socket (&socket_path, launchd_env_var, error);
     194
     195      if (dbus_error_is_set(error))
     196        {
     197          _dbus_string_free(&socket_path);
     198          return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
     199        }
     200
     201      if (!valid_socket)
     202        {
     203          dbus_set_error(&tmp_error, DBUS_ERROR_BAD_ADDRESS,
     204                         "launchd's env var %s does not exist", launchd_env_var);
     205          dbus_error_free(error);
     206          dbus_move_error(&tmp_error, error);
     207          return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
     208        }
     209
     210      launchd_socket = _dbus_string_get_const_data(&socket_path);
     211      *transport_p = _dbus_transport_new_for_domain_socket (launchd_socket, FALSE, error);
     212
     213      if (*transport_p == NULL)
     214        {
     215          _DBUS_ASSERT_ERROR_IS_SET (error);
     216          return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
     217        }
     218      else
     219        {
     220          _DBUS_ASSERT_ERROR_IS_CLEAR (error);
     221          return DBUS_TRANSPORT_OPEN_OK;
     222        }
     223    }
    173224  else
    174225    {
    175226      _DBUS_ASSERT_ERROR_IS_CLEAR (error);