]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add a way to return FDs to the RPC caller
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Dec 2012 14:18:28 +0000 (14:18 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 8 Jan 2013 08:56:49 +0000 (08:56 +0000)
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 <berrange@redhat.com>
src/rpc/virnetserverprogram.c

index 3ac38092ffee57087aa47b720b06a59f273b7e01..06b6325de68e6cb6c4faeb4dd2372c4a4b9d2785 100644 (file)
@@ -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);