summaryrefslogtreecommitdiff
path: root/dbus
diff options
context:
space:
mode:
authorRadoslaw Pajak <r.pajak@samsung.com>2013-10-02 14:38:17 +0200
committerLubomir Rintel <lkundrak@v3.sk>2015-02-11 11:50:01 +0100
commit66a6d36b3e88a3427da51cbfcbc8c86c51df016a (patch)
treeb8fb1aecaf359a640ac42256cbda6e27e818f38a /dbus
parent5e4340ec94e9963f2f2d2d27095b026883a6916f (diff)
[daemon-dev][daemon-fix] starting services by direct message (autostart) and some fixes
- added auto starting services (by directly addressed message) - daemon starts the service and then pass a pending message to it this needs appropiriate kdbus changes - KDBUS_NAME_STARTER must be handled by kdbus (since 02.10.2013) - fixes for name aquiring and releasing Change-Id: Ied7746233132a9ab3bd3377fb563c85558486650 Signed-off-by: Radoslaw Pajak <r.pajak@samsung.com>
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-connection.c41
-rw-r--r--dbus/dbus-connection.h2
-rw-r--r--dbus/dbus-transport-kdbus.c35
-rw-r--r--dbus/kdbus-common.c2
-rw-r--r--dbus/kdbus.h2
5 files changed, 57 insertions, 25 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 7f81c740..b1f04b4f 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -2729,12 +2729,8 @@ free_outgoing_message (void *element,
dbus_message_unref (message);
}
-/* This is run without the mutex held, but after the last reference
- * to the connection has been dropped we should have no thread-related
- * problems
- */
static void
-_dbus_connection_last_unref (DBusConnection *connection)
+_dbus_connection_last_unref_internal (DBusConnection *connection, dbus_bool_t unref_transport)
{
DBusList *link;
@@ -2789,17 +2785,18 @@ _dbus_connection_last_unref (DBusConnection *connection)
_dbus_list_foreach (&connection->outgoing_messages,
free_outgoing_message,
- connection);
+ connection);
_dbus_list_clear (&connection->outgoing_messages);
_dbus_list_foreach (&connection->incoming_messages,
- (DBusForeachFunction) dbus_message_unref,
- NULL);
+ (DBusForeachFunction) dbus_message_unref,
+ NULL);
_dbus_list_clear (&connection->incoming_messages);
_dbus_counter_unref (connection->outgoing_counter);
- _dbus_transport_unref (connection->transport);
+ if(unref_transport)
+ _dbus_transport_unref (connection->transport);
if (connection->disconnect_message_link)
{
@@ -2821,6 +2818,16 @@ _dbus_connection_last_unref (DBusConnection *connection)
dbus_free (connection);
}
+/* This is run without the mutex held, but after the last reference
+ * to the connection has been dropped we should have no thread-related
+ * problems
+ */
+static void
+_dbus_connection_last_unref (DBusConnection *connection)
+{
+ _dbus_connection_last_unref_internal(connection, TRUE);
+}
+
/**
* Decrements the reference count of a DBusConnection, and finalizes
* it if the count reaches zero.
@@ -2869,6 +2876,22 @@ dbus_connection_unref (DBusConnection *connection)
}
}
+void
+dbus_connection_unref_phantom (DBusConnection *connection)
+{
+ dbus_int32_t old_refcount;
+
+ _dbus_return_if_fail (connection != NULL);
+ _dbus_return_if_fail (connection->generation == _dbus_current_generation);
+
+ old_refcount = _dbus_atomic_dec (&connection->refcount);
+
+ _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1, "unref");
+
+ if (old_refcount == 1)
+ _dbus_connection_last_unref_internal(connection, FALSE);
+}
+
/*
* Note that the transport can disconnect itself (other end drops us)
* and in that case this function never runs. So this function must
diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h
index d2239548..a3afb93a 100644
--- a/dbus/dbus-connection.h
+++ b/dbus/dbus-connection.h
@@ -185,6 +185,8 @@ DBusConnection* dbus_connection_ref (DBusConnection
DBUS_EXPORT
void dbus_connection_unref (DBusConnection *connection);
DBUS_EXPORT
+void dbus_connection_unref_phantom (DBusConnection *connection);
+DBUS_EXPORT
void dbus_connection_close (DBusConnection *connection);
DBUS_EXPORT
dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);
diff --git a/dbus/dbus-transport-kdbus.c b/dbus/dbus-transport-kdbus.c
index a7b44777..6a332417 100644
--- a/dbus/dbus-transport-kdbus.c
+++ b/dbus/dbus-transport-kdbus.c
@@ -33,8 +33,6 @@
#include <sys/stat.h>
#include <openssl/md5.h>
-//todo documentation need to be corrected
-
#define KDBUS_PART_FOREACH(part, head, first) \
for (part = (head)->first; \
(uint8_t *)(part) < (uint8_t *)(head) + (head)->size; \
@@ -172,7 +170,7 @@ static int reply_1_data(DBusMessage *message, int data_type, void* pData, DBusCo
return -1;
}
-/*todo uncomment if needed
+/*
static int reply_ack(DBusMessage *message, DBusConnection* connection)
{
DBusMessage *reply;
@@ -410,18 +408,21 @@ static int kdbus_write_msg(DBusTransportSocket *transport, DBusMessage *message,
{
if(errno == EINTR)
goto again;
- if((errno == ESRCH) || (errno == ENXIO) || (errno = EADDRNOTAVAIL)) //when recipient is not available on the bus
+ else if(errno == ENXIO) //no such id on the bus
+ {
+ if(!reply_with_error(DBUS_ERROR_NAME_HAS_NO_OWNER, "Name \"%s\" does not exist", dbus_message_get_destination(message), message, transport->base.connection))
+ goto out;
+ }
+ else if((errno == ESRCH) || (errno = EADDRNOTAVAIL)) //when well known name is not available on the bus
{
if(autostart)
{
- //todo start service here, otherwise
if(!reply_with_error(DBUS_ERROR_SERVICE_UNKNOWN, "The name %s was not provided by any .service files", dbus_message_get_destination(message), message, transport->base.connection))
goto out;
}
else
- if(!reply_with_error(DBUS_ERROR_NAME_HAS_NO_OWNER, "Name \"%s\" does not exist", dbus_message_get_destination(message), message, transport->base.connection))
- goto out;
-
+ if(!reply_with_error(DBUS_ERROR_NAME_HAS_NO_OWNER, "Name \"%s\" does not exist", dbus_message_get_destination(message), message, transport->base.connection))
+ goto out;
}
_dbus_verbose("kdbus error sending message: err %d (%m)\n", errno);
ret_size = -1;
@@ -834,7 +835,7 @@ static int emulateOrgFreedesktopDBus(DBusTransport *transport, DBusMessage *mess
((DBusTransportSocket*)transport)->sender = sender;
if(!reply_1_data(message, DBUS_TYPE_STRING, &name, transport->connection))
- return 0; //todo why we cannot free name after sending reply?
+ return 0; //todo why we cannot free name after sending reply, shouldn't we?
else
free(sender);
@@ -1066,7 +1067,7 @@ out:
return ret_value;
}
#endif
-/* else if(!strcmp(dbus_message_get_member(message), "GetAdtAuditSessionData")) //todo to be implemented
+/* else if(!strcmp(dbus_message_get_member(message), "GetAdtAuditSessionData")) //todo to be implemented if needed and possible
{
char* name = NULL;
@@ -1102,7 +1103,6 @@ out:
#endif
else
return 1; //send to daemon
-// return reply_with_error(DBUS_ERROR_UNKNOWN_METHOD, NULL, (char*)dbus_message_get_member(message), message, transport->connection);
#ifdef DBUS_SERVICES_IN_LIB
if(info.sec_label)
@@ -2106,9 +2106,12 @@ do_writing (DBusTransport *transport)
message = _dbus_connection_get_message_to_send (transport->connection);
_dbus_assert (message != NULL);
- dbus_message_unlock(message);
- dbus_message_set_sender(message, socket_transport->sender);
- dbus_message_lock (message);
+ if(dbus_message_get_sender(message) == NULL) //needed for daemon
+ {
+ dbus_message_unlock(message);
+ dbus_message_set_sender(message, socket_transport->sender);
+ dbus_message_lock (message);
+ }
_dbus_message_get_network_data (message, &header, &body);
total_bytes_to_write = _dbus_string_get_length(header) + _dbus_string_get_length(body);
pDestination = dbus_message_get_destination(message);
@@ -2473,7 +2476,7 @@ kdbus_connection_set (DBusTransport *transport)
{
DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
- dbus_connection_set_is_authenticated(transport->connection); //todo remove when authentication will work
+ dbus_connection_set_is_authenticated(transport->connection); //now we don't have authentication in kdbus
_dbus_watch_set_handler (socket_transport->write_watch,
_dbus_connection_handle_watch,
@@ -2501,7 +2504,7 @@ kdbus_connection_set (DBusTransport *transport)
return TRUE;
}
-/**
+/** original dbus copy-pasted
* @todo We need to have a way to wake up the select sleep if
* a new iteration request comes in with a flag (read/write) that
* we're not currently serving. Otherwise a call that just reads
diff --git a/dbus/kdbus-common.c b/dbus/kdbus-common.c
index 0c967499..fe04a2ec 100644
--- a/dbus/kdbus-common.c
+++ b/dbus/kdbus-common.c
@@ -224,6 +224,8 @@ int request_kdbus_name(int fd, const char *name, const __u64 flags, __u64 id)
flags_kdbus |= KDBUS_NAME_QUEUE;
if(flags & DBUS_NAME_FLAG_REPLACE_EXISTING)
flags_kdbus |= KDBUS_NAME_REPLACE_EXISTING;
+ if(flags & KDBUS_NAME_STARTER)
+ flags_kdbus |= KDBUS_NAME_STARTER;
cmd_name->flags = flags_kdbus;
cmd_name->id = id;
diff --git a/dbus/kdbus.h b/dbus/kdbus.h
index 368cec3f..4e4c2cb3 100644
--- a/dbus/kdbus.h
+++ b/dbus/kdbus.h
@@ -343,6 +343,8 @@ enum {
KDBUS_NAME_QUEUE = 1 << 1,
KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 2,
+ KDBUS_NAME_STARTER = 1 << 7,
+
/* kernel → userspace */
KDBUS_NAME_IN_QUEUE = 1 << 16,
};