diff options
author | Keith Packard <keithp@keithp.com> | 2013-01-17 13:43:02 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-10-31 16:58:25 -0700 |
commit | 9fd35daa3160fd36f00ed354bfcbefefa1353cce (patch) | |
tree | 26c9cb45b4302c46b2edd8206a5bf7e3b7cbdd47 /os/io.c | |
parent | 264fc3abe5f18341d0cf9ddb6766e10e4154e447 (diff) |
Add interfaces to get FDs from clients over the socket
This adds two interfaces:
void SetReqFds(ClientPtr client, int req_fds)
Marks the number of file descriptors expected for this
request. Call this before any request processing so that
any un-retrieved file descriptors will be closed
automatically.
int ReadFdFromClient(ClientPtr client)
Reads the next queued file descriptor from the connection. If
this request is not expecting any more file descriptors, or
if there are no more file descriptors available from the
connection, then this will return -1.
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'os/io.c')
-rw-r--r-- | os/io.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -259,6 +259,12 @@ ReadRequestFromClient(ClientPtr client) oc->input = oci; } + /* Discard any unused file descriptors */ + while (client->req_fds > 0) { + int req_fd = ReadFdFromClient(client); + if (req_fd >= 0) + close(req_fd); + } /* advance to start of next request */ oci->bufptr += oci->lenLastReq; @@ -485,6 +491,21 @@ ReadRequestFromClient(ClientPtr client) return needed; } +int +ReadFdFromClient(ClientPtr client) +{ + int fd = -1; + + if (client->req_fds > 0) { + OsCommPtr oc = (OsCommPtr) client->osPrivate; + + --client->req_fds; + fd = _XSERVTransRecvFd(oc->trans_conn); + } else + LogMessage(X_ERROR, "Request asks for FD without setting req_fds\n"); + return fd; +} + /***************************************************************** * InsertFakeRequest * Splice a consed up (possibly partial) request in as the next request. |