# Updated support for unix socket in abstract namespace

**URL:** <https://www.ruby-forum.com/t/updated-support-for-unix-socket-in-abstract-namespace/207848>\
**Category:** NGINX\
**Created:** [June 4, 2011, 7:28am UTC](https://www.ruby-forum.com/t/updated-support-for-unix-socket-in-abstract-namespace/207848 "2011-06-04T07:28:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 4, 2011, 7:28am UTC](https://www.ruby-forum.com/t/updated-support-for-unix-socket-in-abstract-namespace/207848/1 "2011-06-04T07:28:38Z")

</div>

Hi all,  
attached there is an updated patch for adding support for unix socket in  
abstract namespace.

As requested by Igor, the syntax is now

unix:\0foobar

instead of

unix:@foobar

The only relevant note is this part of code:

- if (saun-\>sun\_path[0] != ‘\0’) {
- 

```
   u->addrs[0].socklen = sizeof(struct sockaddr_un);

```

- }
- else {
- 

```
   u->addrs[0].socklen = sizeof(saun->sun_family) + len;

```

- }

it looks like using

u-\>addrs[0].socklen = sizeof(saun-\>sun\_family) + len;

is not reliable in all os (NetBSD and OpenBSD in my tests did not work)  
so  
i think  
an exception (as i did) is more “secure”.

Probably, as linux is the only os supporting abstract namespace, we  
could  
use:

#ifdef **linux**  
u-\>addrs[0].socklen = sizeof(saun-\>sun\_family) + len;  
#else  
u-\>addrs[0].socklen = sizeof(struct sockaddr\_un);  
#endif

---

<div class="post-metadata">

**Author:** ![Roberto\_De\_Ioris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@Roberto\_De\_Ioris](https://www.ruby-forum.com/u/Roberto_De_Ioris)\
**Post date:** [June 4, 2011, 7:49am UTC](https://www.ruby-forum.com/t/updated-support-for-unix-socket-in-abstract-namespace/207848/2 "2011-06-04T07:49:36Z")

</div>

On Sat, Jun 04, 2011 at 07:27:07AM +0200, Roberto De Ioris wrote:

> unix:@foobar
> 
> #ifdef **linux**  
> u-\>addrs[0].socklen = sizeof(saun-\>sun\_family) + len;  
> #else  
> u-\>addrs[0].socklen = sizeof(struct sockaddr\_un);  
> #endif

Thank you for the patch, I will look how to resolve this on all  
platforms.  
The one issue remains - how to log this address in error\_log.  
My first thought was to use “@foobar” as Linux does, but now I think  
it’s better to create a name with slash “\0foobar”.

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Roberto\_De\_Ioris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@Roberto\_De\_Ioris](https://www.ruby-forum.com/u/Roberto_De_Ioris)\
**Post date:** [June 4, 2011, 8:21am UTC](https://www.ruby-forum.com/t/updated-support-for-unix-socket-in-abstract-namespace/207848/3 "2011-06-04T08:21:02Z")

</div>

> > Probably, as linux is the only os supporting abstract namespace, we  
> > The one issue remains - how to log this address in error\_log.  
> > My first thought was to use “@foobar” as Linux does, but now I think  
> > it’s better to create a name with slash “\0foobar”.

I would suggest \0 for sure. Users can be fooled by different naming  
scheme.  
I have added support in uWSGI for \0 too, to avoid this sort of  
problems.

–  
Roberto De Ioris

> **[unbit - Overview](https://github.com/unbit)**
>
> makers of uWSGI and many more open source projects - unbit
