summaryrefslogtreecommitdiff
path: root/src/shared/bus-wait-for-units.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-01 18:54:59 +0200
committerLennart Poettering <lennart@poettering.net>2019-07-11 12:18:51 +0200
commit3572d3df8f822d4cf1601428401a837f723771cf (patch)
tree0ee1dd4c8767f15aac59ba9f5795f3f65b89f300 /src/shared/bus-wait-for-units.h
parent345f3221856e41880923c88cf853361025999f8b (diff)
downloadsystemd-3572d3df8f822d4cf1601428401a837f723771cf.tar.gz
shared: add generic logic for waiting for a unit to enter some state
This is a generic implementation of a client-side logic of waiting until a unit enters or leaves some state. This is a more generic implementation of the WaitContext logic currently in systemctl.c, and is supposed to replace it (a later commit does this). It's similar to bus-wait-for-jobs.c and we probably should fold that one into it later on. This code is more powerful and cleaner than the WaitContext logic however. In addition to waiting for a unit to exit this also allows us to wait for a unit to leave the "maintainance" state. This commit only implements the generic logic, and adds no users of it yet.
Diffstat (limited to 'src/shared/bus-wait-for-units.h')
-rw-r--r--src/shared/bus-wait-for-units.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/shared/bus-wait-for-units.h b/src/shared/bus-wait-for-units.h
new file mode 100644
index 0000000000..a20f3d8fd7
--- /dev/null
+++ b/src/shared/bus-wait-for-units.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include "macro.h"
+#include "sd-bus.h"
+
+typedef struct BusWaitForUnits BusWaitForUnits;
+
+typedef enum BusWaitForUnitsState {
+ BUS_WAIT_SUCCESS, /* Nothing to wait for anymore and nothing failed */
+ BUS_WAIT_FAILURE, /* dito, but something failed */
+ BUS_WAIT_RUNNING, /* Still something to wait for */
+ _BUS_WAIT_FOR_UNITS_STATE_MAX,
+ _BUS_WAIT_FOR_UNITS_STATE_INVALID = -1,
+} BusWaitForUnitsState;
+
+typedef enum BusWaitForUnitsFlags {
+ BUS_WAIT_FOR_MAINTENANCE_END = 1 << 0, /* Wait until the unit is no longer in maintenance state */
+ BUS_WAIT_FOR_INACTIVE = 1 << 1, /* Wait until the unit is back in inactive or dead state */
+ BUS_WAIT_NO_JOB = 1 << 2, /* Wait until there's no more job pending */
+ BUS_WAIT_REFFED = 1 << 3, /* The unit is already reffed with RefUnit() */
+} BusWaitForUnitsFlags;
+
+typedef void (*bus_wait_for_units_ready_callback)(BusWaitForUnits *d, BusWaitForUnitsState state, void *userdata);
+typedef void (*bus_wait_for_units_unit_callback)(BusWaitForUnits *d, const char *unit_path, bool good, void *userdata);
+
+int bus_wait_for_units_new(sd_bus *bus, BusWaitForUnits **ret);
+BusWaitForUnits* bus_wait_for_units_free(BusWaitForUnits *d);
+
+BusWaitForUnitsState bus_wait_for_units_state(BusWaitForUnits *d);
+void bus_wait_for_units_set_ready_callback(BusWaitForUnits *d, bus_wait_for_units_ready_callback callback, void *userdata);
+int bus_wait_for_units_add_unit(BusWaitForUnits *d, const char *unit, BusWaitForUnitsFlags flags, bus_wait_for_units_unit_callback callback, void *userdata);
+int bus_wait_for_units_run(BusWaitForUnits *d);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForUnits*, bus_wait_for_units_free);