X Tutup
Skip to content

Commit 2d479ff

Browse files
authored
Merge pull request systemd#10963 from poettering/bus-force-state-change-signal
force PropertiesChanged bus signal on all unit state changes
2 parents 6dce3bb + db3cea2 commit 2d479ff

File tree

19 files changed

+159
-28
lines changed

19 files changed

+159
-28
lines changed

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Janitorial Clean-ups:
2323

2424
Features:
2525

26+
* when importing an fs tree with machined, optionally apply userns-rec-chown
27+
28+
* when importing an fs tree with machined, complain if image is not an OS
29+
2630
* when we fork off generators and such, lower LIMIT_NOFILE soft limit to 1K
2731

2832
* rework seccomp/nnp logic that that even if User= is used in combination with

src/core/automount.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "bus-error.h"
1717
#include "bus-util.h"
1818
#include "dbus-automount.h"
19+
#include "dbus-unit.h"
1920
#include "fd-util.h"
2021
#include "format-util.h"
2122
#include "io-util.h"
@@ -237,6 +238,9 @@ static void automount_set_state(Automount *a, AutomountState state) {
237238
AutomountState old_state;
238239
assert(a);
239240

241+
if (a->state != state)
242+
bus_unit_send_pending_change_signal(UNIT(a), false);
243+
240244
old_state = a->state;
241245
a->state = state;
242246

src/core/dbus-job.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "alloc-util.h"
66
#include "dbus-job.h"
7+
#include "dbus-unit.h"
78
#include "dbus.h"
89
#include "job.h"
910
#include "log.h"
@@ -173,6 +174,9 @@ void bus_job_send_change_signal(Job *j) {
173174

174175
assert(j);
175176

177+
/* Make sure that any change signal on the unit is reflected before we send out the change signal on the job */
178+
bus_unit_send_pending_change_signal(j->unit, true);
179+
176180
if (j->in_dbus_queue) {
177181
LIST_REMOVE(dbus_queue, j->manager->dbus_job_queue, j);
178182
j->in_dbus_queue = false;
@@ -185,6 +189,21 @@ void bus_job_send_change_signal(Job *j) {
185189
j->sent_dbus_new_signal = true;
186190
}
187191

192+
void bus_job_send_pending_change_signal(Job *j, bool including_new) {
193+
assert(j);
194+
195+
if (!j->in_dbus_queue)
196+
return;
197+
198+
if (!j->sent_dbus_new_signal && !including_new)
199+
return;
200+
201+
if (MANAGER_IS_RELOADING(j->unit->manager))
202+
return;
203+
204+
bus_job_send_change_signal(j);
205+
}
206+
188207
static int send_removed_signal(sd_bus *bus, void *userdata) {
189208
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
190209
_cleanup_free_ char *p = NULL;
@@ -222,6 +241,9 @@ void bus_job_send_removed_signal(Job *j) {
222241
if (!j->sent_dbus_new_signal)
223242
bus_job_send_change_signal(j);
224243

244+
/* Make sure that any change signal on the unit is reflected before we send out the change signal on the job */
245+
bus_unit_send_pending_change_signal(j->unit, true);
246+
225247
r = bus_foreach_bus(j->manager, j->bus_track, send_removed_signal, j);
226248
if (r < 0)
227249
log_debug_errno(r, "Failed to send job remove signal for %u: %m", j->id);

src/core/dbus-job.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int bus_job_method_cancel(sd_bus_message *message, void *job, sd_bus_error *erro
1212
int bus_job_method_get_waiting_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error);
1313

1414
void bus_job_send_change_signal(Job *j);
15+
void bus_job_send_pending_change_signal(Job *j, bool including_new);
1516
void bus_job_send_removed_signal(Job *j);
1617

1718
int bus_job_coldplug_bus_track(Job *j);

src/core/dbus-unit.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ const sd_bus_vtable bus_unit_vtable[] = {
662662
SD_BUS_PROPERTY("AssertResult", "b", bus_property_get_bool, offsetof(Unit, assert_result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
663663
BUS_PROPERTY_DUAL_TIMESTAMP("ConditionTimestamp", offsetof(Unit, condition_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
664664
BUS_PROPERTY_DUAL_TIMESTAMP("AssertTimestamp", offsetof(Unit, assert_timestamp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
665-
SD_BUS_PROPERTY("Conditions", "a(sbbsi)", property_get_conditions, offsetof(Unit, conditions), 0),
666-
SD_BUS_PROPERTY("Asserts", "a(sbbsi)", property_get_conditions, offsetof(Unit, asserts), 0),
665+
SD_BUS_PROPERTY("Conditions", "a(sbbsi)", property_get_conditions, offsetof(Unit, conditions), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
666+
SD_BUS_PROPERTY("Asserts", "a(sbbsi)", property_get_conditions, offsetof(Unit, asserts), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
667667
SD_BUS_PROPERTY("LoadError", "(ss)", property_get_load_error, 0, SD_BUS_VTABLE_PROPERTY_CONST),
668668
SD_BUS_PROPERTY("Transient", "b", bus_property_get_bool, offsetof(Unit, transient), SD_BUS_VTABLE_PROPERTY_CONST),
669669
SD_BUS_PROPERTY("Perpetual", "b", bus_property_get_bool, offsetof(Unit, perpetual), SD_BUS_VTABLE_PROPERTY_CONST),
@@ -675,8 +675,8 @@ const sd_bus_vtable bus_unit_vtable[] = {
675675
SD_BUS_PROPERTY("SuccessAction", "s", property_get_emergency_action, offsetof(Unit, success_action), SD_BUS_VTABLE_PROPERTY_CONST),
676676
SD_BUS_PROPERTY("SuccessActionExitStatus", "i", bus_property_get_int, offsetof(Unit, success_action_exit_status), SD_BUS_VTABLE_PROPERTY_CONST),
677677
SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST),
678-
SD_BUS_PROPERTY("InvocationID", "ay", bus_property_get_id128, offsetof(Unit, invocation_id), 0),
679-
SD_BUS_PROPERTY("CollectMode", "s", property_get_collect_mode, offsetof(Unit, collect_mode), 0),
678+
SD_BUS_PROPERTY("InvocationID", "ay", bus_property_get_id128, offsetof(Unit, invocation_id), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
679+
SD_BUS_PROPERTY("CollectMode", "s", property_get_collect_mode, offsetof(Unit, collect_mode), SD_BUS_VTABLE_PROPERTY_CONST),
680680
SD_BUS_PROPERTY("Refs", "as", property_get_refs, 0, 0),
681681

682682
SD_BUS_METHOD("Start", "s", "o", method_start, SD_BUS_VTABLE_UNPRIVILEGED),
@@ -1202,6 +1202,27 @@ void bus_unit_send_change_signal(Unit *u) {
12021202
u->sent_dbus_new_signal = true;
12031203
}
12041204

1205+
void bus_unit_send_pending_change_signal(Unit *u, bool including_new) {
1206+
1207+
/* Sends out any pending change signals, but only if they really are pending. This call is used when we are
1208+
* about to change state in order to force out a PropertiesChanged signal beforehand if there was one pending
1209+
* so that clients can follow the full state transition */
1210+
1211+
if (!u->in_dbus_queue) /* If not enqueued, don't bother */
1212+
return;
1213+
1214+
if (!u->sent_dbus_new_signal && !including_new) /* If the unit was never announced, don't bother, it's fine if
1215+
* the unit appears in the new state right-away (except if the
1216+
* caller explicitly asked us to send it anyway) */
1217+
return;
1218+
1219+
if (MANAGER_IS_RELOADING(u->manager)) /* Don't generate unnecessary PropertiesChanged signals for the same unit
1220+
* when we are reloading. */
1221+
return;
1222+
1223+
bus_unit_send_change_signal(u);
1224+
}
1225+
12051226
static int send_removed_signal(sd_bus *bus, void *userdata) {
12061227
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
12071228
_cleanup_free_ char *p = NULL;
@@ -1300,6 +1321,9 @@ int bus_unit_queue_job(
13001321
if (!path)
13011322
return -ENOMEM;
13021323

1324+
/* Before we send the method reply, force out the announcement JobNew for this job */
1325+
bus_job_send_pending_change_signal(j, true);
1326+
13031327
return sd_bus_reply_method_return(message, "o", path);
13041328
}
13051329

src/core/dbus-unit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern const sd_bus_vtable bus_unit_vtable[];
1111
extern const sd_bus_vtable bus_unit_cgroup_vtable[];
1212

1313
void bus_unit_send_change_signal(Unit *u);
14+
void bus_unit_send_pending_change_signal(Unit *u, bool including_new);
1415
void bus_unit_send_removed_signal(Unit *u);
1516

1617
int bus_unit_method_start_generic(sd_bus_message *message, Unit *u, JobType job_type, bool reload_if_possible, sd_bus_error *error);

src/core/device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "alloc-util.h"
77
#include "bus-error.h"
88
#include "dbus-device.h"
9+
#include "dbus-unit.h"
910
#include "device-private.h"
1011
#include "device-util.h"
1112
#include "device.h"
@@ -115,6 +116,9 @@ static void device_set_state(Device *d, DeviceState state) {
115116
DeviceState old_state;
116117
assert(d);
117118

119+
if (d->state != state)
120+
bus_unit_send_pending_change_signal(UNIT(d), false);
121+
118122
old_state = d->state;
119123
d->state = state;
120124

src/core/job.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ Job* job_install(Job *j) {
236236

237237
job_add_to_gc_queue(j);
238238

239+
job_add_to_dbus_queue(j); /* announce this job to clients */
240+
unit_add_to_dbus_queue(j->unit); /* The Job property of the unit has changed now */
241+
239242
return j;
240243
}
241244

src/core/mount.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "alloc-util.h"
1313
#include "dbus-mount.h"
14+
#include "dbus-unit.h"
1415
#include "device.h"
1516
#include "escape.h"
1617
#include "exit-status.h"
@@ -640,6 +641,9 @@ static void mount_set_state(Mount *m, MountState state) {
640641
MountState old_state;
641642
assert(m);
642643

644+
if (m->state != state)
645+
bus_unit_send_pending_change_signal(UNIT(m), false);
646+
643647
old_state = m->state;
644648
m->state = state;
645649

src/core/path.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "bus-error.h"
99
#include "bus-util.h"
1010
#include "dbus-path.h"
11+
#include "dbus-unit.h"
1112
#include "fd-util.h"
1213
#include "fs-util.h"
1314
#include "glob-util.h"
@@ -410,6 +411,9 @@ static void path_set_state(Path *p, PathState state) {
410411
PathState old_state;
411412
assert(p);
412413

414+
if (p->state != state)
415+
bus_unit_send_pending_change_signal(UNIT(p), false);
416+
413417
old_state = p->state;
414418
p->state = state;
415419

0 commit comments

Comments
 (0)
X Tutup