Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: nils.carlson@ericsson.com (Nils Carlson)
Subject: [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation
Date: Fri, 1 Apr 2011 09:15:22 +0200	[thread overview]
Message-ID: <4D957B8A.6090800@ericsson.com> (raw)
In-Reply-To: <1301643140-6880-2-git-send-email-nils.carlson@ericsson.com>

merged.

On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Set the mode when creating the personal socket directory,
> this way all app sockets are private.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
>   libust/tracectl.c               |    2 +-
>   libustcomm/ustcomm.c            |   20 +++++++++++++-------
>   libustcomm/ustcomm.h            |    2 +-
>   libustconsumer/libustconsumer.c |    2 +-
>   4 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/libust/tracectl.c b/libust/tracectl.c
> index ae92b7e..58b567f 100644
> --- a/libust/tracectl.c
> +++ b/libust/tracectl.c
> @@ -1236,7 +1236,7 @@ static struct ustcomm_sock * init_app_socket(int epoll_fd)
>   		goto free_dir_name;
>   	}
>
> -	result = ensure_dir_exists(dir_name);
> +	result = ensure_dir_exists(dir_name, S_IRWXU);
>   	if (result == -1) {
>   		ERR("Unable to create socket directory %s, UST thread bailing",
>   		    dir_name);
> diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
> index dce1e52..e401c42 100644
> --- a/libustcomm/ustcomm.c
> +++ b/libustcomm/ustcomm.c
> @@ -588,28 +588,34 @@ free_dir_name:
>   	return retval;
>   }
>
> -int ensure_dir_exists(const char *dir)
> +int ensure_dir_exists(const char *dir, mode_t mode)
>   {
>   	struct stat st;
>   	int result;
>
> -	if(!strcmp(dir, ""))
> +	if (!strcmp(dir, ""))
>   		return -1;
>
>   	result = stat(dir,&st);
> -	if(result == -1&&  errno != ENOENT) {
> +	if (result<  0&&  errno != ENOENT) {
>   		return -1;
> -	}
> -	else if(result == -1) {
> +	} else if (result<  0) {
>   		/* ENOENT */
>   		int result;
>
> -		/* mkdir mode to 0777 */
> -		result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO);
> +		result = mkdir_p(dir, mode);
>   		if(result != 0) {
>   			ERR("executing in recursive creation of directory %s", dir);
>   			return -1;
>   		}
> +	} else {
> +		if (st.st_mode != mode) {
> +			result = chmod(dir, mode);
> +			if (result<  0) {
> +				ERR("couldn't set directory mode on %s", dir);
> +				return -1;
> +			}
> +		}
>   	}
>
>   	return 0;
> diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
> index db38119..d16aec7 100644
> --- a/libustcomm/ustcomm.h
> +++ b/libustcomm/ustcomm.h
> @@ -119,7 +119,7 @@ struct ustcomm_notify_buf_mapped {
>   };
>
>   /* Ensure directory existence, usefull for unix sockets */
> -extern int ensure_dir_exists(const char *dir);
> +extern int ensure_dir_exists(const char *dir, mode_t mode);
>
>   /* Create and delete sockets */
>   extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd,
> diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c
> index 8eb4424..eaee1fa 100644
> --- a/libustconsumer/libustconsumer.c
> +++ b/libustconsumer/libustconsumer.c
> @@ -846,7 +846,7 @@ static int init_ustconsumer_socket(struct ustconsumer_instance *instance)
>   		int result;
>
>   		/* Only check if socket dir exists if we are using the default directory */
> -		result = ensure_dir_exists(SOCK_DIR);
> +		result = ensure_dir_exists(SOCK_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
>   		if (result == -1) {
>   			ERR("Unable to create socket directory %s", SOCK_DIR);
>   			return -1;





  reply	other threads:[~2011-04-01  7:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
2011-04-01  7:14 ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation Nils Carlson
2011-04-01  7:15   ` Nils Carlson [this message]
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2 Nils Carlson
2011-04-01  7:15   ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl Nils Carlson
2011-04-01  7:16   ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 5/6] Make root see all available pids Nils Carlson
2011-04-01  7:17   ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app Nils Carlson
2011-04-01  7:17   ` Nils Carlson

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=4D957B8A.6090800@ericsson.com \
    --to=nils.carlson@ericsson.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