]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote: create virNetServerServiceNewFDOrUNIX() wrapper
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 15 Jul 2014 12:37:14 +0000 (14:37 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Fri, 22 Aug 2014 07:12:13 +0000 (09:12 +0200)
It's just a wrapper around NewFD and NewUNIX that selects the right
option and increments the number of used FDs.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/libvirt_remote.syms
src/rpc/virnetserverservice.c
src/rpc/virnetserverservice.h

index d482a55833ab23b3606d3a67b784a2c6d4184bd6..6b520b5fa923fbfc71bb09980bd39640bd37c5cc 100644 (file)
@@ -159,6 +159,7 @@ virNetServerServiceGetMaxRequests;
 virNetServerServiceGetPort;
 virNetServerServiceIsReadonly;
 virNetServerServiceNewFD;
+virNetServerServiceNewFDOrUNIX;
 virNetServerServiceNewPostExecRestart;
 virNetServerServiceNewTCP;
 virNetServerServiceNewUNIX;
index 320a02c8f23b5132e9c1092ff69c8a7d005be4f6..e85889b78f6eb623c1b4dde648ce0608c8973452 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virnetserverservice.c: generic network RPC server service
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2012, 2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -25,6 +25,8 @@
 
 #include "virnetserverservice.h"
 
+#include <unistd.h>
+
 #include "viralloc.h"
 #include "virerror.h"
 #include "virthread.h"
@@ -90,6 +92,52 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
 }
 
 
+virNetServerServicePtr
+virNetServerServiceNewFDOrUNIX(const char *path,
+                               mode_t mask,
+                               gid_t grp,
+                               int auth,
+#if WITH_GNUTLS
+                               virNetTLSContextPtr tls,
+#endif
+                               bool readonly,
+                               size_t max_queued_clients,
+                               size_t nrequests_client_max,
+                               unsigned int nfds,
+                               unsigned int *cur_fd)
+{
+    if (*cur_fd - STDERR_FILENO > nfds) {
+        /*
+         * There are no more file descriptors to use, so we have to
+         * fallback to UNIX socket.
+         */
+        return virNetServerServiceNewUNIX(path,
+                                          mask,
+                                          grp,
+                                          auth,
+#if WITH_GNUTLS
+                                          tls,
+#endif
+                                          readonly,
+                                          max_queued_clients,
+                                          nrequests_client_max);
+
+    } else {
+        /*
+         * There's still enough file descriptors.  In this case we'll
+         * use the current one and increment it afterwards.
+         */
+        return virNetServerServiceNewFD(*cur_fd++,
+                                        auth,
+#if WITH_GNUTLS
+                                        tls,
+#endif
+                                        readonly,
+                                        nrequests_client_max);
+    }
+}
+
+
 virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
                                                  const char *service,
                                                  int auth,
index eb31abfb0f0d348ef0ea3985d92c450ce1eaa6d2..a1c89605aeab1f321c43c82fb096566855030dcc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virnetserverservice.h: generic network RPC server service
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2011, 2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -37,6 +37,18 @@ typedef int (*virNetServerServiceDispatchFunc)(virNetServerServicePtr svc,
                                                virNetSocketPtr sock,
                                                void *opaque);
 
+virNetServerServicePtr virNetServerServiceNewFDOrUNIX(const char *path,
+                                                      mode_t mask,
+                                                      gid_t grp,
+                                                      int auth,
+# if WITH_GNUTLS
+                                                      virNetTLSContextPtr tls,
+# endif
+                                                      bool readonly,
+                                                      size_t max_queued_clients,
+                                                      size_t nrequests_client_max,
+                                                      unsigned int nfds,
+                                                      unsigned int *cur_fd);
 virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
                                                  const char *service,
                                                  int auth,