gni_serv_local uses checked_copy which uses memcpy to create the destination name derived from strlen. With abstract sockets however the serv starts with '\0', according to unix(7) can contain '\0'. This leads to a rather serv description. Its hard to say what the desired behavior is as the serv is a null string on the API. A memcpy of the real length is probably a start. My solution currently has some assumptions (however its good enough for me). getnameinfo_err= getnameinfo(&addr.sa, addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV); if (getnameinfo_err) sql_print_warning("getnameinfo() on systemd socket activation socket %d" " failed with error %d", fd, getnameinfo_err); else { /* handle abstract sockets and present them in @ form */ if (sbuf[0] == '\0') addr.un.sun_path[0] = '@'; sql_print_information("Using systemd activated socket %s port %s", hbuf, sbuf[0] == '\0' ? addr.un.sun_path : sbuf); }
A memcpy of the real length could simply the (at least my) user space code to: if (sbuf[0] == '\0') sbuf[0] = '@'; The use of this buffer has some assumptions about if other nulls are in the sun_path buffer. The length of this in memcpy can be derived from the argument addrlen - offsetof(struct sockaddr_un, sun_path). A manual page document document using this as the length if sbuf[0] = '\0' could be useful in allowing a more fully featured use in userspace for this edge case. Both of these changes, it should be able to use the serv/sbuf with abstract sockets, despite detracting a bit in the interface from the protocol independence it aimed to provide.
patch: https://sourceware.org/pipermail/libc-alpha/2021-March/124459.html disclaimer form requested.