diff options
author | Anders Carlsson <andersca@codefactory.se> | 2003-02-16 10:00:37 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@codefactory.se> | 2003-02-16 10:00:37 +0000 |
commit | f116b1282f8482dff6dc797f64270d95f79b53a3 (patch) | |
tree | d56ba5a2f6cb8797b54b079d5b754abac5cd14bc /bus | |
parent | ac5183eafc6bd77bec094c3ba103701a4540f08d (diff) |
2003-02-16 Anders Carlsson <andersca@codefactory.se>
* bus/activation.c: (load_directory), (bus_activation_init),
(bus_activation_activate_service):
* bus/activation.h:
* bus/driver.c:
(bus_driver_handle_activate_service), (bus_driver_handle_message):
More work on the activation handling.
* dbus/dbus-errors.h:
Add some error messages
* dbus/dbus-message.c: (dbus_message_new_error_reply):
* dbus/dbus-message.h:
New function that creates an error message.
* dbus/dbus-protocol.h:
Add ACTIVATE_SERVER message.
* dbus/dbus-server-unix.c: (unix_handle_watch),
(_dbus_server_new_for_domain_socket):
Call _dbus_fd_set_close_on_exec.
* dbus/dbus-sysdeps.c: (make_pipe), (do_exec),
(_dbus_spawn_async), (_dbus_disable_sigpipe),
(_dbus_fd_set_close_on_exec):
* dbus/dbus-sysdeps.h:
Add _dbus_fd_set_close_on exec function. Also add function that checks
that all open fds are set to close-on-exec and warns otherwise.
* dbus/dbus-transport-unix.c:
(_dbus_transport_new_for_domain_socket):
Call _dbus_fd_set_close_on_exec.
Diffstat (limited to 'bus')
-rw-r--r-- | bus/activation.c | 63 | ||||
-rw-r--r-- | bus/activation.h | 7 | ||||
-rw-r--r-- | bus/driver.c | 41 |
3 files changed, 77 insertions, 34 deletions
diff --git a/bus/activation.c b/bus/activation.c index 7f7dd438..b4acd0f3 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -41,6 +41,12 @@ typedef struct char *exec; } BusActivationEntry; +static DBusHashTable *pending_activations = NULL; +typedef struct +{ + char *service; +} BusPendingActivation; + static void bus_activation_entry_free (BusActivationEntry *entry) { @@ -164,36 +170,6 @@ load_directory (const char *directory) bus_desktop_file_free (desktop_file); _dbus_string_free (&full_path); } - -#if 0 - while ((directory_entry = readdir (directory_handle))) - { - DBusString path, filename; - BusDesktopFile *desktop_file; - DBusError error; - const char *filename_c; - - - _dbus_string_init_const (&filename, directory_entry->d_name); - - - _dbus_string_get_const_data (&path, &filename_c); - - if (!desktop_file) - { - _dbus_verbose ("Could not load %s: %s\n", filename_c, - error.message); - dbus_error_free (&error); - _dbus_string_free (&path); - continue; - } - - if (!add_desktop_file_entry (desktop_file)) - { - _dbus_verbose ("Could not add %s to activation entry list.\n", filename_c); - } - } -#endif } @@ -214,3 +190,30 @@ bus_activation_init (const char **directories) i++; } } + +dbus_bool_t +bus_activation_activate_service (const char *service_name, + DBusError *error) +{ + BusActivationEntry *entry; + char *argv[2]; + + entry = _dbus_hash_table_lookup_string (activation_entries, service_name); + + if (!entry) + { + dbus_set_error (error, DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND, + "The service %s was not found in the activation entry list", + service_name); + return FALSE; + } + + /* Now try to spawn the process */ + argv[0] = entry->exec; + argv[1] = NULL; + + if (!_dbus_spawn_async (argv, error)) + return FALSE; + + return TRUE; +} diff --git a/bus/activation.h b/bus/activation.h index 901c4eee..15260f01 100644 --- a/bus/activation.h +++ b/bus/activation.h @@ -24,6 +24,11 @@ #ifndef BUS_ACTIVATION_H #define BUS_ACTIVATION_H -void bus_activation_init (const char **paths); +#include <dbus/dbus.h> + +void bus_activation_init (const char **paths); +dbus_bool_t bus_activation_activate_service (const char *service_name, + DBusError *error); + #endif /* BUS_ACTIVATION_H */ diff --git a/bus/driver.c b/bus/driver.c index 9983f573..80478e45 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -21,6 +21,7 @@ * */ +#include "activation.h" #include "connection.h" #include "driver.h" #include "dispatch.h" @@ -169,7 +170,7 @@ bus_driver_handle_hello (DBusConnection *connection, { DBusString unique_name; BusService *service; - + BUS_HANDLE_OOM (_dbus_string_init (&unique_name, _DBUS_INT_MAX)); BUS_HANDLE_OOM (create_unique_client_name (&unique_name)); @@ -208,7 +209,7 @@ bus_driver_send_welcome_message (DBusConnection *connection, NULL)); BUS_HANDLE_OOM (dbus_connection_send_message (connection, welcome, NULL, NULL)); - + dbus_message_unref (welcome); } @@ -363,6 +364,39 @@ bus_driver_handle_service_exists (DBusConnection *connection, dbus_free (name); } +static void +bus_driver_handle_activate_service (DBusConnection *connection, + DBusMessage *message) +{ + DBusResultCode result; + dbus_uint32_t flags; + char *name; + DBusError error; + + BUS_HANDLE_OOM ((result = dbus_message_get_args (message, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + 0)) != DBUS_RESULT_NO_MEMORY); + if (result != DBUS_RESULT_SUCCESS) + { + dbus_free (name); + dbus_connection_disconnect (connection); + return; + } + + if (!bus_activation_activate_service (name, &error)) + { + DBusMessage *error_reply; + + BUS_HANDLE_OOM (error_reply = dbus_message_new_error_reply (message, + error.name, error.message)); + dbus_error_free (&error); + + BUS_HANDLE_OOM (dbus_connection_send_message (connection, error_reply, NULL, NULL)); + dbus_message_unref (error_reply); + } +} + void bus_driver_handle_message (DBusConnection *connection, DBusMessage *message) @@ -391,7 +425,8 @@ bus_driver_handle_message (DBusConnection *connection, bus_driver_handle_acquire_service (connection, message); else if (strcmp (name, DBUS_MESSAGE_SERVICE_EXISTS) == 0) bus_driver_handle_service_exists (connection, message); - + else if (strcmp (name, DBUS_MESSAGE_ACTIVATE_SERVICE) == 0) + bus_driver_handle_activate_service (connection, message); } void |