2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2003-02-15 18:22:40 +00:00
|
|
|
/* activation.c Activation of services
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 CodeFactory AB
|
2003-04-02 20:14:52 +00:00
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
2004-03-12 14:07:16 +00:00
|
|
|
* Copyright (C) 2004 Imendio HB
|
2003-02-15 18:22:40 +00:00
|
|
|
*
|
2004-08-10 03:07:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2003-02-15 18:22:40 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-02-15 18:22:40 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "activation.h"
|
2007-07-24 12:14:51 +00:00
|
|
|
#include "activation-exit-codes.h"
|
2003-02-15 18:22:40 +00:00
|
|
|
#include "desktop-file.h"
|
2003-03-16 22:25:18 +00:00
|
|
|
#include "services.h"
|
2004-03-12 14:07:16 +00:00
|
|
|
#include "test.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>
|
2005-07-14 20:44:15 +00:00
|
|
|
#include <dbus/dbus-shell.h>
|
2003-04-05 10:04:04 +00:00
|
|
|
#include <dbus/dbus-spawn.h>
|
2003-04-05 19:03:40 +00:00
|
|
|
#include <dbus/dbus-timeout.h>
|
2006-08-10 20:09:43 +00:00
|
|
|
#include <dbus/dbus-sysdeps.h>
|
2007-06-15 19:28:36 +00:00
|
|
|
#ifdef HAVE_ERRNO_H
|
2003-02-15 18:22:40 +00:00
|
|
|
#include <errno.h>
|
2007-06-15 19:28:36 +00:00
|
|
|
#endif
|
2003-02-15 18:22:40 +00:00
|
|
|
|
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;
|
2004-07-29 08:00:45 +00:00
|
|
|
char *server_address;
|
2003-03-16 22:25:18 +00:00
|
|
|
BusContext *context;
|
2003-04-25 23:50:34 +00:00
|
|
|
int n_pending_activations; /**< This is in fact the number of BusPendingActivationEntry,
|
|
|
|
|
* i.e. number of pending activation requests, not pending
|
|
|
|
|
* activations per se
|
2005-07-14 20:44:15 +00:00
|
|
|
*/
|
2004-03-12 14:07:16 +00:00
|
|
|
DBusHashTable *directories;
|
2008-07-10 14:35:38 -04:00
|
|
|
DBusHashTable *environment;
|
2003-03-13 03:52:58 +00:00
|
|
|
};
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2004-03-12 14:07:16 +00:00
|
|
|
int refcount;
|
|
|
|
|
char *dir_c;
|
|
|
|
|
DBusHashTable *entries;
|
|
|
|
|
} BusServiceDirectory;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
int refcount;
|
2003-02-15 18:22:40 +00:00
|
|
|
char *name;
|
|
|
|
|
char *exec;
|
2007-07-24 12:17:39 +00:00
|
|
|
char *user;
|
2004-03-12 14:07:16 +00:00
|
|
|
unsigned long mtime;
|
|
|
|
|
BusServiceDirectory *s_dir;
|
|
|
|
|
char *filename;
|
2003-02-15 18:22:40 +00:00
|
|
|
} BusActivationEntry;
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
typedef struct BusPendingActivationEntry BusPendingActivationEntry;
|
|
|
|
|
|
|
|
|
|
struct BusPendingActivationEntry
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *activation_message;
|
|
|
|
|
DBusConnection *connection;
|
2004-03-16 18:00:35 +00:00
|
|
|
|
|
|
|
|
dbus_bool_t auto_activation;
|
2003-03-16 22:25:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2003-04-11 00:03:06 +00:00
|
|
|
int refcount;
|
2003-04-05 19:03:40 +00:00
|
|
|
BusActivation *activation;
|
2003-03-16 22:25:18 +00:00
|
|
|
char *service_name;
|
2004-03-12 14:15:14 +00:00
|
|
|
char *exec;
|
2003-03-16 22:25:18 +00:00
|
|
|
DBusList *entries;
|
2003-04-25 23:50:34 +00:00
|
|
|
int n_entries;
|
2003-04-05 19:03:40 +00:00
|
|
|
DBusBabysitter *babysitter;
|
|
|
|
|
DBusTimeout *timeout;
|
|
|
|
|
unsigned int timeout_added : 1;
|
2003-03-16 22:25:18 +00:00
|
|
|
} BusPendingActivation;
|
|
|
|
|
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
#if 0
|
2004-03-12 14:07:16 +00:00
|
|
|
static BusServiceDirectory *
|
|
|
|
|
bus_service_directory_ref (BusServiceDirectory *dir)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (dir->refcount);
|
|
|
|
|
|
|
|
|
|
dir->refcount++;
|
|
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
#endif
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_service_directory_unref (BusServiceDirectory *dir)
|
|
|
|
|
{
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (dir->refcount > 0);
|
|
|
|
|
dir->refcount--;
|
|
|
|
|
|
|
|
|
|
if (dir->refcount > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (dir->entries)
|
|
|
|
|
_dbus_hash_table_unref (dir->entries);
|
|
|
|
|
|
|
|
|
|
dbus_free (dir->dir_c);
|
|
|
|
|
dbus_free (dir);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
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);
|
2003-04-05 19:03:40 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
dbus_free (entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-04-05 19:03:40 +00:00
|
|
|
handle_timeout_callback (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
|
|
|
|
|
while (!dbus_timeout_handle (pending_activation->timeout))
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_wait_for_memory ();
|
2003-04-05 19:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-27 01:25:50 +00:00
|
|
|
static BusPendingActivation *
|
2003-04-11 00:03:06 +00:00
|
|
|
bus_pending_activation_ref (BusPendingActivation *pending_activation)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (pending_activation->refcount > 0);
|
|
|
|
|
pending_activation->refcount += 1;
|
2003-11-27 01:25:50 +00:00
|
|
|
|
|
|
|
|
return pending_activation;
|
2003-04-11 00:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bus_pending_activation_unref (BusPendingActivation *pending_activation)
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
if (pending_activation == NULL) /* hash table requires this */
|
2003-03-16 22:25:18 +00:00
|
|
|
return;
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
_dbus_assert (pending_activation->refcount > 0);
|
|
|
|
|
pending_activation->refcount -= 1;
|
|
|
|
|
|
|
|
|
|
if (pending_activation->refcount > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
if (pending_activation->timeout_added)
|
|
|
|
|
{
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context),
|
|
|
|
|
pending_activation->timeout,
|
|
|
|
|
handle_timeout_callback, pending_activation);
|
2003-04-05 19:03:40 +00:00
|
|
|
pending_activation->timeout_added = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pending_activation->timeout)
|
|
|
|
|
_dbus_timeout_unref (pending_activation->timeout);
|
|
|
|
|
|
|
|
|
|
if (pending_activation->babysitter)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
pending_activation->babysitter,
|
|
|
|
|
NULL))
|
|
|
|
|
_dbus_assert_not_reached ("setting watch functions to NULL failed");
|
|
|
|
|
|
|
|
|
|
_dbus_babysitter_unref (pending_activation->babysitter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_free (pending_activation->service_name);
|
2004-03-12 14:15:14 +00:00
|
|
|
dbus_free (pending_activation->exec);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
link = _dbus_list_get_first_link (&pending_activation->entries);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
|
|
|
|
while (link != NULL)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivationEntry *entry = link->data;
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_entry_free (entry);
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
link = _dbus_list_get_next_link (&pending_activation->entries, link);
|
2003-03-16 22:25:18 +00:00
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
_dbus_list_clear (&pending_activation->entries);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
pending_activation->activation->n_pending_activations -=
|
|
|
|
|
pending_activation->n_entries;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (pending_activation->activation->n_pending_activations >= 0);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
dbus_free (pending_activation);
|
2003-03-16 22:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
static BusActivationEntry *
|
|
|
|
|
bus_activation_entry_ref (BusActivationEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (entry->refcount > 0);
|
|
|
|
|
entry->refcount++;
|
|
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
static void
|
2004-03-12 14:07:16 +00:00
|
|
|
bus_activation_entry_unref (BusActivationEntry *entry)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2004-03-12 14:07:16 +00:00
|
|
|
if (entry == NULL) /* hash table requires this */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (entry->refcount > 0);
|
|
|
|
|
entry->refcount--;
|
|
|
|
|
|
|
|
|
|
if (entry->refcount > 0)
|
2003-02-15 18:22:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dbus_free (entry->name);
|
|
|
|
|
dbus_free (entry->exec);
|
2007-07-24 12:17:39 +00:00
|
|
|
dbus_free (entry->user);
|
2004-03-12 14:07:16 +00:00
|
|
|
dbus_free (entry->filename);
|
2003-04-03 21:56:22 +00:00
|
|
|
|
|
|
|
|
dbus_free (entry);
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
2004-03-12 14:07:16 +00:00
|
|
|
update_desktop_file_entry (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
BusServiceDirectory *s_dir,
|
|
|
|
|
DBusString *filename,
|
|
|
|
|
BusDesktopFile *desktop_file,
|
|
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2007-07-24 12:17:39 +00:00
|
|
|
char *name, *exec, *user;
|
2003-02-15 18:22:40 +00:00
|
|
|
BusActivationEntry *entry;
|
2004-03-12 14:07:16 +00:00
|
|
|
DBusStat stat_buf;
|
|
|
|
|
DBusString file_path;
|
2007-07-24 12:17:39 +00:00
|
|
|
DBusError tmp_error;
|
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;
|
2007-07-24 12:17:39 +00:00
|
|
|
user = NULL;
|
2003-03-13 00:56:43 +00:00
|
|
|
entry = NULL;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2007-07-24 12:17:39 +00:00
|
|
|
dbus_error_init (&tmp_error);
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!_dbus_string_init (&file_path))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&file_path, s_dir->dir_c) ||
|
|
|
|
|
!_dbus_concat_dir_and_file (&file_path, filename))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_stat (&file_path, &stat_buf, NULL))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
2005-07-14 20:44:15 +00:00
|
|
|
"Can't stat the service file\n");
|
2004-03-12 14:07:16 +00:00
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
if (!bus_desktop_file_get_string (desktop_file,
|
2005-07-14 20:44:15 +00:00
|
|
|
DBUS_SERVICE_SECTION,
|
|
|
|
|
DBUS_SERVICE_NAME,
|
2006-09-11 15:24:10 +00:00
|
|
|
&name,
|
|
|
|
|
error))
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
|
|
|
|
if (!bus_desktop_file_get_string (desktop_file,
|
2005-07-14 20:44:15 +00:00
|
|
|
DBUS_SERVICE_SECTION,
|
|
|
|
|
DBUS_SERVICE_EXEC,
|
2006-09-11 15:24:10 +00:00
|
|
|
&exec,
|
|
|
|
|
error))
|
|
|
|
|
goto failed;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2007-07-24 12:17:39 +00:00
|
|
|
/* user is not _required_ unless we are using system activation */
|
|
|
|
|
if (!bus_desktop_file_get_string (desktop_file,
|
|
|
|
|
DBUS_SERVICE_SECTION,
|
|
|
|
|
DBUS_SERVICE_USER,
|
|
|
|
|
&user, &tmp_error))
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
|
|
|
|
|
/* if we got OOM, then exit */
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* if we have error because we didn't find anything then continue */
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
dbus_free (user);
|
|
|
|
|
user = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
entry = _dbus_hash_table_lookup_string (s_dir->entries,
|
2005-07-14 20:44:15 +00:00
|
|
|
_dbus_string_get_const_data (filename));
|
2004-03-12 14:07:16 +00:00
|
|
|
if (entry == NULL) /* New file */
|
|
|
|
|
{
|
|
|
|
|
/* FIXME we need a better-defined algorithm for which service file to
|
|
|
|
|
* pick than "whichever one is first in the directory listing"
|
|
|
|
|
*/
|
|
|
|
|
if (_dbus_hash_table_lookup_string (activation->entries, name))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_FAILED,
|
|
|
|
|
"Service %s already exists in activation entry list\n", name);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
entry = dbus_new0 (BusActivationEntry, 1);
|
|
|
|
|
if (entry == NULL)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
entry->name = name;
|
|
|
|
|
entry->exec = exec;
|
2007-07-24 12:17:39 +00:00
|
|
|
entry->user = user;
|
2004-03-12 14:07:16 +00:00
|
|
|
entry->refcount = 1;
|
|
|
|
|
|
|
|
|
|
entry->s_dir = s_dir;
|
|
|
|
|
entry->filename = _dbus_strdup (_dbus_string_get_const_data (filename));
|
|
|
|
|
if (!entry->filename)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (activation->entries, entry->name, bus_activation_entry_ref (entry)))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (s_dir->entries, entry->filename, bus_activation_entry_ref (entry)))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
/* Revert the insertion in the entries table */
|
|
|
|
|
_dbus_hash_table_remove_string (activation->entries, entry->name);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
_dbus_verbose ("Added \"%s\" to list of services\n", entry->name);
|
|
|
|
|
}
|
|
|
|
|
else /* Just update the entry */
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2004-03-12 14:07:16 +00:00
|
|
|
bus_activation_entry_ref (entry);
|
|
|
|
|
_dbus_hash_table_remove_string (activation->entries, entry->name);
|
|
|
|
|
|
|
|
|
|
if (_dbus_hash_table_lookup_string (activation->entries, name))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("The new service name \"%s\" of service file \"%s\" already in cache, ignoring\n",
|
|
|
|
|
name, _dbus_string_get_const_data (&file_path));
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
dbus_free (entry->name);
|
|
|
|
|
dbus_free (entry->exec);
|
2007-07-24 12:17:39 +00:00
|
|
|
dbus_free (entry->user);
|
2004-03-12 14:07:16 +00:00
|
|
|
entry->name = name;
|
|
|
|
|
entry->exec = exec;
|
2007-07-24 12:17:39 +00:00
|
|
|
entry->user = user;
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!_dbus_hash_table_insert_string (activation->entries,
|
2005-07-14 20:44:15 +00:00
|
|
|
entry->name, bus_activation_entry_ref(entry)))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
/* Also remove path to entries hash since we want this in sync with
|
|
|
|
|
* the entries hash table */
|
|
|
|
|
_dbus_hash_table_remove_string (entry->s_dir->entries,
|
|
|
|
|
entry->filename);
|
|
|
|
|
bus_activation_entry_unref (entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
entry->mtime = stat_buf.mtime;
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&file_path);
|
|
|
|
|
bus_activation_entry_unref (entry);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
dbus_free (name);
|
|
|
|
|
dbus_free (exec);
|
2007-07-24 12:17:39 +00:00
|
|
|
dbus_free (user);
|
2004-03-12 14:07:16 +00:00
|
|
|
_dbus_string_free (&file_path);
|
|
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
|
bus_activation_entry_unref (entry);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
check_service_file (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
BusActivationEntry *entry,
|
|
|
|
|
BusActivationEntry **updated_entry,
|
|
|
|
|
DBusError *error)
|
2004-03-12 14:07:16 +00:00
|
|
|
{
|
|
|
|
|
DBusStat stat_buf;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
BusActivationEntry *tmp_entry;
|
|
|
|
|
DBusString file_path;
|
|
|
|
|
DBusString filename;
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
tmp_entry = entry;
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&filename, entry->filename);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&file_path))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
2004-03-12 14:07:16 +00:00
|
|
|
return FALSE;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&file_path, entry->s_dir->dir_c) ||
|
|
|
|
|
!_dbus_concat_dir_and_file (&file_path, &filename))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
2004-03-12 14:07:16 +00:00
|
|
|
retval = FALSE;
|
|
|
|
|
goto out;
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!_dbus_stat (&file_path, &stat_buf, NULL))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("****** Can't stat file \"%s\", removing from cache\n",
|
2005-07-14 20:44:15 +00:00
|
|
|
_dbus_string_get_const_data (&file_path));
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
_dbus_hash_table_remove_string (activation->entries, entry->name);
|
|
|
|
|
_dbus_hash_table_remove_string (entry->s_dir->entries, entry->filename);
|
|
|
|
|
|
|
|
|
|
tmp_entry = NULL;
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (stat_buf.mtime > entry->mtime)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BusDesktopFile *desktop_file;
|
|
|
|
|
DBusError tmp_error;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&tmp_error);
|
|
|
|
|
|
|
|
|
|
desktop_file = bus_desktop_file_load (&file_path, &tmp_error);
|
|
|
|
|
if (desktop_file == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Could not load %s: %s\n",
|
|
|
|
|
_dbus_string_get_const_data (&file_path),
|
|
|
|
|
tmp_error.message);
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2006-09-11 15:24:10 +00:00
|
|
|
|
|
|
|
|
/* @todo We can return OOM or a DBUS_ERROR_FAILED error
|
|
|
|
|
* Handle these both better
|
|
|
|
|
*/
|
2005-07-14 20:44:15 +00:00
|
|
|
if (!update_desktop_file_entry (activation, entry->s_dir, &filename, desktop_file, &tmp_error))
|
|
|
|
|
{
|
|
|
|
|
bus_desktop_file_free (desktop_file);
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_desktop_file_free (desktop_file);
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
out:
|
|
|
|
|
_dbus_string_free (&file_path);
|
|
|
|
|
|
|
|
|
|
if (updated_entry != NULL)
|
|
|
|
|
*updated_entry = tmp_entry;
|
|
|
|
|
return retval;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-12 14:07:16 +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
|
2004-03-12 14:07:16 +00:00
|
|
|
update_directory (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
BusServiceDirectory *s_dir,
|
|
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
|
|
|
|
DBusDirIter *iter;
|
|
|
|
|
DBusString dir, filename;
|
2003-03-13 00:56:43 +00:00
|
|
|
BusDesktopFile *desktop_file;
|
|
|
|
|
DBusError tmp_error;
|
2003-04-03 21:56:22 +00:00
|
|
|
dbus_bool_t retval;
|
2004-03-12 14:07:16 +00:00
|
|
|
BusActivationEntry *entry;
|
|
|
|
|
DBusString full_path;
|
2003-04-03 21:56:22 +00:00
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
iter = NULL;
|
|
|
|
|
desktop_file = NULL;
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
_dbus_string_init_const (&dir, s_dir->dir_c);
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
retval = FALSE;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
/* from this point it's safe to "goto out" */
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
iter = _dbus_directory_open (&dir, error);
|
|
|
|
|
if (iter == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to open directory %s: %s\n",
|
2005-07-14 20:44:15 +00:00
|
|
|
s_dir->dir_c,
|
|
|
|
|
error ? error->message : "unknown");
|
2003-04-03 21:56:22 +00:00
|
|
|
goto out;
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
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);
|
|
|
|
|
|
2003-02-15 18:22:40 +00:00
|
|
|
if (!_dbus_string_ends_with_c_str (&filename, ".service"))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Skipping non-.service file %s\n",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&filename));
|
2005-07-14 20:44:15 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
entry = _dbus_hash_table_lookup_string (s_dir->entries, _dbus_string_get_const_data (&filename));
|
|
|
|
|
if (entry) /* Already has this service file in the cache */
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
if (!check_service_file (activation, entry, NULL, error))
|
|
|
|
|
goto out;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!_dbus_string_append (&full_path, s_dir->dir_c) ||
|
2005-07-14 20:44:15 +00:00
|
|
|
!_dbus_concat_dir_and_file (&full_path, &filename))
|
2004-03-12 14:07:16 +00:00
|
|
|
{
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
/* New file */
|
2003-03-13 00:56:43 +00:00
|
|
|
desktop_file = bus_desktop_file_load (&full_path, &tmp_error);
|
|
|
|
|
if (desktop_file == NULL)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Could not load %s: %s\n",
|
2003-03-31 20:56:29 +00:00
|
|
|
_dbus_string_get_const_data (&full_path),
|
2005-07-14 20:44:15 +00:00
|
|
|
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);
|
2003-04-03 21:56:22 +00:00
|
|
|
goto out;
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-02-15 18:22:40 +00:00
|
|
|
|
2006-09-11 15:24:10 +00:00
|
|
|
/* @todo We can return OOM or a DBUS_ERROR_FAILED error
|
|
|
|
|
* Handle these both better
|
|
|
|
|
*/
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!update_desktop_file_entry (activation, s_dir, &filename, desktop_file, &tmp_error))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
bus_desktop_file_free (desktop_file);
|
2003-03-13 00:56:43 +00:00
|
|
|
desktop_file = NULL;
|
2005-07-14 20:44:15 +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);
|
2003-04-03 21:56:22 +00:00
|
|
|
goto out;
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&tmp_error);
|
2005-07-14 20:44:15 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
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);
|
2003-04-03 21:56:22 +00:00
|
|
|
goto out;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
retval = TRUE;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
out:
|
|
|
|
|
if (!retval)
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
else
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
if (iter != NULL)
|
|
|
|
|
_dbus_directory_close (iter);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
|
2003-04-03 21:56:22 +00:00
|
|
|
return retval;
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
static dbus_bool_t
|
|
|
|
|
populate_environment (BusActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
DBusString key;
|
|
|
|
|
DBusString value;
|
|
|
|
|
int i;
|
|
|
|
|
char **environment;
|
2009-01-06 16:48:39 -05:00
|
|
|
dbus_bool_t retval = FALSE;
|
2008-07-10 14:35:38 -04:00
|
|
|
|
|
|
|
|
environment = _dbus_get_environment ();
|
|
|
|
|
|
|
|
|
|
if (environment == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&key))
|
|
|
|
|
{
|
|
|
|
|
dbus_free_string_array (environment);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&value))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&key);
|
|
|
|
|
dbus_free_string_array (environment);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; environment[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_string_append (&key, environment[i]))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (_dbus_string_split_on_byte (&key, '=', &value))
|
|
|
|
|
{
|
|
|
|
|
char *hash_key, *hash_value;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_steal_data (&key, &hash_key))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_steal_data (&value, &hash_value))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (activation->environment,
|
|
|
|
|
hash_key, hash_value))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_dbus_string_set_length (&key, 0);
|
|
|
|
|
_dbus_string_set_length (&value, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (environment[i] != NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&key);
|
|
|
|
|
_dbus_string_free (&value);
|
|
|
|
|
dbus_free_string_array (environment);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 15:04:14 -05:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_reload (BusActivation *activation,
|
|
|
|
|
const DBusString *address,
|
|
|
|
|
DBusList **directories,
|
|
|
|
|
DBusError *error)
|
2003-02-15 18:22:40 +00:00
|
|
|
{
|
2004-03-12 14:07:16 +00:00
|
|
|
DBusList *link;
|
|
|
|
|
char *dir;
|
2010-01-28 15:04:14 -05:00
|
|
|
|
|
|
|
|
if (activation->server_address != NULL)
|
|
|
|
|
dbus_free (activation->server_address);
|
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;
|
|
|
|
|
}
|
2010-01-28 15:04:14 -05:00
|
|
|
|
|
|
|
|
if (activation->entries != NULL)
|
|
|
|
|
_dbus_hash_table_unref (activation->entries);
|
2003-03-13 03:52:58 +00:00
|
|
|
activation->entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
2004-03-12 14:07:16 +00:00
|
|
|
(DBusFreeFunction)bus_activation_entry_unref);
|
2003-03-13 03:52:58 +00:00
|
|
|
if (activation->entries == NULL)
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2010-01-28 15:04:14 -05:00
|
|
|
if (activation->directories != NULL)
|
|
|
|
|
_dbus_hash_table_unref (activation->directories);
|
2004-03-12 14:07:16 +00:00
|
|
|
activation->directories = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
2005-07-14 20:44:15 +00:00
|
|
|
(DBusFreeFunction)bus_service_directory_unref);
|
2010-01-28 15:04:14 -05:00
|
|
|
|
|
|
|
|
if (activation->directories == NULL)
|
2004-03-12 14:07:16 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2010-01-28 15:04:14 -05:00
|
|
|
|
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
|
|
|
{
|
2004-03-12 14:07:16 +00:00
|
|
|
BusServiceDirectory *s_dir;
|
2010-01-28 15:04:14 -05:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
dir = _dbus_strdup ((const char *) link->data);
|
|
|
|
|
if (!dir)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2010-01-28 15:04:14 -05:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
s_dir = dbus_new0 (BusServiceDirectory, 1);
|
|
|
|
|
if (!s_dir)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
dbus_free (dir);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
s_dir->refcount = 1;
|
|
|
|
|
s_dir->dir_c = dir;
|
2010-01-28 15:04:14 -05:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
s_dir->entries = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
2005-07-14 20:44:15 +00:00
|
|
|
(DBusFreeFunction)bus_activation_entry_unref);
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!s_dir->entries)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
bus_service_directory_unref (s_dir);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (activation->directories, s_dir->dir_c, s_dir))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
bus_service_directory_unref (s_dir);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2006-11-03 01:03:43 +00:00
|
|
|
/* only fail on OOM, it is ok if we can't read the directory */
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!update_directory (activation, s_dir, error))
|
2010-01-28 15:04:14 -05:00
|
|
|
{
|
|
|
|
|
if (dbus_error_has_name (error, DBUS_ERROR_NO_MEMORY))
|
2006-11-03 01:03:43 +00:00
|
|
|
goto failed;
|
|
|
|
|
else
|
|
|
|
|
dbus_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2010-01-28 15:04:14 -05:00
|
|
|
return TRUE;
|
|
|
|
|
failed:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BusActivation*
|
|
|
|
|
bus_activation_new (BusContext *context,
|
|
|
|
|
const DBusString *address,
|
|
|
|
|
DBusList **directories,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
BusActivation *activation;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
activation = dbus_new0 (BusActivation, 1);
|
|
|
|
|
if (activation == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
activation->refcount = 1;
|
|
|
|
|
activation->context = context;
|
|
|
|
|
activation->n_pending_activations = 0;
|
|
|
|
|
|
|
|
|
|
if (!bus_activation_reload (activation, address, directories, error))
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
/* Initialize this hash table once, we don't want to lose pending
|
|
|
|
|
* activations on reload. */
|
|
|
|
|
activation->pending_activations = _dbus_hash_table_new (DBUS_HASH_STRING, NULL,
|
|
|
|
|
(DBusFreeFunction)bus_pending_activation_unref);
|
|
|
|
|
|
|
|
|
|
if (activation->pending_activations == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
activation->environment = _dbus_hash_table_new (DBUS_HASH_STRING,
|
|
|
|
|
(DBusFreeFunction) dbus_free,
|
|
|
|
|
(DBusFreeFunction) dbus_free);
|
2010-01-28 15:04:14 -05:00
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
if (activation->environment == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!populate_environment (activation))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-27 01:25:50 +00:00
|
|
|
BusActivation *
|
2003-03-13 03:52:58 +00:00
|
|
|
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;
|
2003-11-27 01:25:50 +00:00
|
|
|
|
|
|
|
|
return activation;
|
2003-03-13 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_activation_unref (BusActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (activation->refcount > 0);
|
|
|
|
|
|
|
|
|
|
activation->refcount -= 1;
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
if (activation->refcount > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dbus_free (activation->server_address);
|
|
|
|
|
if (activation->entries)
|
|
|
|
|
_dbus_hash_table_unref (activation->entries);
|
|
|
|
|
if (activation->pending_activations)
|
|
|
|
|
_dbus_hash_table_unref (activation->pending_activations);
|
|
|
|
|
if (activation->directories)
|
|
|
|
|
_dbus_hash_table_unref (activation->directories);
|
2008-07-10 14:35:38 -04:00
|
|
|
if (activation->environment)
|
|
|
|
|
_dbus_hash_table_unref (activation->environment);
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
dbus_free (activation);
|
2003-02-15 18:22:40 +00:00
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
static dbus_bool_t
|
|
|
|
|
add_bus_environment (BusActivation *activation,
|
|
|
|
|
DBusError *error)
|
2003-02-17 09:59:23 +00:00
|
|
|
{
|
2003-04-03 05:22:49 +00:00
|
|
|
const char *type;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
if (!bus_activation_set_environment_variable (activation,
|
|
|
|
|
"DBUS_STARTER_ADDRESS",
|
|
|
|
|
activation->server_address,
|
|
|
|
|
error))
|
|
|
|
|
return FALSE;
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
|
2003-04-03 05:22:49 +00:00
|
|
|
type = bus_context_get_type (activation->context);
|
|
|
|
|
if (type != NULL)
|
|
|
|
|
{
|
2008-07-10 14:35:38 -04:00
|
|
|
if (!bus_activation_set_environment_variable (activation,
|
|
|
|
|
"DBUS_STARTER_BUS_TYPE", type,
|
|
|
|
|
error))
|
|
|
|
|
return FALSE;
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
|
|
|
|
|
if (strcmp (type, "session") == 0)
|
|
|
|
|
{
|
2008-07-10 14:35:38 -04:00
|
|
|
if (!bus_activation_set_environment_variable (activation,
|
|
|
|
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
|
|
|
activation->server_address,
|
|
|
|
|
error))
|
|
|
|
|
return FALSE;
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
}
|
|
|
|
|
else if (strcmp (type, "system") == 0)
|
|
|
|
|
{
|
2008-07-10 14:35:38 -04:00
|
|
|
if (!bus_activation_set_environment_variable (activation,
|
|
|
|
|
"DBUS_SYSTEM_BUS_ADDRESS",
|
|
|
|
|
activation->server_address,
|
|
|
|
|
error))
|
|
|
|
|
return FALSE;
|
2003-10-16 Havoc Pennington <hp@redhat.com>
* bus/connection.c (bus_pending_reply_expired): either cancel or
execute, not both
(bus_connections_check_reply): use unlink, not remove_link, as we
don't want to free the link; fixes double free mess
* dbus/dbus-pending-call.c (dbus_pending_call_block): fix in case
where no reply was received
* dbus/dbus-connection.c (_dbus_pending_call_complete_and_unlock):
fix a refcount leak
* bus/signals.c (match_rule_matches): add special cases for the
bus driver, so you can match on sender/destination for it.
* dbus/dbus-sysdeps.c (_dbus_abort): print backtrace if
DBUS_PRINT_BACKTRACE is set
* dbus/dbus-internals.c: add pid to assertion failure messages
* dbus/dbus-connection.c: add message type code to the debug spew
* glib/dbus-gproxy.c (gproxy_get_match_rule): match rules want
sender=foo not service=foo
* dbus/dbus-bus.c (dbus_bus_get): if the activation bus is the
session bus but DBUS_SESSION_BUS_ADDRESS isn't set, use
DBUS_ACTIVATION_ADDRESS instead
* bus/activation.c: set DBUS_SESSION_BUS_ADDRESS,
DBUS_SYSTEM_BUS_ADDRESS if appropriate
* bus/bus.c (bus_context_new): handle OOM copying bus type into
context struct
* dbus/dbus-message.c (dbus_message_iter_get_object_path): new function
(dbus_message_iter_get_object_path_array): new function (half
finished, disabled for the moment)
* glib/dbus-gproxy.c (dbus_gproxy_end_call): properly handle
DBUS_MESSAGE_TYPE_ERROR
* tools/dbus-launch.c (babysit): support DBUS_DEBUG_OUTPUT to
avoid redirecting stderr to /dev/null
(babysit): close stdin if not doing the "exit_with_session" thing
* dbus/dbus-sysdeps.c (_dbus_become_daemon): delete some leftover
debug code; change DBUS_DEBUG_OUTPUT to only enable stderr, not
stdout/stdin, so things don't get confused
* bus/system.conf.in: fix to allow replies, I modified .conf
instead of .conf.in again.
2003-10-16 06:34:51 +00:00
|
|
|
}
|
2003-04-03 05:22:49 +00:00
|
|
|
}
|
2008-07-10 14:35:38 -04:00
|
|
|
|
|
|
|
|
return TRUE;
|
2003-02-17 09:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation;
|
|
|
|
|
DBusPreallocatedHash *hash_entry;
|
|
|
|
|
} RestorePendingData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
restore_pending (void *data)
|
|
|
|
|
{
|
|
|
|
|
RestorePendingData *d = data;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (d->pending_activation != NULL);
|
|
|
|
|
_dbus_assert (d->hash_entry != NULL);
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Restoring pending activation for service %s, has timeout = %d\n",
|
|
|
|
|
d->pending_activation->service_name,
|
|
|
|
|
d->pending_activation->timeout_added);
|
|
|
|
|
|
|
|
|
|
_dbus_hash_table_insert_string_preallocated (d->pending_activation->activation->pending_activations,
|
|
|
|
|
d->hash_entry,
|
|
|
|
|
d->pending_activation->service_name, d->pending_activation);
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_ref (d->pending_activation);
|
|
|
|
|
|
|
|
|
|
d->hash_entry = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_pending_restore_data (void *data)
|
|
|
|
|
{
|
|
|
|
|
RestorePendingData *d = data;
|
|
|
|
|
|
|
|
|
|
if (d->hash_entry)
|
|
|
|
|
_dbus_hash_table_free_preallocated_entry (d->pending_activation->activation->pending_activations,
|
|
|
|
|
d->hash_entry);
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_unref (d->pending_activation);
|
|
|
|
|
|
|
|
|
|
dbus_free (d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_restore_pending_to_transaction (BusTransaction *transaction,
|
|
|
|
|
BusPendingActivation *pending_activation)
|
|
|
|
|
{
|
|
|
|
|
RestorePendingData *d;
|
|
|
|
|
|
|
|
|
|
d = dbus_new (RestorePendingData, 1);
|
|
|
|
|
if (d == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d->pending_activation = pending_activation;
|
|
|
|
|
d->hash_entry = _dbus_hash_table_preallocate_entry (d->pending_activation->activation->pending_activations);
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_ref (d->pending_activation);
|
|
|
|
|
|
|
|
|
|
if (d->hash_entry == NULL ||
|
|
|
|
|
!bus_transaction_add_cancel_hook (transaction, restore_pending, d,
|
|
|
|
|
free_pending_restore_data))
|
|
|
|
|
{
|
|
|
|
|
free_pending_restore_data (d);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Saved pending activation to be restored if the transaction fails\n");
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
dbus_bool_t
|
2003-04-02 20:14:52 +00:00
|
|
|
bus_activation_service_created (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
const char *service_name,
|
2003-04-02 20:14:52 +00:00
|
|
|
BusTransaction *transaction,
|
2005-07-14 20:44:15 +00:00
|
|
|
DBusError *error)
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
|
|
|
|
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))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
/* Only send activation replies to regular activation requests. */
|
|
|
|
|
if (!entry->auto_activation)
|
|
|
|
|
{
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
dbus_uint32_t result;
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
message = dbus_message_new_method_return (entry->activation_message);
|
|
|
|
|
if (!message)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
|
2005-01-18 20:42:15 +00:00
|
|
|
result = DBUS_START_REPLY_SUCCESS;
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_UINT32, &result,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_from_driver (transaction, entry->connection, message))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-03-16 18:00:35 +00:00
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_send_pending_auto_activation_messages (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
BusService *service,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2004-03-16 18:00:35 +00:00
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
/* Check if it's a pending activation */
|
|
|
|
|
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations,
|
2005-07-14 20:44:15 +00:00
|
|
|
bus_service_get_name (service));
|
2004-03-16 18:00:35 +00:00
|
|
|
|
|
|
|
|
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 (entry->auto_activation && dbus_connection_get_is_connected (entry->connection))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
DBusConnection *addressed_recipient;
|
|
|
|
|
|
* configure.in: Add test/name-test/Makefile to the generated
Makefile list
* dbus/dbus-shared.h (#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT):
New flag which replaces DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT
(#define DBUS_NAME_FLAG_DO_NOT_QUEUE): New flag for specifying
not to queue an ower if it can't be the primary owner
* bus/bus.h: Add new internal BusOwner struct
* bus/driver.c (bus_driver_handle_hello): Send flags (0 for default)
to bus_registry_ensure and don't set the prohibit_replacement flag
since they are now set per BusOwner and not per name.
(bus_driver_handle_list_queued_owners): bus method (ListQueuedOwners)
that returns the list of connections in a name's connection queue
* bus/services.c (struct BusService): remove prohibit_replacement field
(struct BusOwner): new struct for keeping track of queued connections
and their associated flags for the queue
(struct BusRegistry): add a BusOwner memory pool
(bus_registry_new): initialize the BusOwner memory pool
(bus_registry_unref): free the BusOwner memory pool
(_bus_service_find_owner_link): new internal method for
searching the queue for a specific connection
(bus_owner_set_flags): new method for adding setting the flags on a
bus owner
(bus_owner_new): new method that creates a BusOwner object from the
pool and sets its flags
(bus_owner_ref, bus_owner_unref): ref counting for BusOwner objects
(bus_registry_ensure): Add the flags parameter
(bus_registry_acquire_service): Switch from using raw connections to
using the BusOwner struct
Add new state machine for dealing with the new set of flags
(bus_registry_set_service_context_table, struct OwnershipCancelData,
cancel_ownership, free_ownership_cancel_data,
add_cancel_ownership_to_transaction, struct OwnershipRestoreData,
restore_ownership, free_ownership_restore_data,
add_restore_ownership_to_transaction): Switch to using BusOwner
instead of raw connections
(bus_service_add_owner): Add flags parameter
Switch to using BusOwner instead of raw connections
Add state machine for dealing with the new set of flags
(bus_service_swap_owner): Swaps the first and second owners in the
queue. Used to make sure proper signals are sent when a service looses
or gains primary ownership. We never insert an owner at the top of the
queue. Instead we insert it in the second position and then swap.
(bus_service_remove_owner): Remove the owner from the queue sending
out the NameLost and NameOwnerChanged signals if the we were the
primary owner
(bus_service_get_primary_owners_connection): New method that extracts
the connection from the primary owner
(bus_service_get_primary_owner): Returns the BusOwner instead of the
connection
(bus_service_get_allow_replacement): Changed from the old
bus_service_get_prohibit_replacement method. Checks the flags of the
primary owner and returns if it can be replaced or not
(bus_service_set_prohibit_replacement): removed
(bus_service_has_owner): returns TRUE if and owner with
the specified connection exists in the queue
* dbus/dbus-bus.c (dbus_bus_connection_get_unique_name): New helper
method that only compiles if tests are enabled. Allows us to get the
unique name of a connection so we can check it against the queue when
doing regression tests
* bus/activation.c (bus_activation_send_pending_auto_activate),
bus/dispatch.c (bus_dispatch),
bus/driver.c (bus_driver_handle_get_service_owner,
bus_driver_handle_get_connection_unix_user,
bus_driver_handle_get_connection_unix_process_id,
bus_driver_handle_get_connection_selinux_security_context),
bus/signals.c (connection_is_primary_owner):
use bus_service_get_primary_owners_connection instead of
bus_service_get_primary_owner
* dbus/dbus-sysdeps.c (_dbus_connect_unix_socket,
_dbus_listen_unix_socket): Calculate the length of the socket
path and use that instead of using a fixed length which was
causing socket names to contain many trailing Nul bytes.
* dbus/dbus-glib-lowlevel.h, glib/dbus-gobject.c
(dbus_g_method_get_sender): New method for extracting the sender
from a DBusGMethodInvocation
(dbus_g_method_return_get_reply): changed name to
dbus_g_method_get_reply
(dbus_g_method_return_send_reply): changed name to
dbus_g_method_send reply
* doc/dbus-specification.xml: New docs that describe how the new
queueing system works and talks about the changes to the how
we specify socket names
* glib/examples/example-service.c,
glib/examples/example-signal-emitter.c,
glib/examples/statemachine/statemachine-server.c:
Changed the RequestName flags to the new system
* test/name-test/ (test-names.c, run-test.sh, Makefile.am): New
regression test suite for testing various states of the new
queueing system
2005-11-22 20:37:00 +00:00
|
|
|
addressed_recipient = bus_service_get_primary_owners_connection (service);
|
2005-07-14 20:44:15 +00:00
|
|
|
|
|
|
|
|
/* Check the security policy, which has the side-effect of adding an
|
|
|
|
|
* expected pending reply.
|
|
|
|
|
*/
|
2004-03-16 18:00:35 +00:00
|
|
|
if (!bus_context_check_security_policy (activation->context, transaction,
|
2005-07-14 20:44:15 +00:00
|
|
|
entry->connection,
|
|
|
|
|
addressed_recipient,
|
|
|
|
|
addressed_recipient,
|
|
|
|
|
entry->activation_message, error))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send (transaction, addressed_recipient, entry->activation_message))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
|
|
|
|
link = next;
|
|
|
|
|
}
|
2003-04-11 00:03:06 +00:00
|
|
|
|
|
|
|
|
if (!add_restore_pending_to_transaction (transaction, pending_activation))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Could not add cancel hook to transaction to revert removing pending activation\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-03-16 18:00:35 +00:00
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations, bus_service_get_name (service));
|
2003-03-16 22:25:18 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
/**
|
2006-09-11 17:41:21 +00:00
|
|
|
* FIXME @todo the error messages here would ideally be preallocated
|
2003-04-05 19:03:40 +00:00
|
|
|
* so we don't need to allocate memory to send them.
|
|
|
|
|
* Using the usual tactic, prealloc an OOM message, then
|
|
|
|
|
* if we can't alloc the real error send the OOM error instead.
|
|
|
|
|
*/
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
try_send_activation_failure (BusPendingActivation *pending_activation,
|
|
|
|
|
const DBusError *how)
|
|
|
|
|
{
|
|
|
|
|
BusActivation *activation;
|
|
|
|
|
DBusList *link;
|
|
|
|
|
BusTransaction *transaction;
|
|
|
|
|
|
|
|
|
|
activation = pending_activation->activation;
|
|
|
|
|
|
|
|
|
|
transaction = bus_transaction_new (activation->context);
|
|
|
|
|
if (transaction == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
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))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-27 06:25:42 +00:00
|
|
|
if (!bus_transaction_send_error_reply (transaction,
|
|
|
|
|
entry->connection,
|
|
|
|
|
how,
|
|
|
|
|
entry->activation_message))
|
2003-04-05 19:03:40 +00:00
|
|
|
goto error;
|
2005-07-14 20:44:15 +00:00
|
|
|
}
|
2003-04-27 06:25:42 +00:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
link = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_transaction_execute_and_free (transaction);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (transaction)
|
|
|
|
|
bus_transaction_cancel_and_free (transaction);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Free the pending activation and send an error message to all the
|
|
|
|
|
* connections that were waiting for it.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
pending_activation_failed (BusPendingActivation *pending_activation,
|
|
|
|
|
const DBusError *how)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME use preallocated OOM messages instead of bus_wait_for_memory() */
|
|
|
|
|
while (!try_send_activation_failure (pending_activation, how))
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_wait_for_memory ();
|
2003-04-05 19:03:40 +00:00
|
|
|
|
|
|
|
|
/* Destroy this pending activation */
|
|
|
|
|
_dbus_hash_table_remove_string (pending_activation->activation->pending_activations,
|
|
|
|
|
pending_activation->service_name);
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-24 12:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* Depending on the exit code of the helper, set the error accordingly
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2009-12-14 18:12:24 -05:00
|
|
|
handle_servicehelper_exit_error (int exit_code,
|
|
|
|
|
DBusError *error)
|
2007-07-24 12:22:43 +00:00
|
|
|
{
|
|
|
|
|
switch (exit_code)
|
|
|
|
|
{
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_NO_MEMORY:
|
2007-07-24 22:11:00 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
|
|
|
|
|
"Launcher could not run (out of memory)");
|
2007-07-24 12:22:43 +00:00
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_SETUP_FAILED:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_SETUP_FAILED,
|
|
|
|
|
"Failed to setup environment correctly");
|
|
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_NAME_INVALID:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_INVALID,
|
|
|
|
|
"Bus name is not valid or missing");
|
|
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND,
|
|
|
|
|
"Bus name not found in system service directory");
|
|
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_PERMISSIONS_INVALID:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID,
|
|
|
|
|
"The permission of the setuid helper is not correct");
|
|
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_FILE_INVALID:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID,
|
|
|
|
|
"The service file is incorrect or does not have all required attributes");
|
|
|
|
|
break;
|
|
|
|
|
case BUS_SPAWN_EXIT_CODE_EXEC_FAILED:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
|
|
|
|
|
"Cannot launch daemon, file not found or permissions invalid");
|
|
|
|
|
break;
|
2007-07-24 22:11:00 +00:00
|
|
|
case BUS_SPAWN_EXIT_CODE_INVALID_ARGS:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
|
|
|
|
|
"Invalid arguments to command line");
|
|
|
|
|
break;
|
2007-07-26 23:01:14 +00:00
|
|
|
case BUS_SPAWN_EXIT_CODE_CHILD_SIGNALED:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED,
|
|
|
|
|
"Launched child was signaled, it probably crashed");
|
|
|
|
|
break;
|
2007-07-24 12:22:43 +00:00
|
|
|
default:
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
|
|
|
|
|
"Launch helper exited with unknown return code %i", exit_code);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
babysitter_watch_callback (DBusWatch *watch,
|
|
|
|
|
unsigned int condition,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
DBusBabysitter *babysitter;
|
2009-12-14 18:12:24 -05:00
|
|
|
dbus_bool_t uses_servicehelper;
|
2003-04-05 19:03:40 +00:00
|
|
|
|
|
|
|
|
babysitter = pending_activation->babysitter;
|
2009-12-14 18:12:24 -05:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
_dbus_babysitter_ref (babysitter);
|
2009-12-14 18:12:24 -05:00
|
|
|
|
2003-04-18 04:18:57 +00:00
|
|
|
retval = dbus_watch_handle (watch, condition);
|
|
|
|
|
|
2009-12-14 18:12:24 -05:00
|
|
|
/* There are two major cases here; are we the system bus or the session? Here this
|
|
|
|
|
* is distinguished by whether or not we use a setuid helper launcher. With the launch helper,
|
|
|
|
|
* some process exit codes are meaningful, processed by handle_servicehelper_exit_error.
|
|
|
|
|
*
|
|
|
|
|
* In both cases though, just ignore when a process exits with status 0; it's possible for
|
|
|
|
|
* a program to (misguidedly) "daemonize", and that appears to us as an exit. This closes a race
|
|
|
|
|
* condition between this code and the child process claiming the bus name.
|
|
|
|
|
*/
|
|
|
|
|
uses_servicehelper = bus_context_get_servicehelper (pending_activation->activation->context) != NULL;
|
|
|
|
|
|
2003-04-18 04:18:57 +00:00
|
|
|
/* FIXME this is broken in the same way that
|
|
|
|
|
* connection watches used to be; there should be
|
|
|
|
|
* a separate callback for status change, instead
|
|
|
|
|
* of doing "if we handled a watch status might
|
|
|
|
|
* have changed"
|
|
|
|
|
*
|
|
|
|
|
* Fixing this lets us move dbus_watch_handle
|
|
|
|
|
* calls into dbus-mainloop.c
|
|
|
|
|
*/
|
2003-04-05 19:03:40 +00:00
|
|
|
if (_dbus_babysitter_get_child_exited (babysitter))
|
|
|
|
|
{
|
|
|
|
|
DBusError error;
|
2004-03-12 14:15:14 +00:00
|
|
|
DBusHashIter iter;
|
2009-12-14 18:12:24 -05:00
|
|
|
dbus_bool_t activation_failed;
|
|
|
|
|
int exit_code = 0;
|
|
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
dbus_error_init (&error);
|
2009-12-14 18:12:24 -05:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
_dbus_babysitter_set_child_exit_error (babysitter, &error);
|
|
|
|
|
|
2009-12-14 18:12:24 -05:00
|
|
|
/* Explicitly check for SPAWN_CHILD_EXITED to avoid overwriting an
|
|
|
|
|
* exec error */
|
|
|
|
|
if (dbus_error_has_name (&error, DBUS_ERROR_SPAWN_CHILD_EXITED)
|
|
|
|
|
&& _dbus_babysitter_get_child_exit_status (babysitter, &exit_code))
|
|
|
|
|
{
|
|
|
|
|
activation_failed = exit_code != 0;
|
|
|
|
|
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
|
|
if (activation_failed)
|
2007-07-24 12:22:43 +00:00
|
|
|
{
|
2009-12-14 18:12:24 -05:00
|
|
|
if (uses_servicehelper)
|
|
|
|
|
handle_servicehelper_exit_error (exit_code, &error);
|
|
|
|
|
else
|
|
|
|
|
_dbus_babysitter_set_child_exit_error (babysitter, &error);
|
2007-07-24 12:22:43 +00:00
|
|
|
}
|
2009-12-14 18:12:24 -05:00
|
|
|
}
|
|
|
|
|
else
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2009-12-14 18:12:24 -05:00
|
|
|
activation_failed = TRUE;
|
2005-07-14 20:44:15 +00:00
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
|
2009-12-14 18:12:24 -05:00
|
|
|
if (activation_failed)
|
|
|
|
|
{
|
|
|
|
|
/* Destroy all pending activations with the same exec */
|
|
|
|
|
_dbus_hash_iter_init (pending_activation->activation->pending_activations,
|
|
|
|
|
&iter);
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
if (p != pending_activation && strcmp (p->exec, pending_activation->exec) == 0)
|
|
|
|
|
pending_activation_failed (p, &error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Destroys the pending activation */
|
|
|
|
|
pending_activation_failed (pending_activation, &error);
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
}
|
2009-12-14 18:12:24 -05:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
_dbus_babysitter_unref (babysitter);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_babysitter_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
return _dbus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context),
|
|
|
|
|
watch, babysitter_watch_callback, pending_activation,
|
|
|
|
|
NULL);
|
2003-04-05 19:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_babysitter_watch (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
_dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context),
|
|
|
|
|
watch, babysitter_watch_callback, pending_activation);
|
2003-04-05 19:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
pending_activation_timed_out (void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
|
|
/* Kill the spawned process, since it sucks
|
|
|
|
|
* (not sure this is what we want to do, but
|
|
|
|
|
* may as well try it for now)
|
|
|
|
|
*/
|
2004-03-12 14:15:14 +00:00
|
|
|
if (pending_activation->babysitter)
|
|
|
|
|
_dbus_babysitter_kill_child (pending_activation->babysitter);
|
2003-04-05 19:03:40 +00:00
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
dbus_set_error (&error, DBUS_ERROR_TIMED_OUT,
|
|
|
|
|
"Activation of %s timed out",
|
|
|
|
|
pending_activation->service_name);
|
|
|
|
|
|
|
|
|
|
pending_activation_failed (pending_activation, &error);
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-11 03:05:58 +00:00
|
|
|
static void
|
|
|
|
|
cancel_pending (void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Canceling pending activation of %s\n",
|
|
|
|
|
pending_activation->service_name);
|
|
|
|
|
|
|
|
|
|
if (pending_activation->babysitter)
|
|
|
|
|
_dbus_babysitter_kill_child (pending_activation->babysitter);
|
|
|
|
|
|
|
|
|
|
_dbus_hash_table_remove_string (pending_activation->activation->pending_activations,
|
|
|
|
|
pending_activation->service_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_pending_cancel_data (void *data)
|
|
|
|
|
{
|
|
|
|
|
BusPendingActivation *pending_activation = data;
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
add_cancel_pending_to_transaction (BusTransaction *transaction,
|
|
|
|
|
BusPendingActivation *pending_activation)
|
|
|
|
|
{
|
|
|
|
|
if (!bus_transaction_add_cancel_hook (transaction, cancel_pending,
|
|
|
|
|
pending_activation,
|
|
|
|
|
free_pending_cancel_data))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
bus_pending_activation_ref (pending_activation);
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Saved pending activation to be canceled if the transaction fails\n");
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
update_service_cache (BusActivation *activation, DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
DBusHashIter iter;
|
|
|
|
|
|
|
|
|
|
_dbus_hash_iter_init (activation->directories, &iter);
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
|
|
|
|
{
|
|
|
|
|
DBusError tmp_error;
|
|
|
|
|
BusServiceDirectory *s_dir;
|
|
|
|
|
|
|
|
|
|
s_dir = _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&tmp_error);
|
|
|
|
|
if (!update_directory (activation, s_dir, &tmp_error))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
|
|
|
|
|
{
|
|
|
|
|
dbus_move_error (&tmp_error, error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_free (&tmp_error);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BusActivationEntry *
|
|
|
|
|
activation_find_entry (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
DBusError *error)
|
2004-03-12 14:07:16 +00:00
|
|
|
{
|
|
|
|
|
BusActivationEntry *entry;
|
|
|
|
|
|
|
|
|
|
entry = _dbus_hash_table_lookup_string (activation->entries, service_name);
|
|
|
|
|
if (!entry)
|
|
|
|
|
{
|
|
|
|
|
if (!update_service_cache (activation, error))
|
2005-07-14 20:44:15 +00:00
|
|
|
return NULL;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
entry = _dbus_hash_table_lookup_string (activation->entries,
|
2005-07-14 20:44:15 +00:00
|
|
|
service_name);
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BusActivationEntry *updated_entry;
|
|
|
|
|
|
|
|
|
|
if (!check_service_file (activation, entry, &updated_entry, error))
|
2005-07-14 20:44:15 +00:00
|
|
|
return NULL;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
entry = updated_entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
|
{
|
2005-01-18 20:42:15 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_SERVICE_UNKNOWN,
|
2005-07-14 20:44:15 +00:00
|
|
|
"The name %s was not provided by any .service files",
|
|
|
|
|
service_name);
|
2004-03-12 14:07:16 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
static char **
|
|
|
|
|
bus_activation_get_environment (BusActivation *activation)
|
|
|
|
|
{
|
|
|
|
|
char **environment;
|
|
|
|
|
int i, length;
|
|
|
|
|
DBusString entry;
|
|
|
|
|
DBusHashIter iter;
|
|
|
|
|
|
|
|
|
|
length = _dbus_hash_table_get_n_entries (activation->environment);
|
|
|
|
|
|
|
|
|
|
environment = dbus_new0 (char *, length + 1);
|
|
|
|
|
|
|
|
|
|
if (environment == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
_dbus_hash_iter_init (activation->environment, &iter);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&entry))
|
2008-07-15 04:01:49 -04:00
|
|
|
{
|
|
|
|
|
dbus_free_string_array (environment);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-07-10 14:35:38 -04:00
|
|
|
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
|
|
|
|
{
|
|
|
|
|
const char *key, *value;
|
|
|
|
|
|
|
|
|
|
key = (const char *) _dbus_hash_iter_get_string_key (&iter);
|
|
|
|
|
value = (const char *) _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append_printf (&entry, "%s=%s", key, value))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_steal_data (&entry, environment + i))
|
|
|
|
|
break;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&entry);
|
|
|
|
|
|
|
|
|
|
if (i != length)
|
|
|
|
|
{
|
2008-07-15 04:01:49 -04:00
|
|
|
dbus_free_string_array (environment);
|
2008-07-10 14:35:38 -04:00
|
|
|
environment = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return environment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_set_environment_variable (BusActivation *activation,
|
|
|
|
|
const char *key,
|
|
|
|
|
const char *value,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
char *hash_key;
|
|
|
|
|
char *hash_value;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
hash_key = NULL;
|
|
|
|
|
hash_value = NULL;
|
|
|
|
|
hash_key = _dbus_strdup (key);
|
|
|
|
|
|
|
|
|
|
if (hash_key == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
hash_value = _dbus_strdup (value);
|
|
|
|
|
|
|
|
|
|
if (hash_value == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_hash_table_insert_string (activation->environment,
|
|
|
|
|
hash_key, hash_value))
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
out:
|
|
|
|
|
if (retval == FALSE)
|
|
|
|
|
{
|
|
|
|
|
dbus_free (hash_key);
|
|
|
|
|
dbus_free (hash_value);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_activate_service (BusActivation *activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
DBusConnection *connection,
|
2003-04-02 20:14:52 +00:00
|
|
|
BusTransaction *transaction,
|
2005-07-14 20:44:15 +00:00
|
|
|
dbus_bool_t auto_activation,
|
|
|
|
|
DBusMessage *activation_message,
|
2003-03-16 22:25:18 +00:00
|
|
|
const char *service_name,
|
2005-07-14 20:44:15 +00:00
|
|
|
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;
|
2007-07-24 12:36:41 +00:00
|
|
|
const char *servicehelper;
|
2005-07-14 20:44:15 +00:00
|
|
|
char **argv;
|
2007-03-04 22:09:50 +00:00
|
|
|
char **envp = NULL;
|
2005-07-14 20:44:15 +00:00
|
|
|
int argc;
|
2003-03-16 22:25:18 +00:00
|
|
|
dbus_bool_t retval;
|
2004-03-12 14:15:14 +00:00
|
|
|
DBusHashIter iter;
|
|
|
|
|
dbus_bool_t activated;
|
2007-07-24 12:36:41 +00:00
|
|
|
DBusString command;
|
2004-03-12 14:15:14 +00:00
|
|
|
|
|
|
|
|
activated = TRUE;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
if (activation->n_pending_activations >=
|
|
|
|
|
bus_context_get_max_pending_activations (activation->context))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
|
2005-07-14 20:44:15 +00:00
|
|
|
"The maximum number of pending activations has been reached, activation of %s failed",
|
|
|
|
|
service_name);
|
2003-04-25 23:50:34 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
entry = activation_find_entry (activation, service_name, error);
|
|
|
|
|
if (!entry)
|
|
|
|
|
return FALSE;
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
/* Bypass the registry lookup if we're auto-activating, bus_dispatch would not
|
|
|
|
|
* call us if the service is already active.
|
|
|
|
|
*/
|
|
|
|
|
if (!auto_activation)
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
2004-07-29 08:00:45 +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)
|
|
|
|
|
{
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
dbus_uint32_t result;
|
|
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
_dbus_verbose ("Service \"%s\" is already active\n", service_name);
|
2003-04-10 05:12:19 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
message = dbus_message_new_method_return (activation_message);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
if (!message)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("No memory to create reply to activate message\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2005-01-18 20:42:15 +00:00
|
|
|
result = DBUS_START_REPLY_ALREADY_RUNNING;
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
if (!dbus_message_append_args (message,
|
2005-01-15 Havoc Pennington <hp@redhat.com>
* Land the new message args API and type system.
This patch is huge, but the public API change is not
really large. The set of D-BUS types has changed somewhat,
and the arg "getters" are more geared toward language bindings;
they don't make a copy, etc.
There are also some known issues. See these emails for details
on this huge patch:
http://lists.freedesktop.org/archives/dbus/2004-December/001836.html
http://lists.freedesktop.org/archives/dbus/2005-January/001922.html
* dbus/dbus-marshal-*: all the new stuff
* dbus/dbus-message.c: basically rewritten
* dbus/dbus-memory.c (check_guards): with "guards" enabled, init
freed blocks to be all non-nul bytes so using freed memory is less
likely to work right
* dbus/dbus-internals.c (_dbus_test_oom_handling): add
DBUS_FAIL_MALLOC=N environment variable, so you can do
DBUS_FAIL_MALLOC=0 to skip the out-of-memory checking, or
DBUS_FAIL_MALLOC=10 to make it really, really, really slow and
thorough.
* qt/message.cpp: port to the new message args API
(operator<<): use str.utf8() rather than str.unicode()
(pretty sure this is right from the Qt docs?)
* glib/dbus-gvalue.c: port to the new message args API
* bus/dispatch.c, bus/driver.c: port to the new message args API
* dbus/dbus-string.c (_dbus_string_init_const_len): initialize the
"locked" flag to TRUE and align_offset to 0; I guess we never
looked at these anyhow, but seems cleaner.
* dbus/dbus-string.h (_DBUS_STRING_ALLOCATION_PADDING):
move allocation padding macro to this header; use it to implement
(_DBUS_STRING_STATIC): ability to declare a static string.
* dbus/dbus-message.c (_dbus_message_has_type_interface_member):
change to return TRUE if the interface is not set.
* dbus/dbus-string.[hc]: move the D-BUS specific validation stuff
to dbus-marshal-validate.[hc]
* dbus/dbus-marshal-basic.c (_dbus_type_to_string): move here from
dbus-internals.c
* dbus/Makefile.am: cut over from dbus-marshal.[hc]
to dbus-marshal-*.[hc]
* dbus/dbus-object-tree.c (_dbus_decompose_path): move this
function here from dbus-marshal.c
2005-01-15 07:15:38 +00:00
|
|
|
DBUS_TYPE_UINT32, &result,
|
2004-07-29 08:00:45 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("No memory to set args of reply to activate message\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
retval = bus_transaction_send_from_driver (transaction, connection, message);
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
if (!retval)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to send reply\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
return retval;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
}
|
2005-07-14 20:44:15 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
pending_activation_entry = dbus_new0 (BusPendingActivationEntry, 1);
|
|
|
|
|
if (!pending_activation_entry)
|
|
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to create pending activation entry\n");
|
2003-03-16 22:25:18 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-16 18:00:35 +00:00
|
|
|
pending_activation_entry->auto_activation = auto_activation;
|
|
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
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))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to append a new entry to pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
pending_activation->n_entries += 1;
|
|
|
|
|
pending_activation->activation->n_pending_activations += 1;
|
2003-03-16 22:25:18 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pending_activation = dbus_new0 (BusPendingActivation, 1);
|
|
|
|
|
if (!pending_activation)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to create pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
|
|
|
|
|
pending_activation->activation = activation;
|
2003-04-11 00:03:06 +00:00
|
|
|
pending_activation->refcount = 1;
|
2003-04-05 19:03:40 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
pending_activation->service_name = _dbus_strdup (service_name);
|
|
|
|
|
if (!pending_activation->service_name)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to copy service name for pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-03-12 14:15:14 +00:00
|
|
|
pending_activation->exec = _dbus_strdup (entry->exec);
|
|
|
|
|
if (!pending_activation->exec)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to copy service exec for pending activation\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2004-03-12 14:15:14 +00:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
pending_activation->timeout =
|
|
|
|
|
_dbus_timeout_new (bus_context_get_activation_timeout (activation->context),
|
|
|
|
|
pending_activation_timed_out,
|
|
|
|
|
pending_activation,
|
|
|
|
|
NULL);
|
|
|
|
|
if (!pending_activation->timeout)
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to create timeout for pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
|
2003-04-06 23:53:27 +00:00
|
|
|
if (!_dbus_loop_add_timeout (bus_context_get_loop (activation->context),
|
|
|
|
|
pending_activation->timeout,
|
|
|
|
|
handle_timeout_callback,
|
|
|
|
|
pending_activation,
|
|
|
|
|
NULL))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to add timeout for pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
|
|
|
|
|
pending_activation->timeout_added = TRUE;
|
|
|
|
|
|
2003-03-17 02:26:41 +00:00
|
|
|
if (!_dbus_list_append (&pending_activation->entries, pending_activation_entry))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to add entry to just-created pending activation\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
bus_pending_activation_entry_free (pending_activation_entry);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-25 23:50:34 +00:00
|
|
|
|
|
|
|
|
pending_activation->n_entries += 1;
|
|
|
|
|
pending_activation->activation->n_pending_activations += 1;
|
2004-03-12 14:15:14 +00:00
|
|
|
|
|
|
|
|
activated = FALSE;
|
|
|
|
|
_dbus_hash_iter_init (activation->pending_activations, &iter);
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
if (strcmp (p->exec, entry->exec) == 0)
|
|
|
|
|
{
|
|
|
|
|
activated = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-03-12 14:15:14 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
if (!_dbus_hash_table_insert_string (activation->pending_activations,
|
2005-07-14 20:44:15 +00:00
|
|
|
pending_activation->service_name,
|
2003-04-11 03:05:58 +00:00
|
|
|
pending_activation))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to put pending activation in hash table\n");
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
bus_pending_activation_unref (pending_activation);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
}
|
2004-03-12 14:15:14 +00:00
|
|
|
|
2003-04-11 03:05:58 +00:00
|
|
|
if (!add_cancel_pending_to_transaction (transaction, pending_activation))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to add pending activation cancel hook to transaction\n");
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations,
|
2005-07-14 20:44:15 +00:00
|
|
|
pending_activation->service_name);
|
|
|
|
|
|
2003-04-11 03:05:58 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2004-07-29 08:00:45 +00:00
|
|
|
if (activated)
|
|
|
|
|
return TRUE;
|
2004-03-12 14:15:14 +00:00
|
|
|
|
2007-07-24 12:36:41 +00:00
|
|
|
/* use command as system and session different */
|
|
|
|
|
if (!_dbus_string_init (&command))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* does the bus use a helper? */
|
|
|
|
|
servicehelper = bus_context_get_servicehelper (activation->context);
|
|
|
|
|
if (servicehelper != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (entry->user == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&command);
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_SPAWN_FILE_INVALID,
|
|
|
|
|
"Cannot do system-bus activation with no user\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* join the helper path and the service name */
|
|
|
|
|
if (!_dbus_string_append (&command, servicehelper))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&command);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (!_dbus_string_append (&command, " "))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&command);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (!_dbus_string_append (&command, service_name))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&command);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* the bus does not use a helper, so we can append arguments with the exec line */
|
|
|
|
|
if (!_dbus_string_append (&command, entry->exec))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&command);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert command into arguments */
|
|
|
|
|
if (!_dbus_shell_parse_argv (_dbus_string_get_const_data (&command), &argc, &argv, error))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Failed to parse command line: %s\n", entry->exec);
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
|
|
|
|
|
_dbus_hash_table_remove_string (activation->pending_activations,
|
|
|
|
|
pending_activation->service_name);
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2007-07-24 12:36:41 +00:00
|
|
|
_dbus_string_free (&command);
|
2005-07-14 20:44:15 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-07-24 12:36:41 +00:00
|
|
|
_dbus_string_free (&command);
|
2005-07-14 20:44:15 +00:00
|
|
|
|
2008-07-10 14:35:38 -04:00
|
|
|
if (!add_bus_environment (activation, error))
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
dbus_free_string_array (argv);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
envp = bus_activation_get_environment (activation);
|
|
|
|
|
|
|
|
|
|
if (envp == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
dbus_free_string_array (argv);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
_dbus_verbose ("Spawning %s ...\n", argv[0]);
|
2003-04-05 19:03:40 +00:00
|
|
|
if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, argv,
|
2007-03-04 22:09:50 +00:00
|
|
|
envp,
|
2008-07-10 14:35:38 -04:00
|
|
|
NULL, activation,
|
2005-07-14 20:44:15 +00:00
|
|
|
error))
|
2003-03-16 22:25:18 +00:00
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to spawn child\n");
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
2005-07-14 20:44:15 +00:00
|
|
|
dbus_free_string_array (argv);
|
2008-07-10 14:35:38 -04:00
|
|
|
dbus_free_string_array (envp);
|
2005-07-14 20:44:15 +00:00
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-04-05 19:03:40 +00:00
|
|
|
|
2005-07-14 20:44:15 +00:00
|
|
|
dbus_free_string_array (argv);
|
2008-07-10 14:35:38 -04:00
|
|
|
envp = NULL;
|
2005-07-14 20:44:15 +00:00
|
|
|
|
2003-04-05 19:03:40 +00:00
|
|
|
_dbus_assert (pending_activation->babysitter != NULL);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter,
|
|
|
|
|
add_babysitter_watch,
|
2005-07-14 20:44:15 +00:00
|
|
|
remove_babysitter_watch,
|
2003-04-05 19:03:40 +00:00
|
|
|
NULL,
|
|
|
|
|
pending_activation,
|
|
|
|
|
NULL))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Failed to set babysitter watch functions\n");
|
2003-04-05 19:03:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2006-07-14 01:17:59 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_list_services (BusActivation *activation,
|
|
|
|
|
char ***listp,
|
|
|
|
|
int *array_len)
|
|
|
|
|
{
|
|
|
|
|
int i, j, len;
|
|
|
|
|
char **retval;
|
|
|
|
|
DBusHashIter iter;
|
|
|
|
|
|
|
|
|
|
len = _dbus_hash_table_get_n_entries (activation->entries);
|
|
|
|
|
retval = dbus_new (char *, len + 1);
|
|
|
|
|
|
|
|
|
|
if (retval == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
_dbus_hash_iter_init (activation->entries, &iter);
|
|
|
|
|
i = 0;
|
|
|
|
|
while (_dbus_hash_iter_next (&iter))
|
|
|
|
|
{
|
|
|
|
|
BusActivationEntry *entry = _dbus_hash_iter_get_value (&iter);
|
|
|
|
|
|
|
|
|
|
retval[i] = _dbus_strdup (entry->name);
|
|
|
|
|
if (retval[i] == NULL)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval[i] = NULL;
|
|
|
|
|
|
|
|
|
|
if (array_len)
|
|
|
|
|
*array_len = len;
|
|
|
|
|
|
|
|
|
|
*listp = retval;
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
|
dbus_free (retval[i]);
|
|
|
|
|
dbus_free (retval);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-12 14:07:16 +00:00
|
|
|
#ifdef DBUS_BUILD_TESTS
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#define SERVICE_NAME_1 "MyService1"
|
|
|
|
|
#define SERVICE_NAME_2 "MyService2"
|
|
|
|
|
#define SERVICE_NAME_3 "MyService3"
|
|
|
|
|
|
|
|
|
|
#define SERVICE_FILE_1 "service-1.service"
|
|
|
|
|
#define SERVICE_FILE_2 "service-2.service"
|
|
|
|
|
#define SERVICE_FILE_3 "service-3.service"
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
test_create_service_file (DBusString *dir,
|
2005-07-14 20:44:15 +00:00
|
|
|
const char *filename,
|
|
|
|
|
const char *name,
|
|
|
|
|
const char *exec)
|
2004-03-12 14:07:16 +00:00
|
|
|
{
|
|
|
|
|
DBusString file_name, full_path;
|
|
|
|
|
FILE *file;
|
|
|
|
|
dbus_bool_t ret_val;
|
|
|
|
|
|
|
|
|
|
ret_val = TRUE;
|
|
|
|
|
_dbus_string_init_const (&file_name, filename);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&full_path, _dbus_string_get_const_data (dir)) ||
|
|
|
|
|
!_dbus_concat_dir_and_file (&full_path, &file_name))
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file = fopen (_dbus_string_get_const_data (&full_path), "w");
|
|
|
|
|
if (!file)
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf (file, "[D-BUS Service]\nName=%s\nExec=%s\n", name, exec);
|
|
|
|
|
fclose (file);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return ret_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
test_remove_service_file (DBusString *dir, const char *filename)
|
|
|
|
|
{
|
|
|
|
|
DBusString file_name, full_path;
|
|
|
|
|
dbus_bool_t ret_val;
|
|
|
|
|
|
|
|
|
|
ret_val = TRUE;
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&file_name, filename);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&full_path, _dbus_string_get_const_data (dir)) ||
|
|
|
|
|
!_dbus_concat_dir_and_file (&full_path, &file_name))
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_dbus_delete_file (&full_path, NULL))
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
return ret_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
test_remove_directory (DBusString *dir)
|
|
|
|
|
{
|
|
|
|
|
DBusDirIter *iter;
|
|
|
|
|
DBusString filename, full_path;
|
|
|
|
|
dbus_bool_t ret_val;
|
|
|
|
|
|
|
|
|
|
ret_val = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&filename))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iter = _dbus_directory_open (dir, NULL);
|
|
|
|
|
if (iter == NULL)
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (_dbus_directory_get_next_file (iter, &filename, NULL))
|
|
|
|
|
{
|
|
|
|
|
if (!test_remove_service_file (dir, _dbus_string_get_const_data (&filename)))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
_dbus_directory_close (iter);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_delete_directory (dir, NULL))
|
|
|
|
|
{
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
init_service_reload_test (DBusString *dir)
|
|
|
|
|
{
|
|
|
|
|
DBusStat stat_buf;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_stat (dir, &stat_buf, NULL))
|
|
|
|
|
{
|
|
|
|
|
if (!_dbus_create_directory (dir, NULL))
|
2005-07-14 20:44:15 +00:00
|
|
|
return FALSE;
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!test_remove_directory (dir))
|
2005-07-14 20:44:15 +00:00
|
|
|
return FALSE;
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_create_directory (dir, NULL))
|
2005-07-14 20:44:15 +00:00
|
|
|
return FALSE;
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create one initial file */
|
|
|
|
|
if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_1, "exec-1"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
cleanup_service_reload_test (DBusString *dir)
|
|
|
|
|
{
|
|
|
|
|
if (!test_remove_directory (dir))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
BusActivation *activation;
|
|
|
|
|
const char *service_name;
|
|
|
|
|
dbus_bool_t expecting_find;
|
|
|
|
|
} CheckData;
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
check_func (void *data)
|
|
|
|
|
{
|
|
|
|
|
CheckData *d;
|
|
|
|
|
BusActivationEntry *entry;
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_bool_t ret_val;
|
|
|
|
|
|
|
|
|
|
ret_val = TRUE;
|
|
|
|
|
d = data;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
entry = activation_find_entry (d->activation, d->service_name, &error);
|
|
|
|
|
if (entry == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
ret_val = TRUE;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
else
|
2005-07-14 20:44:15 +00:00
|
|
|
{
|
|
|
|
|
if (d->expecting_find)
|
|
|
|
|
ret_val = FALSE;
|
|
|
|
|
}
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!d->expecting_find)
|
2005-07-14 20:44:15 +00:00
|
|
|
ret_val = FALSE;
|
2004-03-12 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
do_test (const char *description, dbus_bool_t oom_test, CheckData *data)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t err;
|
|
|
|
|
|
|
|
|
|
if (oom_test)
|
|
|
|
|
err = !_dbus_test_oom_handling (description, check_func, data);
|
|
|
|
|
else
|
|
|
|
|
err = !check_func (data);
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
_dbus_assert_not_reached ("Test failed");
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
do_service_reload_test (DBusString *dir, dbus_bool_t oom_test)
|
|
|
|
|
{
|
|
|
|
|
BusActivation *activation;
|
|
|
|
|
DBusString address;
|
|
|
|
|
DBusList *directories;
|
|
|
|
|
CheckData d;
|
|
|
|
|
|
|
|
|
|
directories = NULL;
|
|
|
|
|
_dbus_string_init_const (&address, "");
|
|
|
|
|
|
|
|
|
|
if (!_dbus_list_append (&directories, _dbus_string_get_data (dir)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
activation = bus_activation_new (NULL, &address, &directories, NULL);
|
|
|
|
|
if (!activation)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d.activation = activation;
|
|
|
|
|
|
|
|
|
|
/* Check for existing service file */
|
|
|
|
|
d.expecting_find = TRUE;
|
|
|
|
|
d.service_name = SERVICE_NAME_1;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Existing service file", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check for non-existing service file */
|
|
|
|
|
d.expecting_find = FALSE;
|
|
|
|
|
d.service_name = SERVICE_NAME_3;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Nonexisting service file", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check for added service file */
|
|
|
|
|
if (!test_create_service_file (dir, SERVICE_FILE_2, SERVICE_NAME_2, "exec-2"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d.expecting_find = TRUE;
|
|
|
|
|
d.service_name = SERVICE_NAME_2;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Added service file", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check for removed service file */
|
|
|
|
|
if (!test_remove_service_file (dir, SERVICE_FILE_2))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d.expecting_find = FALSE;
|
|
|
|
|
d.service_name = SERVICE_FILE_2;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Removed service file", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check for updated service file */
|
|
|
|
|
|
|
|
|
|
_dbus_sleep_milliseconds (1000); /* Sleep a second to make sure the mtime is updated */
|
|
|
|
|
|
|
|
|
|
if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_3, "exec-3"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d.expecting_find = TRUE;
|
|
|
|
|
d.service_name = SERVICE_NAME_3;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Updated service file, part 1", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
d.expecting_find = FALSE;
|
|
|
|
|
d.service_name = SERVICE_NAME_1;
|
|
|
|
|
|
|
|
|
|
if (!do_test ("Updated service file, part 2", oom_test, &d))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
bus_activation_unref (activation);
|
|
|
|
|
_dbus_list_clear (&directories);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_activation_service_reload_test (const DBusString *test_data_dir)
|
|
|
|
|
{
|
|
|
|
|
DBusString directory;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&directory))
|
|
|
|
|
return FALSE;
|
2006-08-10 20:09:43 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&directory, _dbus_get_tmpdir()))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (&directory, "/dbus-reload-test-") ||
|
2004-03-12 14:07:16 +00:00
|
|
|
!_dbus_generate_random_ascii (&directory, 6))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do normal tests */
|
|
|
|
|
if (!init_service_reload_test (&directory))
|
|
|
|
|
_dbus_assert_not_reached ("could not initiate service reload test");
|
|
|
|
|
|
2005-09-06 22:38:54 +00:00
|
|
|
if (!do_service_reload_test (&directory, FALSE))
|
|
|
|
|
; /* Do nothing? */
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
/* Do OOM tests */
|
|
|
|
|
if (!init_service_reload_test (&directory))
|
|
|
|
|
_dbus_assert_not_reached ("could not initiate service reload test");
|
|
|
|
|
|
2005-09-06 22:38:54 +00:00
|
|
|
if (!do_service_reload_test (&directory, TRUE))
|
|
|
|
|
; /* Do nothing? */
|
2004-03-12 14:07:16 +00:00
|
|
|
|
|
|
|
|
/* Cleanup test directory */
|
|
|
|
|
if (!cleanup_service_reload_test (&directory))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&directory);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* DBUS_BUILD_TESTS */
|