logind-session-dbus: use fd_vet_accmode() where appropriate

This commit is contained in:
Mike Yuan
2025-11-11 19:41:11 +01:00
parent 2c5d73660e
commit 51bb3a0932

View File

@@ -531,8 +531,8 @@ static int method_set_display(sd_bus_message *message, void *userdata, sd_bus_er
static int method_set_tty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Session *s = ASSERT_PTR(userdata);
int fd, r, flags;
_cleanup_free_ char *q = NULL;
int fd, r;
assert(message);
@@ -543,15 +543,11 @@ static int method_set_tty(sd_bus_message *message, void *userdata, sd_bus_error
if (!session_is_controller(s, sd_bus_message_get_sender(message)))
return sd_bus_error_set(error, BUS_ERROR_NOT_IN_CONTROL, "You must be in control of this session to set tty");
assert(fd >= 0);
flags = fcntl(fd, F_GETFL, 0);
if (flags < 0)
return -errno;
if ((flags & O_ACCMODE_STRICT) != O_RDWR)
r = fd_vet_accmode(fd, O_RDWR);
if (r == -EPROTOTYPE)
return -EACCES;
if (FLAGS_SET(flags, O_PATH))
return -ENOTTY;
if (r < 0)
return r;
r = getttyname_malloc(fd, &q);
if (r < 0)