tree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhere
The macro determines the right length of a AF_UNIX "struct sockaddr_un" to pass to connect() or bind(). It automatically figures out if the socket refers to an abstract namespace socket, or a socket in the file system, and properly handles the full length of the path field. This macro is not only safer, but also simpler to use, than the usual offsetof() + strlen() logic.
This commit is contained in:
@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
l = strlen(argv[1]);
|
||||
|
||||
n = sendto(fd, argv[1], l, 0, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
|
||||
n = sendto(fd, argv[1], l, 0, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
||||
if (n < 0) {
|
||||
log_debug_errno(errno, "Failed to send cgroups agent message: %m");
|
||||
return EXIT_FAILURE;
|
||||
|
||||
Reference in New Issue
Block a user