oeffis: handle fcntl failures correctly

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
This commit is contained in:
Peter Hutterer 2026-05-11 11:45:09 +10:00 committed by Marge Bot
parent 7d42a95d12
commit 62ac026432

View file

@ -327,7 +327,6 @@ xdp_session_path(char *sender_name, char *token)
static int
connect_to_eis_returned(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{
int eisfd;
struct oeffis *oeffis = userdata;
int rc = sd_bus_message_get_errno(m);
@ -336,27 +335,37 @@ connect_to_eis_returned(sd_bus_message *m, void *userdata, sd_bus_error *ret_err
return rc;
}
rc = sd_bus_message_read(m, "h", &eisfd);
int sd_eisfd;
rc = sd_bus_message_read(m, "h", &sd_eisfd);
if (rc < 0) {
oeffis_disconnect(oeffis, "Unable to get fd from portal: %s", strerror(-rc));
return -rc;
}
/* the fd is owned by the message */
rc = xerrno(xdup(eisfd));
if (rc < 0) {
oeffis_disconnect(oeffis, "Failed to dup fd: %s", strerror(-rc));
return -rc;
_cleanup_close_ int eisfd = xerrno(xdup(sd_eisfd));
if (eisfd < 0) {
oeffis_disconnect(oeffis, "Failed to dup fd: %s", strerror(-eisfd));
return -eisfd;
} else {
eisfd = rc;
int flags = fcntl(eisfd, F_GETFL, 0);
fcntl(eisfd, F_SETFL, flags | O_NONBLOCK);
int flags = xerrno(fcntl(eisfd, F_GETFL, 0));
if (flags >= 0)
rc = xerrno(fcntl(eisfd, F_SETFL, flags | O_NONBLOCK));
else
rc = flags;
if (rc < 0) {
oeffis_disconnect(oeffis,
"Failed to set the fd to non-blocking: %s",
strerror(-rc));
return -rc;
}
}
log_debug("Got fd %d from portal", eisfd);
rc = oeffis_set_eis_fd(oeffis, eisfd);
rc = oeffis_set_eis_fd(oeffis, steal_fd(&eisfd));
if (rc < 0) {
oeffis_disconnect(oeffis, "Failed to set the fd: %s", strerror(-rc));
return -rc;