[ltt-dev] [UST PATCH 2/5] Add mode setting to socket directory creation

Nils Carlson nils.carlson at ludd.ltu.se
Tue Mar 29 13:46:35 EDT 2011


On Mar 29, 2011, at 5:45 PM, Mathieu Desnoyers wrote:

> * Nils Carlson (nils.carlson at ericsson.com) wrote:
>> Set the mode when creating the personal socket directory,
>> this way all app sockets are private.
>
> Do we want to start supporting group "tracing" here ?
>
No, not really. Its probably better to handle the tracing group
by forcing privilige handling through the session daemon.

The problem with the current ust scheme is that we create all sockets
in the same dir and the dir is global rw so anybody can mess it up.

At this point I'm content with making the current UST behave, we'll
use the session daemon for more intelligent solutions.

/Nils

> Mathieu
>
>>
>> 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 24a533d..c1f73ab 100644
>> --- a/libustcomm/ustcomm.c
>> +++ b/libustcomm/ustcomm.c
>> @@ -587,28 +587,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 8b4acf9..137fe5b 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;
>> -- 
>> 1.7.1
>>
>>
>> _______________________________________________
>> ltt-dev mailing list
>> ltt-dev at lists.casi.polymtl.ca
>> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>>
>
> -- 
> Mathieu Desnoyers
> Operating System Efficiency R&D Consultant
> EfficiOS Inc.
> http://www.efficios.com
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev





More information about the lttng-dev mailing list