2003-02-15 18:22:40 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* activation.c Activation of services
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 CodeFactory AB
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "activation.h"
|
|
|
|
|
#include "desktop-file.h"
|
2003-03-16 22:25:18 +00:00
|
|
|
#include "services.h"
|
2003-02-15 18:22:40 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
#include <dbus/dbus-internals.h>
|
|
|
|
|
#include <dbus/dbus-hash.h>
|
2003-03-16 22:25:18 +00:00
|
|
|
#include <dbus/dbus-list.h>
|
2003-02-15 18:22:40 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#define DBUS_SERVICE_SECTION "D-BUS Service"
|
|
|
|
|
#define DBUS_SERVICE_NAME "Name"
|
|
|
|
|
#define DBUS_SERVICE_EXEC "Exec"
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
struct BusActivation
|
|
|
|
|
{
|
|
|
|
|
int refcount;
|
|
|
|
|
DBusHashTable *entries;
|
2003-03-16 22:25:18 +00:00
|
|
|
DBusHashTable *pending_activations;
|
2003-03-13 03:52:58 +00:00
|
|
|
char *server_address;
|
2003-03-16 22:25:18 +00:00
|
|
|
BusContext *context;
|
2003-03-13 03:52:58 +00:00
|
|
|
};
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
char *exec;
|
|
|
|
|
} BusActivationEntry;
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
typedef struct BusPendingActivationEntry BusPendingActivationEntry;
|
|
|
|
|
|
|
|
|
|
struct BusPendingActivationEntry
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *activation_message;
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
char *service_name;
|
|
|
|
|
DBusList *entries;
|
|
|
|
|
} BusPendingActivation;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_pending_activation_entry_free (BusPendingActivationEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
if (entry->activation_message)
|
|
|
|
|
dbus_message_unref (entry->activation_message);
|
|
|
|
|
|
|
|
|
|
if (entry->connection)
|
|
|
|
|
dbus_connection_unref (entry->connection);
|
|
|
|
|
|
|
|
|
|
dbus_free (entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_pending_activation_free (BusPendingActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
if (!activation)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dbus_free (activation->service_name);
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&activation->entries);
|
|
|
|
|
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivationEntry *entry = link->data;
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_entry_free (entry);
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_next_link (&activation->entries, link);
|
|
|
|
|
}
|
|
|
|
|
_dbus_list_clear (&activation->entries);
|
|
|
|
|
|
|
|
|
|
dbus_free (activation);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
static void
|
|
|
|
|
bus_activation_entry_free (BusActivationEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
if (!entry)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dbus_free (entry->name);
|
|
|
|
|
dbus_free (entry->exec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
2003-03-13 03:52:58 +00:00
|
|
|
add_desktop_file_entry (BusActivation *activation,
|
|
|
|
|
BusDesktopFile *desktop_file,
|
2003-03-13 00:56:43 +00:00
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
|
|
|
|
char *name, *exec;
|
|
|
|
|
BusActivationEntry *entry;
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
name = NULL;
|
|
|
|
|
exec = NULL;
|
|
|
|
|
entry = NULL;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
if (!bus_desktop_file_get_string (desktop_file,
|
|
|
|
|
DBUS_SERVICE_SECTION,
|
|
|
|
|
DBUS_SERVICE_NAME,
|
|
|
|
|
&name))
|
|
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"No \""DBUS_SERVICE_NAME"\" key in .service file\n");
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_desktop_file_get_string (desktop_file,
|
|
|
|
|
DBUS_SERVICE_SECTION,
|
|
|
|
|
DBUS_SERVICE_EXEC,
|
|
|
|
|
&exec))
|
|
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"No \""DBUS_SERVICE_EXEC"\" key in .service file\n");
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* FIXME we need a better-defined algorithm for which service file to
|
|
|
|
|
* pick than "whichever one is first in the directory listing"
|
|
|
|
|
*/
|
2003-03-13 03:52:58 +00:00
|
|
|
if (_dbus_hash_table_lookup_string (activation->entries, name))
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Service %s already exists in activation entry list\n", name);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry = dbus_new0 (BusActivationEntry, 1);
|
|
|
|
|
if (entry == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry->name = name;
|
|
|
|
|
entry->exec = exec;
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
if (!_dbus_hash_table_insert_string (activation->entries, entry->name, entry))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("Added \"%s\" to list of services\n", entry->name);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
dbus_free (name);
|
|
|
|
|
dbus_free (exec);
|
|
|
|
|
dbus_free (entry);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* warning: this doesn't fully "undo" itself on failure, i.e. doesn't strip
|
|
|
|
|
* hash entries it already added.
|
|
|
|
|
*/
|
|
|
|
|
static dbus_bool_t
|
2003-03-13 03:52:58 +00:00
|
|
|
load_directory (BusActivation *activation,
|
|
|
|
|
const char *directory,
|
|
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
|
|
|
|
DBusDirIter *iter;
|
|
|
|
|
DBusString dir, filename;
|
2003-03-13 00:56:43 +00:00
|
|
|
DBusString full_path;
|
|
|
|
|
BusDesktopFile *desktop_file;
|
|
|
|
|
DBusError tmp_error;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
_dbus_string_init_const (&dir, directory);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
iter = NULL;
|
|
|
|
|
desktop_file = NULL;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&filename))
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&full_path))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* from this point it's safe to "goto failed" */
|
|
|
|
|
|
|
|
|
|
iter = _dbus_directory_open (&dir, error);
|
|
|
|
|
if (iter == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to open directory %s: %s\n",
|
|
|
|
|
directory, error ? error->message : "unknown");
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
/* Now read the files */
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_error_init (&tmp_error);
|
|
|
|
|
while (_dbus_directory_get_next_file (iter, &filename, &tmp_error))
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
_dbus_assert (!dbus_error_is_set (&tmp_error));
|
|
|
|
|
|
|
|
|
|
_dbus_string_set_length (&full_path, 0);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&full_path, directory) ||
|
|
|
|
|
!_dbus_concat_dir_and_file (&full_path, &filename))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_ends_with_c_str (&filename, ".service"))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Skipping non-.service file %s\n",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&filename));
|
2003-03-13 00:56:43 +00:00
|
|
|
continue;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
desktop_file = bus_desktop_file_load (&full_path, &tmp_error);
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (desktop_file == NULL)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_verbose ("Could not load %s: %s\n",
|
|
|
|
|
_dbus_string_get_const_data (&full_path),
|
2003-03-13 00:56:43 +00:00
|
|
|
tmp_error.message);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&tmp_error);
|
2003-02-15 18:22:40 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
if (!add_desktop_file_entry (activation, desktop_file, &tmp_error))
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
bus_desktop_file_free (desktop_file);
|
|
|
|
|
desktop_file = NULL;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
_dbus_verbose ("Could not add %s to activation entry list: %s\n",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&full_path), tmp_error.message);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
continue;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bus_desktop_file_free (desktop_file);
|
|
|
|
|
desktop_file = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (dbus_error_is_set (&tmp_error))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
|
|
|
|
|
if (iter != NULL)
|
|
|
|
|
_dbus_directory_close (iter);
|
|
|
|
|
if (desktop_file)
|
|
|
|
|
bus_desktop_file_free (desktop_file);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
BusActivation*
|
2003-03-31 08:19:50 +00:00
|
|
|
bus_activation_new (BusContext *context,
|
|
|
|
|
const DBusString *address,
|
2003-04-02 00:29:33 +00:00
|
|
|
DBusList **directories,
|
2003-03-31 08:19:50 +00:00
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
BusActivation *activation;
|
2003-04-02 00:29:33 +00:00
|
|
|
DBusList *link;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
activation = dbus_new0 (BusActivation, 1);
|
|
|
|
|
if (activation == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
activation->refcount = 1;
|
2003-03-16 22:25:18 +00:00
|
|
|
activation->context = context;
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-31 08:19:50 +00:00
|
|
|
if (!_dbus_string_copy_data (address, &activation->server_address))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-02-17 09:59:23 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
activation->entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
2003-03-13 00:56:43 +00:00
|
|
|
(DBusFreeFunction)bus_activation_entry_free);
|
2003-03-13 03:52:58 +00:00
|
|
|
if (activation->entries == NULL)
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
activation->pending_activations = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
|
|
|
|
(DBusFreeFunction)bus_pending_activation_free);
|
|
|
|
|
|
|
|
|
|
if (activation->pending_activations == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
/* Load service files */
|
2003-04-02 00:29:33 +00:00
|
|
|
link = _dbus_list_get_first_link (directories);
|
|
|
|
|
while (link != NULL)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2003-04-02 00:29:33 +00:00
|
|
|
if (!load_directory (activation, link->data, error))
|
2003-03-13 00:56:43 +00:00
|
|
|
goto failed;
|
2003-04-02 00:29:33 +00:00
|
|
|
link = _dbus_list_get_next_link (directories, link);
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
return activation;
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
failed:
|
2003-03-13 03:52:58 +00:00
|
|
|
bus_activation_unref (activation);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_activation_ref (BusActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (activation->refcount > 0);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
activation->refcount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_activation_unref (BusActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (activation->refcount > 0);
|
|
|
|
|
|
|
|
|
|
activation->refcount -= 1;
|
|
|
|
|
|
|
|
|
|
if (activation->refcount == 0)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (activation->server_address);
|
|
|
|
|
if (activation->entries)
|
|
|
|
|
_dbus_hash_table_unref (activation->entries);
|
2003-03-16 22:25:18 +00:00
|
|
|
if (activation->pending_activations)
|
|
|
|
|
_dbus_hash_table_unref (activation->pending_activations);
|
2003-03-13 03:52:58 +00:00
|
|
|
dbus_free (activation);
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-02-17 09:59:23 +00:00
|
|
|
static void
|
|
|
|
|
child_setup (void *data)
|
|
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
BusActivation *activation = data;
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* If no memory, we simply have the child exit, so it won't try
|
|
|
|
|
* to connect to the wrong thing.
|
|
|
|
|
*/
|
2003-03-13 03:52:58 +00:00
|
|
|
if (!_dbus_setenv ("DBUS_ADDRESS", activation->server_address))
|
2003-03-13 00:56:43 +00:00
|
|
|
_dbus_exit (1);
|
2003-02-17 09:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
dbus_bool_t
|
2003-03-16 22:25:18 +00:00
|
|
|
bus_activation_service_created (BusActivation *activation,
|
|
|
|
|
const char *service_name,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation;
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusList *link;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
|
|
|
|
/* Check if it's a pending activation */
|
|
|
|
|
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name);
|
|
|
|
|
|
|
|
|
|
if (!pending_activation)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
link = _dbus_list_get_first_link (&pending_activation->entries);
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivationEntry *entry = link->data;
|
|
|
|
|
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
|
|
|
|
|
|
|
|
|
|
if (dbus_connection_get_is_connected (entry->connection))
|
|
|
|
|
{
|
|
|
|
|
message = dbus_message_new_reply (entry->activation_message);
|
|
|
|
|
if (!message)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ACTIVATED,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (entry->connection, message, NULL))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_entry_free (entry);
|
|
|
|
|
|
|
|
|
|
_dbus_list_remove_link (&pending_activation->entries, link);
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations, service_name);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations, service_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_activate_service (BusActivation *activation,
|
|
|
|
|
DBusConnection *connection,
|
|
|
|
|
DBusMessage *activation_message,
|
|
|
|
|
const char *service_name,
|
|
|
|
|
DBusError *error)
|
2003-02-16 10:00:37 +00:00
|
|
|
{
|
|
|
|
|
BusActivationEntry *entry;
|
2003-03-16 22:25:18 +00:00
|
|
|
BusPendingActivation *pending_activation;
|
|
|
|
|
BusPendingActivationEntry *pending_activation_entry;
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusString service_str;
|
2003-02-16 10:00:37 +00:00
|
|
|
char *argv[2];
|
2003-03-16 22:25:18 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
entry = _dbus_hash_table_lookup_string (activation->entries, service_name);
|
2003-02-16 10:00:37 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
/* Check if the service is active */
|
|
|
|
|
_dbus_string_init_const (&service_str, service_name);
|
|
|
|
|
if (bus_registry_lookup (bus_context_get_registry (activation->context), &service_str) != NULL)
|
|
|
|
|
{
|
|
|
|
|
message = dbus_message_new_reply (activation_message);
|
|
|
|
|
|
|
|
|
|
if (!message)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = dbus_connection_send (connection, message, NULL);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
if (!retval)
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pending_activation_entry = dbus_new0 (BusPendingActivationEntry, 1);
|
|
|
|
|
if (!pending_activation_entry)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pending_activation_entry->activation_message = activation_message;
|
|
|
|
|
dbus_message_ref (activation_message);
|
|
|
|
|
pending_activation_entry->connection = connection;
|
|
|
|
|
dbus_connection_ref (connection);
|
|
|
|
|
|
|
|
|
|
/* Check if the service is being activated */
|
|
|
|
|
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name);
|
|
|
|
|
if (pending_activation)
|
|
|
|
|
{
|
2003-03-17 02:26:41 +00:00
|
|
|
if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry))
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pending_activation = dbus_new0 (BusPendingActivation, 1);
|
|
|
|
|
if (!pending_activation)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
pending_activation->service_name = _dbus_strdup (service_name);
|
|
|
|
|
if (!pending_activation->service_name)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_free (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 02:26:41 +00:00
|
|
|
if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry))
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_free (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (activation->pending_activations,
|
|
|
|
|
pending_activation->service_name, pending_activation))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_free (pending_activation);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* FIXME we need to support a full command line, not just a single
|
|
|
|
|
* argv[0]
|
|
|
|
|
*/
|
|
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
/* Now try to spawn the process */
|
|
|
|
|
argv[0] = entry->exec;
|
|
|
|
|
argv[1] = NULL;
|
|
|
|
|
|
2003-02-17 09:59:23 +00:00
|
|
|
if (!_dbus_spawn_async (argv,
|
2003-03-13 03:52:58 +00:00
|
|
|
child_setup, activation,
|
2003-02-17 09:59:23 +00:00
|
|
|
error))
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations,
|
|
|
|
|
pending_activation->service_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|