Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: nils.carlson@ericsson.com (Nils Carlson)
Subject: [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2
Date: Fri, 1 Apr 2011 09:14:55 +0200	[thread overview]
Message-ID: <4D957B6F.7090306@ericsson.com> (raw)
In-Reply-To: <1301643140-6880-1-git-send-email-nils.carlson@ericsson.com>

merged.

On 04/01/2011 09:32 AM, Nils Carlson wrote:
> Changes since v1:
> 	* Document memory allocation
>
> Make a separate app socket directories for each user, providing
> some basic security and also the possibility of consistent cleanup.
>
> Signed-off-by: Nils Carlson<nils.carlson at ericsson.com>
> ---
>   libust/tracectl.c    |   34 +++++++++++++++++++---------------
>   libustcomm/ustcomm.c |   34 +++++++++++++++++++++++++++++-----
>   libustcomm/ustcomm.h |    4 ++++
>   3 files changed, 52 insertions(+), 20 deletions(-)
>
> diff --git a/libust/tracectl.c b/libust/tracectl.c
> index 33c7280..ae92b7e 100644
> --- a/libust/tracectl.c
> +++ b/libust/tracectl.c
> @@ -1221,37 +1221,41 @@ static void auto_probe_connect(struct marker *m)
>
>   static struct ustcomm_sock * init_app_socket(int epoll_fd)
>   {
> -	char *name;
> +	char *dir_name, *sock_name;
>   	int result;
> -	struct ustcomm_sock *sock;
> +	struct ustcomm_sock *sock = NULL;
>
> -	result = asprintf(&name, "%s/%d", SOCK_DIR, (int)getpid());
> +	dir_name = ustcomm_user_sock_dir();
> +	if (!dir_name)
> +		return NULL;
> +
> +	result = asprintf(&sock_name, "%s/%d", dir_name, (int)getpid());
>   	if (result<  0) {
>   		ERR("string overflow allocating socket name, "
>   		    "UST thread bailing");
> -		return NULL;
> +		goto free_dir_name;
>   	}
>
> -	result = ensure_dir_exists(SOCK_DIR);
> +	result = ensure_dir_exists(dir_name);
>   	if (result == -1) {
>   		ERR("Unable to create socket directory %s, UST thread bailing",
> -		    SOCK_DIR);
> -		goto free_name;
> +		    dir_name);
> +		goto free_sock_name;
>   	}
>
> -	sock = ustcomm_init_named_socket(name, epoll_fd);
> +	sock = ustcomm_init_named_socket(sock_name, epoll_fd);
>   	if (!sock) {
>   		ERR("Error initializing named socket (%s). Check that directory"
> -		    "exists and that it is writable. UST thread bailing", name);
> -		goto free_name;
> +		    "exists and that it is writable. UST thread bailing", sock_name);
> +		goto free_sock_name;
>   	}
>
> -	free(name);
> -	return sock;
> +free_sock_name:
> +	free(sock_name);
> +free_dir_name:
> +	free(dir_name);
>
> -free_name:
> -	free(name);
> -	return NULL;
> +	return sock;
>   }
>
>   static void __attribute__((constructor)) init()
> diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
> index 43f4289..dce1e52 100644
> --- a/libustcomm/ustcomm.c
> +++ b/libustcomm/ustcomm.c
> @@ -533,6 +533,21 @@ close_sock:
>   	return -1;
>   }
>
> +/* Returns the current users socket directory, must be freed */
> +char *ustcomm_user_sock_dir(void)
> +{
> +	int result;
> +	char *sock_dir = NULL;
> +
> +	result = asprintf(&sock_dir, "%s%s", USER_SOCK_DIR,
> +			  cuserid(NULL));
> +	if (result<  0) {
> +		ERR("string overflow allocating directory name");
> +		return NULL;
> +	}
> +
> +	return sock_dir;
> +}
>
>   /* Open a connection to a traceable app.
>    *
> @@ -545,21 +560,30 @@ int ustcomm_connect_app(pid_t pid, int *app_fd)
>   {
>   	int result;
>   	int retval = 0;
> -	char *name;
> +	char *dir_name, *sock_name;
> +
> +	dir_name = ustcomm_user_sock_dir();
> +	if (!dir_name)
> +		return -ENOMEM;
>
> -	result = asprintf(&name, "%s/%d", SOCK_DIR, pid);
> +	result = asprintf(&sock_name, "%s/%d", dir_name, pid);
>   	if (result<  0) {
>   		ERR("failed to allocate socket name");
> -		return -1;
> +		retval = -1;
> +		goto free_dir_name;
>   	}
>
> -	result = ustcomm_connect_path(name, app_fd);
> +	result = ustcomm_connect_path(sock_name, app_fd);
>   	if (result<  0) {
>   		ERR("failed to connect to app");
>   		retval = -1;
> +		goto free_sock_name;
>   	}
>
> -	free(name);
> +free_sock_name:
> +	free(sock_name);
> +free_dir_name:
> +	free(dir_name);
>
>   	return retval;
>   }
> diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
> index 0ec04fc..db38119 100644
> --- a/libustcomm/ustcomm.h
> +++ b/libustcomm/ustcomm.h
> @@ -25,6 +25,7 @@
>   #include<ust/kcompat/kcompat.h>
>
>   #define SOCK_DIR "/tmp/ust-app-socks"
> +#define USER_SOCK_DIR "/tmp/ust-socks-"
>
>   struct ustcomm_sock {
>   	struct cds_list_head list;
> @@ -156,6 +157,9 @@ extern int ustcomm_req(int sock,
>   		       char *res_data);
>
>   extern int ustcomm_request_consumer(pid_t pid, const char *channel);
> +
> +/* Returns the current users socket directory, must be freed */
> +extern char *ustcomm_user_sock_dir(void);
>   extern int ustcomm_connect_app(pid_t pid, int *app_fd);
>   extern int ustcomm_connect_path(const char *path, int *connection_fd);
>





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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  7:32 Nils Carlson
2011-04-01  7:14 ` Nils Carlson [this message]
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
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=4D957B6F.7090306@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