allow abstract unix sockets
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 14 Apr 2017 13:36:53 +0000 (15:36 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 14 Apr 2017 13:36:53 +0000 (15:36 +0200)
unix sockets named "unix:@something" are now treated
as abstract sockets.

Change-Id: Ieb2bb9dd1c7b420b9e3fae81590ef49c32f63802
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-ws.c

index 56682dd..ba9a18a 100644 (file)
@@ -281,7 +281,7 @@ static int api_ws_socket_unix(const char *path, int server)
                return -1;
        }
 
-       if (server)
+       if (server && path[0] != '@')
                unlink(path);
 
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -291,6 +291,8 @@ static int api_ws_socket_unix(const char *path, int server)
        memset(&addr, 0, sizeof addr);
        addr.sun_family = AF_UNIX;
        strcpy(addr.sun_path, path);
+       if (addr.sun_path[0] == '@')
+               addr.sun_path[0] = 0; /* implement abstract sockets */
        if (server) {
                rc = bind(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
        } else {