gluon-mesh-batman-adv: respondd: determine compat version from release version

We cannot add the same file (here: /lib/gluon/mesh-batman-adv/compat) to
two, installed packages. Therefore, instead of determining the compat
version number from this file, infer it from the batman-adv release
version number instead.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
This commit is contained in:
Linus Lüssing 2019-07-27 07:40:27 +02:00 committed by Matthias Schiffer
parent 011187e9f5
commit f9e68be4e0
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
1 changed files with 12 additions and 13 deletions

View File

@ -232,25 +232,24 @@ static struct json_object * get_mesh(void) {
return ret;
}
static struct json_object * get_batman_adv_compat(void) {
FILE *f = fopen("/lib/gluon/mesh-batman-adv/compat", "r");
if (!f)
static struct json_object * get_batman_adv_compat(const char *version) {
int compat = 15;
if (!version)
return NULL;
struct json_object *ret = NULL;
if (strcmp(version, "2013.4.0") == 0)
compat = 14;
int compat;
if (fscanf(f, "%i", &compat) == 1)
ret = json_object_new_int(compat);
fclose(f);
return ret;
return json_object_new_int(compat);
}
static struct json_object * respondd_provider_nodeinfo(void) {
struct json_object *ret = json_object_new_object();
char *version = gluonutil_read_line("/sys/module/batman_adv/version");
struct json_object *compat = get_batman_adv_compat(version);
struct json_object *network = json_object_new_object();
json_object_object_add(network, "addresses", get_addresses());
json_object_object_add(network, "mesh", get_mesh());
@ -258,8 +257,8 @@ static struct json_object * respondd_provider_nodeinfo(void) {
struct json_object *software = json_object_new_object();
struct json_object *software_batman_adv = json_object_new_object();
json_object_object_add(software_batman_adv, "version", gluonutil_wrap_and_free_string(gluonutil_read_line("/sys/module/batman_adv/version")));
json_object_object_add(software_batman_adv, "compat", get_batman_adv_compat());
json_object_object_add(software_batman_adv, "version", gluonutil_wrap_and_free_string(version));
json_object_object_add(software_batman_adv, "compat", compat);
json_object_object_add(software, "batman-adv", software_batman_adv);
json_object_object_add(ret, "software", software);