diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-03-15 11:49:29 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-03-17 13:01:40 +0100 |
commit | fb0f81a1d8b5369842269fa1bdb9ad8d52882491 (patch) | |
tree | ce78a61d1c9fdb46be72c6f0e0657e4a6c0abbdd /src/wgtpkg-unit.c | |
parent | 2a8b46d16ea5d0c99831e95b47cab037f220f7af (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/wgtpkg-unit.c')
-rw-r--r-- | src/wgtpkg-unit.c | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index f141766..48cf3bb 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -419,28 +419,63 @@ static int get_wants_target(char *path, size_t pathlen, const struct unitdesc *d return rc; } +static int do_send_reload(const struct unitdesc descs[], unsigned count) +{ + unsigned i; + int reloadsys, reloadusr; + + reloadsys = reloadusr = 0; + for (i = 0 ; i < count ; i++) { + if (descs[i].wanted_by != NULL) { + switch (descs[i].scope) { + case unitscope_user: + reloadusr = 1; + break; + case unitscope_system: + reloadsys = 1; + break; + default: + break; + } + } + } + + if (reloadusr) + reloadusr = systemd_daemon_reload(1); + if (reloadsys) + reloadsys = systemd_daemon_reload(0); + return reloadsys ? : reloadusr ? : 0; +} + static int do_uninstall_units(void *closure, const struct unitdesc descs[], unsigned count) { int rc, rc2; unsigned i; char path[PATH_MAX]; + rc = 0; for (i = 0 ; i < count ; i++) { - rc = check_unit_desc(&descs[i], 0); - if (rc == 0) { - rc = get_unit_path(path, sizeof path, &descs[i]); - if (rc >= 0) { - rc = unlink(path); + rc2 = check_unit_desc(&descs[i], 0); + if (rc2 == 0) { + rc2 = get_unit_path(path, sizeof path, &descs[i]); + if (rc2 >= 0) { + rc2 = unlink(path); } + if (rc2 < 0 && rc == 0) + rc = rc2; if (descs[i].wanted_by != NULL) { rc2 = get_wants_path(path, sizeof path, &descs[i]); if (rc2 >= 0) rc2 = unlink(path); - rc = rc < 0 ? rc : rc2; } } + if (rc2 < 0 && rc == 0) + rc = rc2; } - return 0; + rc2 = do_send_reload(descs, count); + if (rc2 < 0 && rc == 0) + rc = rc2; + return rc; } static int do_install_units(void *closure, const struct unitdesc descs[], unsigned count) @@ -469,12 +504,16 @@ static int do_install_units(void *closure, const struct unitdesc descs[], unsign i++; } } - if (rc < 0) { - do_uninstall_units(closure, descs, i); - return rc; - } + if (rc < 0) + goto error; } + rc = do_send_reload(descs, count); + if (rc < 0) + goto error; return 0; +error: + do_uninstall_units(closure, descs, i); + return rc; } static int add_metadata(struct json_object *jdesc, const char *installdir, const char *icondir, int port) |