mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
connection: return INVALID for invalid fds
This commit is contained in:
parent
2f28e59c63
commit
7ad111de47
1 changed files with 11 additions and 7 deletions
|
|
@ -83,6 +83,9 @@ int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *c
|
||||||
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
|
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
|
||||||
struct buffer *buf = &impl->in;
|
struct buffer *buf = &impl->in;
|
||||||
|
|
||||||
|
if (index == SPA_ID_INVALID)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (index >= buf->msg.n_fds)
|
if (index >= buf->msg.n_fds)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
|
|
@ -93,7 +96,7 @@ int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *c
|
||||||
*
|
*
|
||||||
* \param conn the connection
|
* \param conn the connection
|
||||||
* \param fd the fd to add
|
* \param fd the fd to add
|
||||||
* \return the index of the fd or -1 when an error occured
|
* \return the index of the fd or SPA_IDX_INVALID when an error occured
|
||||||
*
|
*
|
||||||
* \memberof pw_protocol_native_connection
|
* \memberof pw_protocol_native_connection
|
||||||
*/
|
*/
|
||||||
|
|
@ -103,6 +106,9 @@ uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connecti
|
||||||
struct buffer *buf = &impl->out;
|
struct buffer *buf = &impl->out;
|
||||||
uint32_t index, i;
|
uint32_t index, i;
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
return SPA_IDX_INVALID;
|
||||||
|
|
||||||
for (i = 0; i < buf->msg.n_fds; i++) {
|
for (i = 0; i < buf->msg.n_fds; i++) {
|
||||||
if (buf->msg.fds[i] == fd)
|
if (buf->msg.fds[i] == fd)
|
||||||
return i;
|
return i;
|
||||||
|
|
@ -111,7 +117,7 @@ uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connecti
|
||||||
index = buf->msg.n_fds;
|
index = buf->msg.n_fds;
|
||||||
if (index + buf->n_fds >= MAX_FDS) {
|
if (index + buf->n_fds >= MAX_FDS) {
|
||||||
pw_log_error("connection %p: too many fds", conn);
|
pw_log_error("connection %p: too many fds", conn);
|
||||||
return -1;
|
return SPA_IDX_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->msg.fds[index] = fd;
|
buf->msg.fds[index] = fd;
|
||||||
|
|
@ -447,8 +453,8 @@ int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *co
|
||||||
struct iovec iov[1];
|
struct iovec iov[1];
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
char cmsgbuf[CMSG_SPACE(MAX_FDS_MSG * sizeof(int))];
|
char cmsgbuf[CMSG_SPACE(MAX_FDS_MSG * sizeof(int))];
|
||||||
int *cm, res = 0, *fds;
|
int res = 0, *fds;
|
||||||
uint32_t i, fds_len, n_fds, outfds;
|
uint32_t fds_len, n_fds, outfds;
|
||||||
struct buffer *buf;
|
struct buffer *buf;
|
||||||
void *data;
|
void *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
@ -482,9 +488,7 @@ int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *co
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
cmsg->cmsg_type = SCM_RIGHTS;
|
cmsg->cmsg_type = SCM_RIGHTS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(fds_len);
|
cmsg->cmsg_len = CMSG_LEN(fds_len);
|
||||||
cm = (int *) CMSG_DATA(cmsg);
|
memcpy(CMSG_DATA(cmsg), fds, cmsg->cmsg_len);
|
||||||
for (i = 0; i < outfds; i++)
|
|
||||||
cm[i] = fds[i] > 0 ? fds[i] : -fds[i];
|
|
||||||
msg.msg_controllen = cmsg->cmsg_len;
|
msg.msg_controllen = cmsg->cmsg_len;
|
||||||
} else {
|
} else {
|
||||||
msg.msg_control = NULL;
|
msg.msg_control = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue