2018-08-29 18:25:55

by Stotland, Inga

[permalink] [raw]
Subject: [PATCH BlueZ v5] tools/meshctl: Fix default directory for JSON files

This fixes the name of default directory that contains sample JSON files.
README file is updated to describe the default location.
---
tools/mesh/README | 19 +++++++++++++-
tools/meshctl.c | 65 ++++++++++++++++++++++++++++++++---------------
2 files changed, 62 insertions(+), 22 deletions(-)

diff --git a/tools/mesh/README b/tools/mesh/README
index ea561efc8..44d633313 100644
--- a/tools/mesh/README
+++ b/tools/mesh/README
@@ -1,5 +1,5 @@
MeshCtl - BlueZ GATT based Bluetooth Mesh Provisioner
-******************************************
+*****************************************************

Copyright (C) 2017 Intel Corporation. All rights reserved.

@@ -16,6 +16,23 @@ Configuration and options

Build meshctl and other Bluetooth Mesh based tools and utils

+Example configuration files
+===========================
+
+The MeshCtl tool requires two input configuration files in JSON format:
+ - local_node.json
+ Local mesh node configuration
+ - prov_db.json
+ Provisoner's database for all the configured nodes in the mesh
+
+The default directory for MeshCtl configuration files is
+/home/<username>/.config/meshctl
+
+To use .json configuration files either copy them to the default directory
+or, to specify a custom storage directory, run meshctl tool as:
+
+ meshctl -c <config_dir_name>
+
Information
===========

diff --git a/tools/meshctl.c b/tools/meshctl.c
index 3e1484f61..55e25a56e 100644
--- a/tools/meshctl.c
+++ b/tools/meshctl.c
@@ -72,6 +72,8 @@
#define MESH_PROXY_DATA_IN_UUID_STR "00002add-0000-1000-8000-00805f9b34fb"
#define MESH_PROXY_DATA_OUT_UUID_STR "00002ade-0000-1000-8000-00805f9b34fb"

+#define MESHCTL_CONFIG_DIR "meshctl"
+
static DBusConnection *dbus_conn;

struct adapter {
@@ -1873,7 +1875,7 @@ static const struct bt_shell_menu main_menu = {
{ } },
};

-static const char *mesh_config_dir;
+static const char *config_dir;

static const struct option options[] = {
{ "config", required_argument, 0, 'c' },
@@ -1881,7 +1883,7 @@ static const struct option options[] = {
};

static const char **optargs[] = {
- &mesh_config_dir
+ &config_dir
};

static const char *help[] = {
@@ -1907,38 +1909,57 @@ int main(int argc, char *argv[])
int status;
int len;
int extra;
+ char *mesh_dir = NULL;

bt_shell_init(argc, argv, &opt);
bt_shell_set_menu(&main_menu);
bt_shell_set_prompt(PROMPT_OFF);

- if (!mesh_config_dir) {
- bt_shell_printf("Local config directory not provided.\n");
- mesh_config_dir = "";
+ if (!config_dir) {
+ char *home;
+
+ home = getenv("XDG_CONFIG_HOME");
+ if (home) {
+ mesh_dir = g_strdup_printf("%s/%s", home,
+ MESHCTL_CONFIG_DIR);
+ }
+
+ if (!mesh_dir) {
+ home = getenv("HOME");
+ mesh_dir = g_strdup_printf("%s/.config/%s", home,
+ MESHCTL_CONFIG_DIR);
+ }
+
+ if (!mesh_dir) {
+ g_printerr("Configuration directory not found\n");
+ goto fail;
+ }
+
} else {
- bt_shell_printf("Reading prov_db.json and local_node.json from"
- " %s\n", mesh_config_dir);
+ mesh_dir = g_strdup_printf("%s", config_dir);
}

- len = strlen(mesh_config_dir);
- if (len && mesh_config_dir[len - 1] != '/') {
+
+ g_print("Reading prov_db.json and local_node.json from %s directory\n",
+ mesh_dir);
+
+ len = strlen(mesh_dir);
+
+ if (len && mesh_dir[len - 1] != '/')
extra = 1;
- bt_shell_printf("mesh_config_dir[%d] %s\n", len,
- &mesh_config_dir[len - 1]);
- } else {
+ else
extra = 0;
- }
+
mesh_local_config_filename = g_malloc(len + strlen("local_node.json")
+ 2);
if (!mesh_local_config_filename)
goto fail;

mesh_prov_db_filename = g_malloc(len + strlen("prov_db.json") + 2);
- if (!mesh_prov_db_filename) {
+ if (!mesh_prov_db_filename)
goto fail;
- }

- sprintf(mesh_local_config_filename, "%s", mesh_config_dir);
+ sprintf(mesh_local_config_filename, "%s", mesh_dir);

if (extra)
sprintf(mesh_local_config_filename + len , "%c", '/');
@@ -1946,7 +1967,6 @@ int main(int argc, char *argv[])
sprintf(mesh_local_config_filename + len + extra, "%s",
"local_node.json");
len = len + extra + strlen("local_node.json");
- sprintf(mesh_local_config_filename + len, "%c", '\0');

if (!prov_db_read_local_node(mesh_local_config_filename, true)) {
g_printerr("Failed to parse local node configuration file %s\n",
@@ -1954,14 +1974,15 @@ int main(int argc, char *argv[])
goto fail;
}

- sprintf(mesh_prov_db_filename, "%s", mesh_config_dir);
- len = strlen(mesh_config_dir);
+ sprintf(mesh_prov_db_filename, "%s", mesh_dir);
+ len = strlen(mesh_dir);
+
+ g_free(mesh_dir);
+
if (extra)
sprintf(mesh_prov_db_filename + len , "%c", '/');

sprintf(mesh_prov_db_filename + len + extra, "%s", "prov_db.json");
- sprintf(mesh_prov_db_filename + len + extra + strlen("prov_db.json"),
- "%c", '\0');

if (!prov_db_read(mesh_prov_db_filename)) {
g_printerr("Failed to parse provisioning database file %s\n",
@@ -2006,5 +2027,7 @@ int main(int argc, char *argv[])

fail:
bt_shell_cleanup();
+ g_free(mesh_dir);
+
return EXIT_FAILURE;
}
--
2.17.1


2018-08-31 14:27:15

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v5] tools/meshctl: Fix default directory for JSON files

Hi Inga,

On Wed, Aug 29, 2018 at 9:25 PM, Inga Stotland <[email protected]> wrote:
> This fixes the name of default directory that contains sample JSON files.
> README file is updated to describe the default location.
> ---
> tools/mesh/README | 19 +++++++++++++-
> tools/meshctl.c | 65 ++++++++++++++++++++++++++++++++---------------
> 2 files changed, 62 insertions(+), 22 deletions(-)
>
> diff --git a/tools/mesh/README b/tools/mesh/README
> index ea561efc8..44d633313 100644
> --- a/tools/mesh/README
> +++ b/tools/mesh/README
> @@ -1,5 +1,5 @@
> MeshCtl - BlueZ GATT based Bluetooth Mesh Provisioner
> -******************************************
> +*****************************************************
>
> Copyright (C) 2017 Intel Corporation. All rights reserved.
>
> @@ -16,6 +16,23 @@ Configuration and options
>
> Build meshctl and other Bluetooth Mesh based tools and utils
>
> +Example configuration files
> +===========================
> +
> +The MeshCtl tool requires two input configuration files in JSON format:
> + - local_node.json
> + Local mesh node configuration
> + - prov_db.json
> + Provisoner's database for all the configured nodes in the mesh
> +
> +The default directory for MeshCtl configuration files is
> +/home/<username>/.config/meshctl
> +
> +To use .json configuration files either copy them to the default directory
> +or, to specify a custom storage directory, run meshctl tool as:
> +
> + meshctl -c <config_dir_name>
> +
> Information
> ===========
>
> diff --git a/tools/meshctl.c b/tools/meshctl.c
> index 3e1484f61..55e25a56e 100644
> --- a/tools/meshctl.c
> +++ b/tools/meshctl.c
> @@ -72,6 +72,8 @@
> #define MESH_PROXY_DATA_IN_UUID_STR "00002add-0000-1000-8000-00805f9b34fb"
> #define MESH_PROXY_DATA_OUT_UUID_STR "00002ade-0000-1000-8000-00805f9b34fb"
>
> +#define MESHCTL_CONFIG_DIR "meshctl"
> +
> static DBusConnection *dbus_conn;
>
> struct adapter {
> @@ -1873,7 +1875,7 @@ static const struct bt_shell_menu main_menu = {
> { } },
> };
>
> -static const char *mesh_config_dir;
> +static const char *config_dir;
>
> static const struct option options[] = {
> { "config", required_argument, 0, 'c' },
> @@ -1881,7 +1883,7 @@ static const struct option options[] = {
> };
>
> static const char **optargs[] = {
> - &mesh_config_dir
> + &config_dir
> };
>
> static const char *help[] = {
> @@ -1907,38 +1909,57 @@ int main(int argc, char *argv[])
> int status;
> int len;
> int extra;
> + char *mesh_dir = NULL;
>
> bt_shell_init(argc, argv, &opt);
> bt_shell_set_menu(&main_menu);
> bt_shell_set_prompt(PROMPT_OFF);
>
> - if (!mesh_config_dir) {
> - bt_shell_printf("Local config directory not provided.\n");
> - mesh_config_dir = "";
> + if (!config_dir) {
> + char *home;
> +
> + home = getenv("XDG_CONFIG_HOME");
> + if (home) {
> + mesh_dir = g_strdup_printf("%s/%s", home,
> + MESHCTL_CONFIG_DIR);
> + }
> +
> + if (!mesh_dir) {
> + home = getenv("HOME");
> + mesh_dir = g_strdup_printf("%s/.config/%s", home,
> + MESHCTL_CONFIG_DIR);
> + }
> +
> + if (!mesh_dir) {
> + g_printerr("Configuration directory not found\n");
> + goto fail;
> + }
> +
> } else {
> - bt_shell_printf("Reading prov_db.json and local_node.json from"
> - " %s\n", mesh_config_dir);
> + mesh_dir = g_strdup_printf("%s", config_dir);
> }
>
> - len = strlen(mesh_config_dir);
> - if (len && mesh_config_dir[len - 1] != '/') {
> +
> + g_print("Reading prov_db.json and local_node.json from %s directory\n",
> + mesh_dir);
> +
> + len = strlen(mesh_dir);
> +
> + if (len && mesh_dir[len - 1] != '/')
> extra = 1;
> - bt_shell_printf("mesh_config_dir[%d] %s\n", len,
> - &mesh_config_dir[len - 1]);
> - } else {
> + else
> extra = 0;
> - }
> +
> mesh_local_config_filename = g_malloc(len + strlen("local_node.json")
> + 2);
> if (!mesh_local_config_filename)
> goto fail;
>
> mesh_prov_db_filename = g_malloc(len + strlen("prov_db.json") + 2);
> - if (!mesh_prov_db_filename) {
> + if (!mesh_prov_db_filename)
> goto fail;
> - }
>
> - sprintf(mesh_local_config_filename, "%s", mesh_config_dir);
> + sprintf(mesh_local_config_filename, "%s", mesh_dir);
>
> if (extra)
> sprintf(mesh_local_config_filename + len , "%c", '/');
> @@ -1946,7 +1967,6 @@ int main(int argc, char *argv[])
> sprintf(mesh_local_config_filename + len + extra, "%s",
> "local_node.json");
> len = len + extra + strlen("local_node.json");
> - sprintf(mesh_local_config_filename + len, "%c", '\0');
>
> if (!prov_db_read_local_node(mesh_local_config_filename, true)) {
> g_printerr("Failed to parse local node configuration file %s\n",
> @@ -1954,14 +1974,15 @@ int main(int argc, char *argv[])
> goto fail;
> }
>
> - sprintf(mesh_prov_db_filename, "%s", mesh_config_dir);
> - len = strlen(mesh_config_dir);
> + sprintf(mesh_prov_db_filename, "%s", mesh_dir);
> + len = strlen(mesh_dir);
> +
> + g_free(mesh_dir);
> +
> if (extra)
> sprintf(mesh_prov_db_filename + len , "%c", '/');
>
> sprintf(mesh_prov_db_filename + len + extra, "%s", "prov_db.json");
> - sprintf(mesh_prov_db_filename + len + extra + strlen("prov_db.json"),
> - "%c", '\0');
>
> if (!prov_db_read(mesh_prov_db_filename)) {
> g_printerr("Failed to parse provisioning database file %s\n",
> @@ -2006,5 +2027,7 @@ int main(int argc, char *argv[])
>
> fail:
> bt_shell_cleanup();
> + g_free(mesh_dir);
> +
> return EXIT_FAILURE;
> }
> --
> 2.17.1

Applied, thanks.


--
Luiz Augusto von Dentz

2018-09-12 19:32:43

by Gix, Brian

[permalink] [raw]
Subject: RE: [PATCH BlueZ v5] tools/meshctl: Fix default directory for JSON files

SGkgUmF1bCwNCg0KLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogbGludXgtYmx1
ZXRvb3RoLW93bmVyQHZnZXIua2VybmVsLm9yZyBbbWFpbHRvOmxpbnV4LWJsdWV0b290aC0NCj4g
b3duZXJAdmdlci5rZXJuZWwub3JnXSBPbiBCZWhhbGYgT2YgUmF1bCBQaXBlcg0KPiBTZW50OiBX
ZWRuZXNkYXksIFNlcHRlbWJlciAxMiwgMjAxOCAxMDozMyBBTQ0KPiBUbzogbHVpei5kZW50ekBn
bWFpbC5jb20NCj4gQ2M6IFN0b3RsYW5kLCBJbmdhIDxpbmdhLnN0b3RsYW5kQGludGVsLmNvbT47
IGxpbnV4LQ0KPiBibHVldG9vdGhAdmdlci5rZXJuZWwub3JnDQo+IFN1YmplY3Q6IFJlOiBbUEFU
Q0ggQmx1ZVogdjVdIHRvb2xzL21lc2hjdGw6IEZpeCBkZWZhdWx0IGRpcmVjdG9yeSBmb3IgSlNP
Tg0KPiBmaWxlcw0KPiANCj4gSGVsbG8gLA0KPiBPbiBGcmksIEF1ZyAzMSwgMjAxOCBhdCA3OjU3
IFBNIEx1aXogQXVndXN0byB2b24gRGVudHoNCj4gPGx1aXouZGVudHpAZ21haWwuY29tPiB3cm90
ZToNCj4gPg0KPiA+IEhpIEluZ2EsDQo+ID4NCj4gPiBPbiBXZWQsIEF1ZyAyOSwgMjAxOCBhdCA5
OjI1IFBNLCBJbmdhIFN0b3RsYW5kIDxpbmdhLnN0b3RsYW5kQGludGVsLmNvbT4NCj4gd3JvdGU6
DQo+ID4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G9yeSBub3QgcHJvdmlkZWQuXG4iKTsNCj4gPiA+IC0gICAgICAgICAgICAgICBtZXNoX2Nv
bmZpZ19kaXIgPSAiIjsNCj4gPiA+ICsgICAgICAgaWYgKCFjb25maWdfZGlyKSB7DQo+ID4gPiAr
ICAgICAgICAgICAgICAgY2hhciAqaG9tZTsNCj4gPiA+ICsNCj4gPiA+ICsgICAgICAgICAgICAg
ICBob21lID0gZ2V0ZW52KCJYREdfQ09ORklHX0hPTUUiKTsNCj4gPiA+ICsgICAgICAgICAgICAg
ICBpZiAoaG9tZSkgew0KPiA+ID4gKyAgICAgICAgICAgICAgICAgICAgICAgbWVzaF9kaXIgPSBn
X3N0cmR1cF9wcmludGYoIiVzLyVzIiwgaG9tZSwNCj4gPiA+ICsgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgTUVTSENUTF9DT05GSUdfRElSKTsN
Cj4gPiA+ICsgICAgICAgICAgICAgICB9DQo+ID4gPiArDQo+ID4gPiArICAgICAgICAgICAgICAg
aWYgKCFtZXNoX2Rpcikgew0KPiA+ID4gKyAgICAgICAgICAgICAgICAgICAgICAgaG9tZSA9IGdl
dGVudigiSE9NRSIpOw0KPiA+ID4gKyAgICAgICAgICAgICAgICAgICAgICAgbWVzaF9kaXIgPSBn
X3N0cmR1cF9wcmludGYoIiVzLy5jb25maWcvJXMiLCBob21lLA0KPiA+ID4gKyAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBNRVNIQ1RMX0NPTkZJ
R19ESVIpOw0KPiA+ID4gKyAgICAgICAgICAgICAgIH0NCj4gPiA+ICsNCj4gPiA+ICsgICAgICAg
ICAgICAgICBpZiAoIW1lc2hfZGlyKSB7DQo+ID4gPiArICAgICAgICAgICAgICAgICAgICAgICBn
X3ByaW50ZXJyKCJDb25maWd1cmF0aW9uIGRpcmVjdG9yeSBub3QgZm91bmRcbiIpOw0KPiA+ID4g
K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W51cCgpOw0KPiA+ID4gKyAgICAgICBnX2ZyZWUobWVz
aF9kaXIpOw0KPiA+ID4gKw0KPiA+ID4gICAgICAgICByZXR1cm4gRVhJVF9GQUlMVVJFOw0KPiA+
ID4gIH0NCj4gPiA+IC0tDQo+ID4gPiAyLjE3LjENCj4gPg0KPiA+IEFwcGxpZWQsIHRoYW5rcy4N
Cj4gPg0KPiA+DQo+ID4gLS0NCj4gPiBMdWl6IEF1Z3VzdG8gdm9uIERlbnR6DQo+IA0KPiBJcyB0
aGVyZSBhIFBCX0FEViBzdXBwb3J0IGluIG1lc2hjdGwgZm9yIHByb3Zpc2lvbmluZz9JZiBub3Qg
YW55IHBsYW4gaW4NCj4gZnV0dXJlPw0KDQpQQi1BRFYgc3VwcG9ydCB3aWxsICpub3QqIGJlIGFk
ZGVkIHRvIG1lc2hjdGwsIGhvd2V2ZXIsIHdlICp3aWxsKiBiZSBhZGRpbmcgUHJvdmlzaW9uaW5n
IHN1cHBvcnQgdG8gYnRtZXNoIGFuZCBtZXNoZC4gVGhpcyB3b3JrIGlzIHVuZGVyd2F5IG5vdywg
YWx0aG91Z2ggd2UgZG8gbmVlZCB0byB3YWl0IGZvciBhIGZldyB0aGluZ3MgaW4gdGhlIFdvcmtp
bmcgR3JvdXAgdG8gYmVjb21lICJPZmZpY2lhbCIgcmVnYXJkaW5nIHRoZSBkYXRhYmFzZS4NCg0K
PiANCj4gQnIsDQo+IFJwDQo=

2018-09-12 17:33:00

by Raul Piper

[permalink] [raw]
Subject: Re: [PATCH BlueZ v5] tools/meshctl: Fix default directory for JSON files

Hello ,
On Fri, Aug 31, 2018 at 7:57 PM Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Hi Inga,
>
> On Wed, Aug 29, 2018 at 9:25 PM, Inga Stotland <[email protected]> wrote:
> > This fixes the name of default directory that contains sample JSON files.
> > README file is updated to describe the default location.
> > ---
> > tools/mesh/README | 19 +++++++++++++-
> > tools/meshctl.c | 65 ++++++++++++++++++++++++++++++++---------------
> > 2 files changed, 62 insertions(+), 22 deletions(-)
> >
> > diff --git a/tools/mesh/README b/tools/mesh/README
> > index ea561efc8..44d633313 100644
> > --- a/tools/mesh/README
> > +++ b/tools/mesh/README
> > @@ -1,5 +1,5 @@
> > MeshCtl - BlueZ GATT based Bluetooth Mesh Provisioner
> > -******************************************
> > +*****************************************************
> >
> > Copyright (C) 2017 Intel Corporation. All rights reserved.
> >
> > @@ -16,6 +16,23 @@ Configuration and options
> >
> > Build meshctl and other Bluetooth Mesh based tools and utils
> >
> > +Example configuration files
> > +===========================
> > +
> > +The MeshCtl tool requires two input configuration files in JSON format:
> > + - local_node.json
> > + Local mesh node configuration
> > + - prov_db.json
> > + Provisoner's database for all the configured nodes in the mesh
> > +
> > +The default directory for MeshCtl configuration files is
> > +/home/<username>/.config/meshctl
> > +
> > +To use .json configuration files either copy them to the default directory
> > +or, to specify a custom storage directory, run meshctl tool as:
> > +
> > + meshctl -c <config_dir_name>
> > +
> > Information
> > ===========
> >
> > diff --git a/tools/meshctl.c b/tools/meshctl.c
> > index 3e1484f61..55e25a56e 100644
> > --- a/tools/meshctl.c
> > +++ b/tools/meshctl.c
> > @@ -72,6 +72,8 @@
> > #define MESH_PROXY_DATA_IN_UUID_STR "00002add-0000-1000-8000-00805f9b34fb"
> > #define MESH_PROXY_DATA_OUT_UUID_STR "00002ade-0000-1000-8000-00805f9b34fb"
> >
> > +#define MESHCTL_CONFIG_DIR "meshctl"
> > +
> > static DBusConnection *dbus_conn;
> >
> > struct adapter {
> > @@ -1873,7 +1875,7 @@ static const struct bt_shell_menu main_menu = {
> > { } },
> > };
> >
> > -static const char *mesh_config_dir;
> > +static const char *config_dir;
> >
> > static const struct option options[] = {
> > { "config", required_argument, 0, 'c' },
> > @@ -1881,7 +1883,7 @@ static const struct option options[] = {
> > };
> >
> > static const char **optargs[] = {
> > - &mesh_config_dir
> > + &config_dir
> > };
> >
> > static const char *help[] = {
> > @@ -1907,38 +1909,57 @@ int main(int argc, char *argv[])
> > int status;
> > int len;
> > int extra;
> > + char *mesh_dir = NULL;
> >
> > bt_shell_init(argc, argv, &opt);
> > bt_shell_set_menu(&main_menu);
> > bt_shell_set_prompt(PROMPT_OFF);
> >
> > - if (!mesh_config_dir) {
> > - bt_shell_printf("Local config directory not provided.\n");
> > - mesh_config_dir = "";
> > + if (!config_dir) {
> > + char *home;
> > +
> > + home = getenv("XDG_CONFIG_HOME");
> > + if (home) {
> > + mesh_dir = g_strdup_printf("%s/%s", home,
> > + MESHCTL_CONFIG_DIR);
> > + }
> > +
> > + if (!mesh_dir) {
> > + home = getenv("HOME");
> > + mesh_dir = g_strdup_printf("%s/.config/%s", home,
> > + MESHCTL_CONFIG_DIR);
> > + }
> > +
> > + if (!mesh_dir) {
> > + g_printerr("Configuration directory not found\n");
> > + goto fail;
> > + }
> > +
> > } else {
> > - bt_shell_printf("Reading prov_db.json and local_node.json from"
> > - " %s\n", mesh_config_dir);
> > + mesh_dir = g_strdup_printf("%s", config_dir);
> > }
> >
> > - len = strlen(mesh_config_dir);
> > - if (len && mesh_config_dir[len - 1] != '/') {
> > +
> > + g_print("Reading prov_db.json and local_node.json from %s directory\n",
> > + mesh_dir);
> > +
> > + len = strlen(mesh_dir);
> > +
> > + if (len && mesh_dir[len - 1] != '/')
> > extra = 1;
> > - bt_shell_printf("mesh_config_dir[%d] %s\n", len,
> > - &mesh_config_dir[len - 1]);
> > - } else {
> > + else
> > extra = 0;
> > - }
> > +
> > mesh_local_config_filename = g_malloc(len + strlen("local_node.json")
> > + 2);
> > if (!mesh_local_config_filename)
> > goto fail;
> >
> > mesh_prov_db_filename = g_malloc(len + strlen("prov_db.json") + 2);
> > - if (!mesh_prov_db_filename) {
> > + if (!mesh_prov_db_filename)
> > goto fail;
> > - }
> >
> > - sprintf(mesh_local_config_filename, "%s", mesh_config_dir);
> > + sprintf(mesh_local_config_filename, "%s", mesh_dir);
> >
> > if (extra)
> > sprintf(mesh_local_config_filename + len , "%c", '/');
> > @@ -1946,7 +1967,6 @@ int main(int argc, char *argv[])
> > sprintf(mesh_local_config_filename + len + extra, "%s",
> > "local_node.json");
> > len = len + extra + strlen("local_node.json");
> > - sprintf(mesh_local_config_filename + len, "%c", '\0');
> >
> > if (!prov_db_read_local_node(mesh_local_config_filename, true)) {
> > g_printerr("Failed to parse local node configuration file %s\n",
> > @@ -1954,14 +1974,15 @@ int main(int argc, char *argv[])
> > goto fail;
> > }
> >
> > - sprintf(mesh_prov_db_filename, "%s", mesh_config_dir);
> > - len = strlen(mesh_config_dir);
> > + sprintf(mesh_prov_db_filename, "%s", mesh_dir);
> > + len = strlen(mesh_dir);
> > +
> > + g_free(mesh_dir);
> > +
> > if (extra)
> > sprintf(mesh_prov_db_filename + len , "%c", '/');
> >
> > sprintf(mesh_prov_db_filename + len + extra, "%s", "prov_db.json");
> > - sprintf(mesh_prov_db_filename + len + extra + strlen("prov_db.json"),
> > - "%c", '\0');
> >
> > if (!prov_db_read(mesh_prov_db_filename)) {
> > g_printerr("Failed to parse provisioning database file %s\n",
> > @@ -2006,5 +2027,7 @@ int main(int argc, char *argv[])
> >
> > fail:
> > bt_shell_cleanup();
> > + g_free(mesh_dir);
> > +
> > return EXIT_FAILURE;
> > }
> > --
> > 2.17.1
>
> Applied, thanks.
>
>
> --
> Luiz Augusto von Dentz

Is there a PB_ADV support in meshctl for provisioning?If not any plan in future?

Br,
Rp