virnetmessage: Introduce virNetMessageClearFDs

The helper splits out the clearing of the FDs transacted inside a
virNetMessage.

APIs transacting FDs both from and to the client at the same time will
need to clear the FDs stored in virNetMessage as the structure is
re-used for the reply and without clearing the list of FDs we'd return
the FDs sent by the client in addition to the new FDs sent by the API.t

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-02-17 17:07:39 +01:00
parent 3c4b49e871
commit 7cfbfe66fc
3 changed files with 10 additions and 1 deletions

View File

@ -102,6 +102,7 @@ virNetDaemonUpdateServices;
# rpc/virnetmessage.h
virNetMessageAddFD;
virNetMessageClear;
virNetMessageClearFDs;
virNetMessageClearPayload;
virNetMessageDecodeHeader;
virNetMessageDecodeLength;

View File

@ -48,7 +48,7 @@ virNetMessage *virNetMessageNew(bool tracked)
void
virNetMessageClearPayload(virNetMessage *msg)
virNetMessageClearFDs(virNetMessage *msg)
{
size_t i;
@ -58,6 +58,13 @@ virNetMessageClearPayload(virNetMessage *msg)
msg->donefds = 0;
msg->nfds = 0;
VIR_FREE(msg->fds);
}
void
virNetMessageClearPayload(virNetMessage *msg)
{
virNetMessageClearFDs(msg);
msg->bufferOffset = 0;
msg->bufferLength = 0;

View File

@ -49,6 +49,7 @@ struct _virNetMessage {
virNetMessage *virNetMessageNew(bool tracked);
void virNetMessageClearFDs(virNetMessage *msg);
void virNetMessageClearPayload(virNetMessage *msg);
void virNetMessageClear(virNetMessage *);