From 8f0375f289440640e4f1a4ef7fe8c2c92a24d05d Mon Sep 17 00:00:00 2001 From: Alexander Kanavin Date: Mon, 24 Feb 2014 17:09:18 +0200 Subject: [PATCH] transport: add new unixexec-child transport on Unix This transport should be used by the child processes started by the "unixexec:" transport. The process' standard input stream is used for communication by the transport (the "unixexec" transport mandates that the standard input and output streams of the child process are connected to the same anonymous Unix domain socket). --- dbus/dbus-test.c | 3 +- dbus/dbus-test.h | 3 +- dbus/dbus-transport-unix.c | 94 +++++++++++++++++++++++++++++++++++++++++++++- doc/dbus-specification.xml | 31 ++++++++++++++- 4 files changed, 127 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c index 5990d6e..a38629e 100644 --- a/dbus/dbus-test.c +++ b/dbus/dbus-test.c @@ -156,7 +156,8 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *speci #ifdef DBUS_UNIX run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir); - run_test ("transport-unix", specific_test, _dbus_transport_unix_test); + run_test ("transport-unixexec", specific_test, _dbus_transport_unixexec_test); + run_test ("transport-unixexec-child", specific_test, _dbus_transport_unixexec_child_test); #endif run_test ("keyring", specific_test, _dbus_keyring_test); diff --git a/dbus/dbus-test.h b/dbus/dbus-test.h index f254388..1dddccb 100644 --- a/dbus/dbus-test.h +++ b/dbus/dbus-test.h @@ -48,7 +48,8 @@ dbus_bool_t _dbus_data_slot_test (void); dbus_bool_t _dbus_sysdeps_test (void); dbus_bool_t _dbus_spawn_test (const char *test_data_dir); dbus_bool_t _dbus_userdb_test (const char *test_data_dir); -dbus_bool_t _dbus_transport_unix_test (void); +dbus_bool_t _dbus_transport_unixexec_test (void); +dbus_bool_t _dbus_transport_unixexec_child_test (void); dbus_bool_t _dbus_memory_test (void); dbus_bool_t _dbus_object_tree_test (void); dbus_bool_t _dbus_credentials_test (const char *test_data_dir); diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index 9a9fea5..6277424 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -24,6 +24,7 @@ #include #include +#include #include "dbus-internals.h" #include "dbus-connection-internal.h" @@ -214,6 +215,57 @@ _dbus_transport_new_for_exec (const char *path, } /** + * Creates a new transport connected to UNIX standard input stream. This + * corresponds to the other side of a transport created with + * _dbus_transport_new_for_exec(). + * + * @param error address where an error can be returned. + * @returns a new transport, or #NULL on failure. + */ +static DBusTransport* +_dbus_transport_new_for_exec_child (DBusError *error) +{ + int fd; + DBusTransport *transport; + DBusString address; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&address)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + /* Open a connection on standard input; according to the spec for unixexec + * transport, the standard input and output are connected to the same + * UNIX domain socket */ + fd = STDIN_FILENO; + + if (!_dbus_string_append (&address, "unixexec-child:")) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + transport = _dbus_transport_new_for_socket (fd, NULL, &address); + if (transport == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed; + } + + _dbus_string_free (&address); + + return transport; + + failed: + _dbus_string_free (&address); + return NULL; +} + + +/** * Opens platform specific transport types. * * @param entry the address entry to try opening @@ -350,6 +402,21 @@ _dbus_transport_open_platform_specific (DBusAddressEntry *entry, return DBUS_TRANSPORT_OPEN_OK; } } + else if (strcmp (method, "unixexec-child") == 0) + { + *transport_p = _dbus_transport_new_for_exec_child (error); + + if (*transport_p == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT; + } + else + { + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + return DBUS_TRANSPORT_OPEN_OK; + } + } #ifdef DBUS_ENABLE_LAUNCHD else if (strcmp (method, "launchd") == 0) { @@ -415,7 +482,7 @@ _dbus_transport_open_platform_specific (DBusAddressEntry *entry, #ifdef DBUS_ENABLE_EMBEDDED_TESTS dbus_bool_t -_dbus_transport_unix_test (void) +_dbus_transport_unixexec_test (void) { DBusConnection *c; DBusError error; @@ -439,4 +506,29 @@ _dbus_transport_unix_test (void) return ret; } +dbus_bool_t +_dbus_transport_unixexec_child_test (void) +{ + DBusConnection *c; + DBusError error; + dbus_bool_t ret; + const char *address; + + dbus_error_init (&error); + + c = dbus_connection_open ("unixexec-child:", &error); + _dbus_assert (c != NULL); + _dbus_assert (!dbus_error_is_set (&error)); + + address = _dbus_connection_get_address (c); + _dbus_assert (address != NULL); + + ret = strcmp (address, "unixexec-child:") == 0; + + dbus_connection_unref (c); + + return ret; +} + + #endif diff --git a/doc/dbus-specification.xml b/doc/dbus-specification.xml index bed4899..d962ce7 100644 --- a/doc/dbus-specification.xml +++ b/doc/dbus-specification.xml @@ -2998,7 +2998,8 @@ [FIXME we need to specify in detail each transport and its possible arguments] Current transports include: unix domain sockets (including - abstract namespace on linux), launchd, systemd, TCP/IP, an executed subprocess and a debug/testing transport + abstract namespace on linux), launchd, systemd, TCP/IP, an executed subprocess + (both parent and child sides) and a debug/testing transport using in-process pipes. Future possible transports include one that tunnels over X11 protocol. @@ -3376,6 +3377,34 @@ + + Executed Subprocesses on Unix (the child process side) + + This transport should be used by the child processes started by the + "unixexec:" transport. The process' standard input stream is used for + communication by the transport (the "unixexec" transport mandates that + the standard input and output streams of the child process are + connected to the same anonymous Unix domain socket). + + + The forked process will inherit the standard error output and + process group from the parent process. + + + Executed subprocesses are not available on Windows. + + + unixexec-child addresses are connectable, but are not + listenable. + + + Server Address Format + + Executed subprocess addresses are identified by the "unixexec-child:" + prefix. + + + Meta Transports -- 1.8.4.5