From f8b04951b4ccafdf28b875825edd46316fafb519 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 18 Dec 2018 10:58:25 +0100 Subject: afm-unit: Fix http port multi allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When serveral targets were set in the widget file, the framework allocated the same HTTP port to each. This lead to impossibility to run all targets or to a systemd conflict. This should fix the issue by allocating an HTTP port for each target installed by the widget. To achieves that goal, the afm-unit.conf tag for the port is moved from '#metadata.http-port' to '#metatarget.http-port'. Bug-AGL: SPEC-2068 Change-Id: I5376d6f052e0ffc5c77cc80041528637777aed1e Signed-off-by: José Bollo --- src/tests/test-unit/test-unit.c | 8 +++++++- src/wgtpkg-install.c | 8 ++------ src/wgtpkg-mustach.c | 2 +- src/wgtpkg-unit.c | 22 ++++++++++++++++++---- src/wgtpkg-unit.h | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/tests/test-unit/test-unit.c b/src/tests/test-unit/test-unit.c index 2b166e9..347135a 100644 --- a/src/tests/test-unit/test-unit.c +++ b/src/tests/test-unit/test-unit.c @@ -65,6 +65,12 @@ puts(json_object_to_json_string_ext(desc->desc, JSON_C_TO_STRING_PRETTY)); return 0; } +static int port() +{ + static int r = 10000; + return r++; +} + int main(int ac, char **av) { struct unitconf conf; @@ -73,7 +79,7 @@ int main(int ac, char **av) conf.installdir = "INSTALL-DIR"; conf.icondir = "ICONS-DIR"; - conf.port = 666; + conf.port = port; rc = unit_generator_open_template(*++av); if (rc < 0) error("can't read template %s: %m",*av); diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c index c5c41ea..8d59b37 100644 --- a/src/wgtpkg-install.c +++ b/src/wgtpkg-install.c @@ -541,7 +541,7 @@ struct wgt_info *install_widget(const char *wgtfile, const char *root, int force struct wgt_info *ifo; const struct wgt_desc *desc; char installdir[PATH_MAX]; - int port, err; + int err; struct unitconf uconf; NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root); @@ -596,13 +596,9 @@ struct wgt_info *install_widget(const char *wgtfile, const char *root, int force if (install_file_properties(desc)) goto error4; - port = get_port(); - if (port < 0) - goto error4; - uconf.installdir = installdir; uconf.icondir = FWK_ICON_DIR; - uconf.port = port; + uconf.port = get_port; if (unit_install(ifo, &uconf)) goto error4; diff --git a/src/wgtpkg-mustach.c b/src/wgtpkg-mustach.c index 4251427..5e4348a 100644 --- a/src/wgtpkg-mustach.c +++ b/src/wgtpkg-mustach.c @@ -31,7 +31,7 @@ #define MAX_DEPTH 256 /* - * exploration state when instanciating mustache + * exploration state when instantiating mustache */ struct expl { struct json_object *root; diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index 89d1473..cca718f 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -28,7 +28,7 @@ #include #include - + #include "verbose.h" #include "utils-file.h" @@ -38,6 +38,7 @@ #include "utils-systemd.h" #include "wgtpkg-unit.h" +#include "wgt-strings.h" #if 0 #include @@ -54,7 +55,7 @@ static char *template; * When returning 1 and 'after' isn't NULL, the pointer to the * first character after the pettern in 'text' is stored in 'after'. * The characters '\n' and ' ' have a special meaning in the search: - * * '\n': matches any space or tabs (including none) followed + * * '\n': matches any space or tabs (including none) followed * either by '\n' or '\0' (end of the string) * * ' ': matches any space or tabs but at least one. */ @@ -373,13 +374,26 @@ int unit_generator_open_template(const char *filename) static int add_metadata(struct json_object *jdesc, const struct unitconf *conf) { + struct json_object *targets, *targ; char portstr[30]; + int port, i, n; + + if (json_object_object_get_ex(jdesc, string_targets, &targets)) { + n = json_object_array_length(targets); + for (i = 0 ; i < n ; i++) { + targ = json_object_array_get_idx(targets, i); + port = conf->port(); + if (port < 0) + return port; + sprintf(portstr, "%d", port); + if (!j_add_string_m(targ, "#metatarget.http-port", portstr)) + return -1; + } + } - sprintf(portstr, "%d", conf->port); return j_add_many_strings_m(jdesc, "#metadata.install-dir", conf->installdir, "#metadata.icons-dir", conf->icondir, - "#metadata.http-port", portstr, NULL) ? 0 : -1; } diff --git a/src/wgtpkg-unit.h b/src/wgtpkg-unit.h index 7330365..fc91204 100644 --- a/src/wgtpkg-unit.h +++ b/src/wgtpkg-unit.h @@ -47,7 +47,7 @@ struct unitdesc { struct unitconf { const char *installdir; const char *icondir; - int port; + int (*port)(); }; struct generatedesc { -- cgit 1.2.3-korg