From 3fd121c170b8d2fcd78f367d036bde0632c6828c Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 21 Dec 2012 14:18:28 +0000 Subject: [PATCH] Add a way to return FDs to the RPC caller Currently the libvirt client can pass FDs to the server, but the dispatch mechanism provides no way to return FDs back from the server to the client. Tweak the dispatch code, such that if a dispatcher returns '1', this indicates that it populated the virNetMessagePtr with FDs to return Signed-off-by: Daniel P. Berrange --- src/rpc/virnetserverprogram.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 3ac38092ff..06b6325de6 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -431,17 +431,20 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog, rv = (dispatcher->func)(server, client, msg, &rerr, arg, ret); /* - * Clear out the FDs we got from the client, we don't - * want to send them back ! + * If rv == 1, this indicates the dispatch func has + * populated 'msg' with a list of FDs to return to + * the caller. + * + * Otherwise we must clear out the FDs we got from + * the client originally. * - * XXX we don't have a way to let dispatcher->func - * return any FDs. Fortunately we don't need this - * capability just yet */ - for (i = 0 ; i < msg->nfds ; i++) - VIR_FORCE_CLOSE(msg->fds[i]); - VIR_FREE(msg->fds); - msg->nfds = 0; + if (rv != 1) { + for (i = 0 ; i < msg->nfds ; i++) + VIR_FORCE_CLOSE(msg->fds[i]); + VIR_FREE(msg->fds); + msg->nfds = 0; + } xdr_free(dispatcher->arg_filter, arg);