aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils-systemd.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-03-15 11:49:29 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-03-17 13:01:40 +0100
commitfb0f81a1d8b5369842269fa1bdb9ad8d52882491 (patch)
treece78a61d1c9fdb46be72c6f0e0657e4a6c0abbdd /src/utils-systemd.c
parent2a8b46d16ea5d0c99831e95b47cab037f220f7af (diff)
Emits reload to systemd when needed
The current implementation enforce the reload when a 'wants' target is created or deleted. This should work well for system units. However, for system units, this behaviour isn't enought when more that a user is active because only the user that installs the application will be updated. For this reason, a paralelle mechanism has to be defined. Also note that systemd is henceforth required for tools because wgtpkg-installer needs it now. Change-Id: I4fc03a44dbc58c2374ea21dbf6b436f646d04e00 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/utils-systemd.c')
-rw-r--r--src/utils-systemd.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils-systemd.c b/src/utils-systemd.c
index 757a52c..48fb3d8 100644
--- a/src/utils-systemd.c
+++ b/src/utils-systemd.c
@@ -33,6 +33,35 @@
# define SYSTEMD_UNITS_ROOT "/usr/local/lib/systemd"
#endif
+static const char sdb_path[] = "/org/freedesktop/systemd1";
+static const char sdb_destination[] = "org.freedesktop.systemd1";
+static const char sdbi_manager[] = "org.freedesktop.systemd1.Manager";
+static const char sdbm_reload[] = "Reload";
+
+static struct sd_bus *sysbus;
+static struct sd_bus *usrbus;
+
+static int get_bus(int isuser, struct sd_bus **ret)
+{
+ int rc;
+ struct sd_bus *bus;
+
+ bus = isuser ? usrbus : sysbus;
+ if (bus) {
+ *ret = bus;
+ rc = 0;
+ } else if (isuser) {
+ rc = sd_bus_open_user(ret);
+ if (!rc)
+ usrbus = *ret;
+ } else {
+ rc = sd_bus_open_system(ret);
+ if (!rc)
+ sysbus = *ret;
+ }
+ return rc;
+}
+
int systemd_get_unit_path(char *path, size_t pathlen, int isuser, const char *unit, const char *uext)
{
int rc = snprintf(path, pathlen, "%s/%s/%s.%s",
@@ -75,3 +104,15 @@ int systemd_get_wants_target(char *path, size_t pathlen, const char *unit, const
return rc;
}
+int systemd_daemon_reload(int isuser)
+{
+ int rc;
+ struct sd_bus *bus;
+
+ rc = get_bus(isuser, &bus);
+ if (!rc) {
+ rc = sd_bus_call_method(bus, sdb_destination, sdb_path, sdbi_manager, sdbm_reload, NULL, NULL, NULL);
+ }
+ return rc;
+}
+