swtpm: Implement ctrlchannel_set_client_fd()

Implement ctrlchannel_set_client_fd() to set a new client
fd and return its current value.

Use this new function to set the file descriptor to -1 upon
closing its associate file descriptor in the main loop.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2017-10-16 13:02:01 -04:00 committed by Stefan Berger
parent 75f9f0d300
commit aa3999d387
3 changed files with 11 additions and 0 deletions

View File

@ -101,6 +101,15 @@ int ctrlchannel_get_client_fd(struct ctrlchannel *cc)
return cc->clientfd;
}
int ctrlchannel_set_client_fd(struct ctrlchannel *cc, int fd)
{
int clientfd = cc->clientfd;
cc->clientfd = fd;
return clientfd;
}
static int ctrlchannel_return_state(ptm_getstate *pgs, int fd)
{
uint32_t blobtype = be32toh(pgs->u.req.type);

View File

@ -47,6 +47,7 @@ struct mainLoopParams;
struct ctrlchannel *ctrlchannel_new(int fd, bool isclient);
int ctrlchannel_get_fd(struct ctrlchannel *cc);
int ctrlchannel_get_client_fd(struct ctrlchannel *cc);
int ctrlchannel_set_client_fd(struct ctrlchannel *cc, int fd);
int ctrlchannel_process_fd(int fd,
struct libtpms_callbacks *cbs,
bool *terminate,

View File

@ -262,6 +262,7 @@ skip_process:
if (ctrlclntfd >= 0)
close(ctrlclntfd);
ctrlchannel_set_client_fd(mlp->cc, -1);
if (mlp->fd >= 0) {
close(mlp->fd);