[stgt] [PATCH 09/15] tgt: os.h - bind() is picky about names

Boaz Harrosh bharrosh at panasas.com
Tue Mar 3 09:36:40 CET 2009


FUJITA Tomonori wrote:
> On Sun,  1 Mar 2009 18:51:53 +0200
> Boaz Harrosh <bharrosh at panasas.com> wrote:
> 
>> The BSD's bind does not like the Linux IPC names with zero
>> as first char and zeros padding at end. Separate implementations
>> in os.c.
>>
>> Note: On BSD, after exit a file is left in current directory
>>       with the pipe's name. The "up" script was modified to
>>       delete this file before and after the tgtd load.
>>       (File name is: TGT_IPC_ABSTRACT_NAMESPACE)
>>
>> Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
>> ---
>>  usr/bsd/os.c   |   14 ++++++++++++++
>>  usr/linux/os.c |   10 ++++++++++
>>  usr/mgmt.c     |    6 ++----
>>  usr/os.h       |    3 +++
>>  4 files changed, 29 insertions(+), 4 deletions(-)
> 
> Hmm, the following patch seems to work on both Linux and FreeBSD 7.1
> for me.
> 
> Yeah, I installed FreeBSD 7.1 to try to write the better patches.
> 
> 
> diff --git a/usr/mgmt.c b/usr/mgmt.c
> index 5351b2c..47c8820 100644
> --- a/usr/mgmt.c
> +++ b/usr/mgmt.c
> @@ -562,8 +562,7 @@ int ipc_init(void)
>  
>  	memset(&addr, 0, sizeof(addr));
>  	addr.sun_family = AF_LOCAL;
> -	memcpy((char *) &addr.sun_path + 1, TGT_IPC_NAMESPACE,
> -	       strlen(TGT_IPC_NAMESPACE));
> +	strncpy(addr.sun_path, TGT_IPC_NAMESPACE, sizeof(addr.sun_path));
>  
>  	err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
>  	if (err) {
> diff --git a/usr/tgtadm.c b/usr/tgtadm.c
> index 6280c99..71d7fc5 100644
> --- a/usr/tgtadm.c
> +++ b/usr/tgtadm.c
> @@ -182,8 +182,7 @@ static int ipc_mgmt_connect(int *fd)
>  
>  	memset(&addr, 0, sizeof(addr));
>  	addr.sun_family = AF_LOCAL;
> -	memcpy((char *) &addr.sun_path + 1, TGT_IPC_NAMESPACE,
> -	       strlen(TGT_IPC_NAMESPACE));
> +	strncpy(addr.sun_path, TGT_IPC_NAMESPACE, sizeof(addr.sun_path));
>  
>  	err = connect(*fd, (struct sockaddr *) &addr, sizeof(addr));
>  	if (err < 0)


Sure, thanks
  I did not want to change the Linux code, I have no experience
with IPC code, I thought it is important to have zero at first char,
otherwise why is it there?

Feel free to replace the patch with this one

Ack-by: Boaz Harrosh <bharrosh at panasas.com>
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list