chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dbus: don't try to run AddMatch when connected to a private bus
[elogind.git]
/
src
/
dbus-unit.c
diff --git
a/src/dbus-unit.c
b/src/dbus-unit.c
index e3e1be12ade2be09393e0198ca85ac57eda43096..63301a08243d6025ed2f8afb7e808d2f21ba262b 100644
(file)
--- a/
src/dbus-unit.c
+++ b/
src/dbus-unit.c
@@
-25,6
+25,8
@@
#include "log.h"
#include "dbus-unit.h"
#include "log.h"
#include "dbus-unit.h"
+const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
+
int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
char *t;
Iterator j;
int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
char *t;
Iterator j;
@@
-253,11
+255,12
@@
int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_kill_mode, kill_mode, KillMode);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_kill_mode, kill_mode, KillMode);
-static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message) {
+static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBus
Connection *connection, DBus
Message *message) {
DBusMessage *reply = NULL;
Manager *m = u->meta.manager;
DBusError error;
JobType job_type = _JOB_TYPE_INVALID;
DBusMessage *reply = NULL;
Manager *m = u->meta.manager;
DBusError error;
JobType job_type = _JOB_TYPE_INVALID;
+ char *path = NULL;
dbus_error_init(&error);
dbus_error_init(&error);
@@
-269,8
+272,10
@@
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
job_type = JOB_RELOAD;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart"))
job_type = JOB_RESTART;
job_type = JOB_RELOAD;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart"))
job_type = JOB_RESTART;
+ else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "TryRestart"))
+ job_type = JOB_TRY_RESTART;
else if (UNIT_VTABLE(u)->bus_message_handler)
else if (UNIT_VTABLE(u)->bus_message_handler)
- return UNIT_VTABLE(u)->bus_message_handler(u, message);
+ return UNIT_VTABLE(u)->bus_message_handler(u,
connection,
message);
else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@
-279,20
+284,22
@@
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
JobMode mode;
Job *j;
int r;
JobMode mode;
Job *j;
int r;
- char *path;
+
+ if (job_type == JOB_START && u->meta.only_by_dependency)
+ return bus_send_error_reply(m, connection, message, NULL, -EPERM);
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, message, &error, -EINVAL);
+ return bus_send_error_reply(m,
connection,
message, &error, -EINVAL);
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, message, NULL, -EINVAL);
+ return bus_send_error_reply(m,
connection,
message, NULL, -EINVAL);
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m,
connection,
message, NULL, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
@@
-307,8
+314,10
@@
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
goto oom;
}
goto oom;
}
+ free(path);
+
if (reply) {
if (reply) {
- if (!dbus_connection_send(
m->api_bus
, reply, NULL))
+ if (!dbus_connection_send(
connection
, reply, NULL))
goto oom;
dbus_message_unref(reply);
goto oom;
dbus_message_unref(reply);
@@
-317,6
+326,8
@@
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
return DBUS_HANDLER_RESULT_HANDLED;
oom:
return DBUS_HANDLER_RESULT_HANDLED;
oom:
+ free(path);
+
if (reply)
dbus_message_unref(reply);
if (reply)
dbus_message_unref(reply);
@@
-325,7
+336,7
@@
oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
-static DBusHandlerResult bus_unit_message_handler(DBusConnection
*connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
Unit *u;
int r;
Manager *m = data;
Unit *u;
int r;
@@
-347,10
+358,10
@@
static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, D
if (r == -ENOENT)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
if (r == -ENOENT)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- return bus_send_error_reply(m, message, NULL, r);
+ return bus_send_error_reply(m,
connection,
message, NULL, r);
}
}
- return bus_unit_message_dispatch(u, message);
+ return bus_unit_message_dispatch(u,
connection,
message);
}
const DBusObjectPathVTable bus_unit_vtable = {
}
const DBusObjectPathVTable bus_unit_vtable = {
@@
-367,7
+378,7
@@
void bus_unit_send_change_signal(Unit *u) {
LIST_REMOVE(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
u->meta.in_dbus_queue = false;
LIST_REMOVE(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
u->meta.in_dbus_queue = false;
- if (
set_isempty(u->meta.manager->subscribed
)) {
+ if (
!bus_has_subscriber(u->meta.manager
)) {
u->meta.sent_dbus_new_signal = true;
return;
}
u->meta.sent_dbus_new_signal = true;
return;
}
@@
-393,7
+404,7
@@
void bus_unit_send_change_signal(Unit *u) {
goto oom;
}
goto oom;
}
- if (
!dbus_connection_send(u->meta.manager->api_bus, m, NULL)
)
+ if (
bus_broadcast(u->meta.manager, m) < 0
)
goto oom;
free(p);
goto oom;
free(p);
@@
-418,9
+429,12
@@
void bus_unit_send_removed_signal(Unit *u) {
assert(u);
assert(u);
- if (
set_isempty(u->meta.manager->subscribed) || !u->meta.sent_dbus_new_signal
)
+ if (
!bus_has_subscriber(u->meta.manager)
)
return;
return;
+ if (!u->meta.sent_dbus_new_signal)
+ bus_unit_send_change_signal(u);
+
if (!(p = unit_dbus_path(u)))
goto oom;
if (!(p = unit_dbus_path(u)))
goto oom;
@@
-433,7
+447,7
@@
void bus_unit_send_removed_signal(Unit *u) {
DBUS_TYPE_INVALID))
goto oom;
DBUS_TYPE_INVALID))
goto oom;
- if (
!dbus_connection_send(u->meta.manager->api_bus, m, NULL)
)
+ if (
bus_broadcast(u->meta.manager, m) < 0
)
goto oom;
free(p);
goto oom;
free(p);