linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gix, Brian" <brian.gix@intel.com>
To: "linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>,
	"Stotland, Inga" <inga.stotland@intel.com>
Cc: "luiz.dentz@gmail.com" <luiz.dentz@gmail.com>,
	"johan.hedberg@gmail.com" <johan.hedberg@gmail.com>
Subject: Re: [PATCH BlueZ 1/1] mesh: Modify check of the node directory name upon removal
Date: Wed, 26 Jun 2019 17:44:46 +0000	[thread overview]
Message-ID: <1561571085.22940.18.camel@intel.com> (raw)
In-Reply-To: <20190624174142.15920-1-inga.stotland@intel.com>

Applied, Thanks.

On Mon, 2019-06-24 at 10:41 -0700, Inga Stotland wrote:
> This removes check for "mesh" as the parent directory name and, instead,
> verifies that the node configuration directory name is the hexadecimal
> string representating the node's UUID.
> ---
>  mesh/storage.c | 39 +++++++++++++--------------------------
>  1 file changed, 13 insertions(+), 26 deletions(-)
> 
> diff --git a/mesh/storage.c b/mesh/storage.c
> index 1a9945aa8..54c985559 100644
> --- a/mesh/storage.c
> +++ b/mesh/storage.c
> @@ -53,20 +53,6 @@ static const char *bak_ext = ".bak";
>  static const char *tmp_ext = ".tmp";
>  static const char *storage_dir;
>  
> -/* This is a thread-safe always malloced version of dirname which will work
> - * regardless of which underlying dirname() implementation is used.
> - */
> -static char *alloc_dirname(const char *path)
> -{
> -	char *tmp = l_strdup(path);
> -	char *dir;
> -
> -	dir = dirname(tmp);
> -	strncpy(tmp, dir, strlen(path) + 1);
> -
> -	return tmp;
> -}
> -
>  static bool read_node_cb(struct mesh_db_node *db_node, void *user_data)
>  {
>  	struct mesh_node *node = user_data;
> @@ -486,20 +472,20 @@ void storage_save_config(struct mesh_node *node, bool no_wait,
>  		l_idle_oneshot(idle_save_config, info, NULL);
>  }
>  
> -static int create_dir(const char *dirname)
> +static int create_dir(const char *dir_name)
>  {
>  	struct stat st;
>  	char dir[PATH_MAX + 1], *prev, *next;
>  	int err;
>  
> -	err = stat(dirname, &st);
> +	err = stat(dir_name, &st);
>  	if (!err && S_ISREG(st.st_mode))
>  		return 0;
>  
>  	memset(dir, 0, PATH_MAX + 1);
>  	strcat(dir, "/");
>  
> -	prev = strchr(dirname, '/');
> +	prev = strchr(dir_name, '/');
>  
>  	while (prev) {
>  		next = strchr(prev + 1, '/');
> @@ -517,7 +503,7 @@ static int create_dir(const char *dirname)
>  		prev = next;
>  	}
>  
> -	mkdir(dirname, 0755);
> +	mkdir(dir_name, 0755);
>  
>  	return 0;
>  }
> @@ -640,7 +626,8 @@ static int del_fobject(const char *fpath, const struct stat *sb, int typeflag,
>  /* Permanently remove node configuration */
>  void storage_remove_node_config(struct mesh_node *node)
>  {
> -	char *node_path, *mesh_path, *mesh_name;
> +	char *node_path, *node_name;
> +	char uuid[33];
>  	struct json_object *jnode;
>  
>  	if (!node)
> @@ -656,13 +643,13 @@ void storage_remove_node_config(struct mesh_node *node)
>  	l_debug("Delete node config %s", node_path);
>  
>  	/* Make sure path name of node follows expected guidelines */
> -	mesh_path = alloc_dirname(node_path);
> -	mesh_name = basename(mesh_path);
> -	if (strcmp(mesh_name, "mesh"))
> -		goto done;
> +	if (!hex2str(node_uuid_get(node), 16, uuid, sizeof(uuid)))
> +		return;
>  
> -	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
> +	node_name = basename(node_path);
>  
> -done:
> -	l_free(mesh_path);
> +	if (strcmp(node_name, uuid))
> +		return;
> +
> +	nftw(node_path, del_fobject, 5, FTW_DEPTH | FTW_PHYS);
>  }

      reply	other threads:[~2019-06-26 17:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24 17:41 [PATCH BlueZ 1/1] mesh: Modify check of the node directory name upon removal Inga Stotland
2019-06-26 17:44 ` Gix, Brian [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1561571085.22940.18.camel@intel.com \
    --to=brian.gix@intel.com \
    --cc=inga.stotland@intel.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).