mirror of
https://github.com/systemd/systemd.git
synced 2026-08-03 22:50:29 +00:00
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:
@@ -105,7 +105,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) {
|
||||
|
||||
uctrl->saddr.un.sun_family = AF_LOCAL;
|
||||
strscpy(uctrl->saddr.un.sun_path, sizeof(uctrl->saddr.un.sun_path), "/run/udev/control");
|
||||
uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.un.sun_path);
|
||||
uctrl->addrlen = SOCKADDR_UN_LEN(uctrl->saddr.un);
|
||||
return uctrl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user