Abstract paths for Unix sockets on Linux

1,287 views
Skip to first unread message

Rémy Oudompheng

unread,
Mar 18, 2012, 4:56:41 AM3/18/12
to golang-nuts
Hello,

Linux supports a special addressing scheme for Unix domain sockets,
"abstract path", that avoids polluting the file system with
unnecessary entries.
I was wondering how to do that in Go and discovered that I had to
prefix the path name by "@" (digging through old issues and source
code).

Is that a well-spread convention? unix(7) manpage only says "the
address must begin with a NUL byte" but /proc/net/unix shows "@"
instead of the NUL byte.
I was wondering if the feature needed documentation or if users should
be able to guess by themselves.

package main

import (
"net"
"time"
)

func client() {
net.Dial("unix", "@/tmp/secret")
time.Sleep(time.Hour)
}

func main() {
go client()
c, _ := net.Listen("unix", "@/tmp/secret")
c.Accept()
time.Sleep(time.Hour)
}

Albert Strasheim

unread,
Mar 18, 2012, 5:24:14 AM3/18/12
to golan...@googlegroups.com
Hello

On Sunday, March 18, 2012 10:56:41 AM UTC+2, Rémy Oudompheng wrote:

Linux supports a special addressing scheme for Unix domain sockets,
"abstract path", that avoids polluting the file system with
unnecessary entries.
I was wondering how to do that in Go and discovered that I had to
prefix the path name by "@" (digging through old issues and source
code).

Is that a well-spread convention? unix(7) manpage only says "the
address must begin with a NUL byte" but /proc/net/unix shows "@"
instead of the NUL byte.
I was wondering if the feature needed documentation or if users should
be able to guess by themselves.


I would say it's a relatively well-known convention, but it should probably be documented.

Here is what systemd's systemd.socket manual page says on the topic:

"If the address starts with an at symbol (@) it is read as abstract namespace socket in the AF_UNIX family. The @ is replaced with a NUL character before binding."

Regards

Albert
Reply all
Reply to author
Forward
0 new messages