socket: support setting ownership of message queues

This applies the existing SocketUser=/SocketGroup= options to units
defining a POSIX message queue, bringing them in line with UNIX
sockets and FIFOs.  They are set on the file descriptor rather than
a file system path because the /dev/mqueue path interface is an
optional mount unit.
This commit is contained in:
David Michael
2024-10-28 23:40:42 +01:00
committed by Lennart Poettering
parent 2b7a56d286
commit 3eec82f6b3
3 changed files with 58 additions and 5 deletions
+8
View File
@@ -2024,6 +2024,14 @@ static int socket_chown(Socket *s, PidRef *ret_pid) {
path = socket_address_get_path(&p->address);
else if (p->type == SOCKET_FIFO)
path = p->path;
else if (p->type == SOCKET_MQUEUE) {
/* Use fchown on the fd since /dev/mqueue might not be mounted. */
if (fchown(p->fd, uid, gid) < 0) {
log_unit_error_errno(UNIT(s), errno, "Failed to fchown(): %m");
_exit(EXIT_CHOWN);
}
continue;
}
if (!path)
continue;