if (m->notify_fd < 0) {
_cleanup_close_ int fd = -1;
- union sockaddr_union sa = {
- .sa.sa_family = AF_UNIX,
- };
+ union sockaddr_union sa = {};
static const int one = 1;
+ int salen;
/* First free all secondary fields */
m->notify_socket = mfree(m->notify_socket);
if (!m->notify_socket)
return log_oom();
+ salen = sockaddr_un_set_path(&sa.un, m->notify_socket);
+ if (salen < 0)
+ return log_error_errno(salen, "Notify socket '%s' not valid for AF_UNIX socket address, refusing.", m->notify_socket);
+
(void) mkdir_parents_label(m->notify_socket, 0755);
(void) unlink(m->notify_socket);
- strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path));
- r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
+ r = bind(fd, &sa.sa, salen);
if (r < 0)
- return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
+ return log_error_errno(errno, "bind(%s) failed: %m", m->notify_socket);
r = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
if (r < 0)