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 <jose.bollo@iot.bzh>
;---- text/html application/vnd.agl.native application/vnd.agl.service ----
;---------------------------------------------------------------------------------
{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}}
;---- text/html application/vnd.agl.native application/vnd.agl.service ----
;---------------------------------------------------------------------------------
{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}}
-X-AFM-http-port={{:#metadata.http-port}}
+X-AFM-http-port={{:#metatarget.http-port}}
Type=notify
ExecStart=/usr/bin/afb-daemon \
--name afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} \
Type=notify
ExecStart=/usr/bin/afb-daemon \
--name afbd-{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} \
--verbose \
--verbose \
--monitoring \
--verbose \
--verbose \
--monitoring \
- --port={{:#metadata.http-port}} \
+ --port={{:#metatarget.http-port}} \
--token=HELLO \
--roothttp={{#content.type=application/vnd.agl.service}}.{{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}}{{#required-permission.urn:AGL:permission::public:no-htdocs}}.{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{^required-permission.urn:AGL:permission::public:no-htdocs}}htdocs{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{/content.type=application/vnd.agl.service}} \
{{#required-permission.urn:AGL:permission::public:applications:read}}--alias=/icons:{{:#metadata.icons-dir}}{{/required-permission.urn:AGL:permission::public:applications:read}} \
--token=HELLO \
--roothttp={{#content.type=application/vnd.agl.service}}.{{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}}{{#required-permission.urn:AGL:permission::public:no-htdocs}}.{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{^required-permission.urn:AGL:permission::public:no-htdocs}}htdocs{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{/content.type=application/vnd.agl.service}} \
{{#required-permission.urn:AGL:permission::public:applications:read}}--alias=/icons:{{:#metadata.icons-dir}}{{/required-permission.urn:AGL:permission::public:applications:read}} \
;---------------------------------------------------------------------------------
{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}}
{{^content.type=application/vnd.agl.service}}
;---------------------------------------------------------------------------------
{{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}}
{{^content.type=application/vnd.agl.service}}
-X-AFM--http-port={{:#metadata.http-port}}
+X-AFM--http-port={{:#metatarget.http-port}}
{{/content.type=application/vnd.agl.service}}
Type=notify
ExecStart=/usr/bin/afb-daemon \
{{/content.type=application/vnd.agl.service}}
Type=notify
ExecStart=/usr/bin/afb-daemon \
{{#content.type=application/vnd.agl.service}} \
--no-httpd \
{{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}} \
{{#content.type=application/vnd.agl.service}} \
--no-httpd \
{{/content.type=application/vnd.agl.service}}{{^content.type=application/vnd.agl.service}} \
- --port={{:#metadata.http-port}} \
+ --port={{:#metatarget.http-port}} \
--random-token \
--roothttp={{#required-permission.urn:AGL:permission::public:no-htdocs}}.{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{^required-permission.urn:AGL:permission::public:no-htdocs}}htdocs{{/required-permission.urn:AGL:permission::public:no-htdocs}} \
{{/content.type=application/vnd.agl.service}} \
--random-token \
--roothttp={{#required-permission.urn:AGL:permission::public:no-htdocs}}.{{/required-permission.urn:AGL:permission::public:no-htdocs}}{{^required-permission.urn:AGL:permission::public:no-htdocs}}htdocs{{/required-permission.urn:AGL:permission::public:no-htdocs}} \
{{/content.type=application/vnd.agl.service}} \
dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4:
IF_AGL_DEVEL
dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4:
IF_AGL_DEVEL
-X-AFM-http-port={{:#metadata.http-port}}
+X-AFM-http-port={{:#metatarget.http-port}}
ELSE
IF_NOT_CONTENT(application/vnd.agl.service)
ELSE
IF_NOT_CONTENT(application/vnd.agl.service)
-X-AFM--http-port={{:#metadata.http-port}}
+X-AFM--http-port={{:#metatarget.http-port}}
--verbose \
--verbose \
--monitoring \
--verbose \
--verbose \
--monitoring \
- --port={{:#metadata.http-port}} \
+ --port={{:#metatarget.http-port}} \
--token=HELLO \
--roothttp=ON_CONTENT(application/vnd.agl.service, ., ON_PERM(:public:no-htdocs, ., htdocs)) \
ELSE \
IF_CONTENT(application/vnd.agl.service) \
--no-httpd \
ELSE \
--token=HELLO \
--roothttp=ON_CONTENT(application/vnd.agl.service, ., ON_PERM(:public:no-htdocs, ., htdocs)) \
ELSE \
IF_CONTENT(application/vnd.agl.service) \
--no-httpd \
ELSE \
- --port={{:#metadata.http-port}} \
+ --port={{:#metatarget.http-port}} \
--random-token \
--roothttp=ON_PERM(:public:no-htdocs, ., htdocs) \
ENDIF \
--random-token \
--roothttp=ON_PERM(:public:no-htdocs, ., htdocs) \
ENDIF \
+static int port()
+{
+ static int r = 10000;
+ return r++;
+}
+
int main(int ac, char **av)
{
struct unitconf conf;
int main(int ac, char **av)
{
struct unitconf conf;
conf.installdir = "INSTALL-DIR";
conf.icondir = "ICONS-DIR";
conf.installdir = "INSTALL-DIR";
conf.icondir = "ICONS-DIR";
rc = unit_generator_open_template(*++av);
if (rc < 0)
error("can't read template %s: %m",*av);
rc = unit_generator_open_template(*++av);
if (rc < 0)
error("can't read template %s: %m",*av);
struct wgt_info *ifo;
const struct wgt_desc *desc;
char installdir[PATH_MAX];
struct wgt_info *ifo;
const struct wgt_desc *desc;
char installdir[PATH_MAX];
struct unitconf uconf;
NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
struct unitconf uconf;
NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
if (install_file_properties(desc))
goto error4;
if (install_file_properties(desc))
goto error4;
- port = get_port();
- if (port < 0)
- goto error4;
-
uconf.installdir = installdir;
uconf.icondir = FWK_ICON_DIR;
uconf.installdir = installdir;
uconf.icondir = FWK_ICON_DIR;
if (unit_install(ifo, &uconf))
goto error4;
if (unit_install(ifo, &uconf))
goto error4;
- * exploration state when instanciating mustache
+ * exploration state when instantiating mustache
*/
struct expl {
struct json_object *root;
*/
struct expl {
struct json_object *root;
#include <limits.h>
#include <json-c/json.h>
#include <limits.h>
#include <json-c/json.h>
#include "verbose.h"
#include "utils-file.h"
#include "verbose.h"
#include "utils-file.h"
#include "utils-systemd.h"
#include "wgtpkg-unit.h"
#include "utils-systemd.h"
#include "wgtpkg-unit.h"
+#include "wgt-strings.h"
* 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:
* 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.
*/
* either by '\n' or '\0' (end of the string)
* * ' ': matches any space or tabs but at least one.
*/
static int add_metadata(struct json_object *jdesc, const struct unitconf *conf)
{
static int add_metadata(struct json_object *jdesc, const struct unitconf *conf)
{
+ struct json_object *targets, *targ;
+ 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,
return j_add_many_strings_m(jdesc,
"#metadata.install-dir", conf->installdir,
"#metadata.icons-dir", conf->icondir,
- "#metadata.http-port", portstr,
struct unitconf {
const char *installdir;
const char *icondir;
struct unitconf {
const char *installdir;
const char *icondir;