net.Listen("unix", ...) permission denied

486 views
Skip to first unread message

Roberto Zanotto

unread,
Jan 5, 2016, 12:58:25 PM1/5/16
to golang-nuts
Hi everyone.

I don't have experience with socket, I assume I'm missing something.
To start a unix domain socket server (on linux x64), I do the following:

sockDir := "/tmp/mydir"
if _, err = os.Stat(sockDir); os.IsNotExist(err) {
os.Mkdir(sockDir, os.ModeDir)
}
sockName := sockDir + "/" + "mysocket"
ln, err := net.Listen("unix", sockName)

I get: listen unix /tmp/mydir/mysocket: bind: permission denied
Should I create the file for the socket first? With which flags and permissions? Or maybe I shouldn't be doing this in tmp?

Thanks

Alex Skinner

unread,
Jan 5, 2016, 1:44:45 PM1/5/16
to golang-nuts
Look at the permission of /tmp/mydir, it's likely 000.  Change os.ModeDir to 0755 (for example) above to allow your user access to the directory.

Alex

Roberto Zanotto

unread,
Jan 5, 2016, 1:48:08 PM1/5/16
to golang-nuts
I totally missed the part of the least significant bits in os.FileMode. Thanks :)
Reply all
Reply to author
Forward
0 new messages