2010-12-01 16:36:40 +00:00
|
|
|
/*
|
|
|
|
* virnetserverservice.c: generic network RPC server service
|
|
|
|
*
|
2014-07-15 12:37:14 +00:00
|
|
|
* Copyright (C) 2006-2012, 2014 Red Hat, Inc.
|
2010-12-01 16:36:40 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-01 16:36:40 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "virnetserverservice.h"
|
|
|
|
|
2014-07-15 12:37:14 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
#include "virthread.h"
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
|
|
|
|
|
|
|
struct _virNetServerService {
|
2012-07-11 13:35:52 +00:00
|
|
|
virObject object;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
size_t nsocks;
|
|
|
|
virNetSocketPtr *socks;
|
|
|
|
|
|
|
|
int auth;
|
|
|
|
bool readonly;
|
2011-06-30 10:45:55 +00:00
|
|
|
size_t nrequests_client_max;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetTLSContextPtr tls;
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
virNetServerServiceDispatchFunc dispatchFunc;
|
|
|
|
void *dispatchOpaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
static virClassPtr virNetServerServiceClass;
|
|
|
|
static void virNetServerServiceDispose(void *obj);
|
|
|
|
|
|
|
|
static int virNetServerServiceOnceInit(void)
|
|
|
|
{
|
2013-01-09 17:37:27 +00:00
|
|
|
if (!(virNetServerServiceClass = virClassNew(virClassForObject(),
|
|
|
|
"virNetServerService",
|
2012-07-11 13:35:52 +00:00
|
|
|
sizeof(virNetServerService),
|
|
|
|
virNetServerServiceDispose)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(virNetServerService)
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
static void virNetServerServiceAccept(virNetSocketPtr sock,
|
|
|
|
int events ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virNetServerServicePtr svc = opaque;
|
|
|
|
virNetSocketPtr clientsock = NULL;
|
|
|
|
|
|
|
|
if (virNetSocketAccept(sock, &clientsock) < 0)
|
2012-08-09 11:06:45 +00:00
|
|
|
goto cleanup;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (!clientsock) /* Connection already went away */
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!svc->dispatchFunc)
|
2012-08-09 11:06:45 +00:00
|
|
|
goto cleanup;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-08-09 11:06:45 +00:00
|
|
|
svc->dispatchFunc(svc, clientsock, svc->dispatchOpaque);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
cleanup:
|
2012-08-09 11:06:45 +00:00
|
|
|
virObjectUnref(clientsock);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-15 12:37:14 +00:00
|
|
|
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
|
2014-08-28 13:03:47 +00:00
|
|
|
* use the current one and increment it afterwards. Take care
|
|
|
|
* with order of operation for pointer arithmetic and auto
|
|
|
|
* increment on cur_fd - the parentheses are necessary.
|
2014-07-15 12:37:14 +00:00
|
|
|
*/
|
2014-08-28 13:03:47 +00:00
|
|
|
return virNetServerServiceNewFD((*cur_fd)++,
|
2014-07-15 12:37:14 +00:00
|
|
|
auth,
|
|
|
|
#if WITH_GNUTLS
|
|
|
|
tls,
|
|
|
|
#endif
|
|
|
|
readonly,
|
2014-07-16 17:26:16 +00:00
|
|
|
max_queued_clients,
|
2014-07-15 12:37:14 +00:00
|
|
|
nrequests_client_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
|
|
|
const char *service,
|
2015-05-21 14:51:28 +00:00
|
|
|
int family,
|
2010-12-01 16:36:40 +00:00
|
|
|
int auth,
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2013-01-07 14:54:18 +00:00
|
|
|
virNetTLSContextPtr tls,
|
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
bool readonly,
|
2013-07-25 12:45:38 +00:00
|
|
|
size_t max_queued_clients,
|
2013-01-07 14:54:18 +00:00
|
|
|
size_t nrequests_client_max)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
virNetServerServicePtr svc;
|
|
|
|
size_t i;
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
svc->auth = auth;
|
|
|
|
svc->readonly = readonly;
|
2011-06-30 10:45:55 +00:00
|
|
|
svc->nrequests_client_max = nrequests_client_max;
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2012-07-11 13:35:48 +00:00
|
|
|
svc->tls = virObjectRef(tls);
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (virNetSocketNewListenTCP(nodename,
|
|
|
|
service,
|
2015-05-21 14:51:28 +00:00
|
|
|
family,
|
2010-12-01 16:36:40 +00:00
|
|
|
&svc->socks,
|
|
|
|
&svc->nsocks) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2013-07-25 12:45:38 +00:00
|
|
|
if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0)
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (virNetSocketAddIOCallback(svc->socks[i],
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
2011-07-19 13:11:33 +00:00
|
|
|
svc,
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectFreeCallback) < 0) {
|
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
2011-07-19 13:11:33 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
|
|
|
|
mode_t mask,
|
|
|
|
gid_t grp,
|
|
|
|
int auth,
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2013-01-07 14:54:18 +00:00
|
|
|
virNetTLSContextPtr tls,
|
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
bool readonly,
|
2013-07-25 12:45:38 +00:00
|
|
|
size_t max_queued_clients,
|
2013-01-07 14:54:18 +00:00
|
|
|
size_t nrequests_client_max)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
virNetServerServicePtr svc;
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
svc->auth = auth;
|
|
|
|
svc->readonly = readonly;
|
2011-06-30 10:45:55 +00:00
|
|
|
svc->nrequests_client_max = nrequests_client_max;
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2012-07-11 13:35:48 +00:00
|
|
|
svc->tls = virObjectRef(tls);
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2017-02-09 14:13:38 +00:00
|
|
|
if (VIR_ALLOC_N(svc->socks, 1) < 0)
|
2013-07-04 10:15:05 +00:00
|
|
|
goto error;
|
2017-02-09 14:13:38 +00:00
|
|
|
svc->nsocks = 1;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (virNetSocketNewListenUNIX(path,
|
|
|
|
mask,
|
2011-08-12 09:10:19 +00:00
|
|
|
-1,
|
2010-12-01 16:36:40 +00:00
|
|
|
grp,
|
|
|
|
&svc->socks[0]) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2013-07-25 12:45:38 +00:00
|
|
|
if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0)
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (virNetSocketAddIOCallback(svc->socks[i],
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
2011-07-19 13:11:33 +00:00
|
|
|
svc,
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectFreeCallback) < 0) {
|
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
2011-07-19 13:11:33 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2010-12-01 16:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:09:19 +00:00
|
|
|
virNetServerServicePtr virNetServerServiceNewFD(int fd,
|
|
|
|
int auth,
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2013-01-07 14:54:18 +00:00
|
|
|
virNetTLSContextPtr tls,
|
|
|
|
#endif
|
2012-08-09 14:09:19 +00:00
|
|
|
bool readonly,
|
2014-07-16 17:26:16 +00:00
|
|
|
size_t max_queued_clients,
|
2013-01-07 14:54:18 +00:00
|
|
|
size_t nrequests_client_max)
|
2012-08-09 14:09:19 +00:00
|
|
|
{
|
|
|
|
virNetServerServicePtr svc;
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-08-09 14:09:19 +00:00
|
|
|
|
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
svc->auth = auth;
|
|
|
|
svc->readonly = readonly;
|
|
|
|
svc->nrequests_client_max = nrequests_client_max;
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2012-08-09 14:09:19 +00:00
|
|
|
svc->tls = virObjectRef(tls);
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2012-08-09 14:09:19 +00:00
|
|
|
|
2017-02-09 14:13:38 +00:00
|
|
|
if (VIR_ALLOC_N(svc->socks, 1) < 0)
|
2013-07-04 10:15:05 +00:00
|
|
|
goto error;
|
2017-02-09 14:13:38 +00:00
|
|
|
svc->nsocks = 1;
|
2012-08-09 14:09:19 +00:00
|
|
|
|
|
|
|
if (virNetSocketNewListenFD(fd,
|
|
|
|
&svc->socks[0]) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2014-07-16 17:26:16 +00:00
|
|
|
if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-08-09 14:09:19 +00:00
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
2015-06-04 17:18:56 +00:00
|
|
|
virObjectRef(svc);
|
2012-08-09 14:09:19 +00:00
|
|
|
if (virNetSocketAddIOCallback(svc->socks[i],
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
|
|
|
svc,
|
2015-06-04 17:18:56 +00:00
|
|
|
virObjectFreeCallback) < 0) {
|
|
|
|
virObjectUnref(svc);
|
2012-08-09 14:09:19 +00:00
|
|
|
goto error;
|
2015-06-04 17:18:56 +00:00
|
|
|
}
|
2012-08-09 14:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-08-09 14:09:19 +00:00
|
|
|
virObjectUnref(svc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr object)
|
|
|
|
{
|
|
|
|
virNetServerServicePtr svc;
|
|
|
|
virJSONValuePtr socks;
|
|
|
|
size_t i;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n;
|
2012-10-26 20:28:40 +00:00
|
|
|
unsigned int max;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (virNetServerServiceInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(object, "auth", &svc->auth) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing auth field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(object, "readonly", &svc->readonly) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing readonly field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberUint(object, "nrequests_client_max",
|
2012-10-26 20:28:40 +00:00
|
|
|
&max) < 0) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing nrequests_client_max field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
2012-10-26 20:28:40 +00:00
|
|
|
svc->nrequests_client_max = max;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (!(socks = virJSONValueObjectGet(object, "socks"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing socks field in JSON state document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((n = virJSONValueArraySize(socks)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("socks field in JSON was not an array"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2017-02-09 14:13:38 +00:00
|
|
|
if (VIR_ALLOC_N(svc->socks, n) < 0)
|
2012-08-09 11:54:54 +00:00
|
|
|
goto error;
|
2017-02-09 14:13:38 +00:00
|
|
|
svc->nsocks = n;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(socks, i);
|
|
|
|
virNetSocketPtr sock;
|
|
|
|
|
|
|
|
if (!(sock = virNetSocketNewPostExecRestart(child))) {
|
|
|
|
virObjectUnref(sock);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
svc->socks[i] = sock;
|
|
|
|
|
|
|
|
/* IO callback is initially disabled, until we're ready
|
|
|
|
* to deal with incoming clients */
|
|
|
|
virObjectRef(svc);
|
|
|
|
if (virNetSocketAddIOCallback(sock,
|
|
|
|
0,
|
|
|
|
virNetServerServiceAccept,
|
|
|
|
svc,
|
|
|
|
virObjectFreeCallback) < 0) {
|
|
|
|
virObjectUnref(svc);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return svc;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-08-09 11:54:54 +00:00
|
|
|
virObjectUnref(svc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virJSONValuePtr virNetServerServicePreExecRestart(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
virJSONValuePtr object = virJSONValueNewObject();
|
|
|
|
virJSONValuePtr socks;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendNumberInt(object, "auth", svc->auth) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virJSONValueObjectAppendBoolean(object, "readonly", svc->readonly) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virJSONValueObjectAppendNumberUint(object, "nrequests_client_max", svc->nrequests_client_max) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2013-01-09 14:54:12 +00:00
|
|
|
if (!(socks = virJSONValueNewArray()))
|
|
|
|
goto error;
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectAppend(object, "socks", socks) < 0) {
|
|
|
|
virJSONValueFree(socks);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virJSONValuePtr child;
|
|
|
|
if (!(child = virNetSocketPreExecRestart(svc->socks[i])))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueArrayAppend(socks, child) < 0) {
|
|
|
|
virJSONValueFree(child);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-08-09 11:54:54 +00:00
|
|
|
virJSONValueFree(object);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 17:11:42 +00:00
|
|
|
int virNetServerServiceGetPort(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
/* We're assuming if there are multiple sockets
|
|
|
|
* for IPv4 & 6, then they are all on same port */
|
|
|
|
return virNetSocketGetPort(svc->socks[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
int virNetServerServiceGetAuth(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
return svc->auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool virNetServerServiceIsReadonly(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
return svc->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-09 11:06:45 +00:00
|
|
|
size_t virNetServerServiceGetMaxRequests(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
return svc->nrequests_client_max;
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2012-08-09 11:06:45 +00:00
|
|
|
virNetTLSContextPtr virNetServerServiceGetTLSContext(virNetServerServicePtr svc)
|
|
|
|
{
|
|
|
|
return svc->tls;
|
|
|
|
}
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2012-08-09 11:06:45 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
|
|
|
virNetServerServiceDispatchFunc func,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
svc->dispatchFunc = func;
|
|
|
|
svc->dispatchOpaque = opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
void virNetServerServiceDispose(void *obj)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2012-07-11 13:35:52 +00:00
|
|
|
virNetServerServicePtr svc = obj;
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++)
|
2017-02-09 14:13:38 +00:00
|
|
|
virObjectUnref(svc->socks[i]);
|
2010-12-01 16:36:40 +00:00
|
|
|
VIR_FREE(svc->socks);
|
|
|
|
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2012-07-11 13:35:48 +00:00
|
|
|
virObjectUnref(svc->tls);
|
2013-01-07 14:54:18 +00:00
|
|
|
#endif
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void virNetServerServiceToggle(virNetServerServicePtr svc,
|
|
|
|
bool enabled)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++)
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetSocketUpdateIOCallback(svc->socks[i],
|
|
|
|
enabled ?
|
|
|
|
VIR_EVENT_HANDLE_READABLE :
|
|
|
|
0);
|
|
|
|
}
|
2011-08-04 08:54:58 +00:00
|
|
|
|
|
|
|
void virNetServerServiceClose(virNetServerServicePtr svc)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/rpc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-08-04 08:54:58 +00:00
|
|
|
|
|
|
|
if (!svc)
|
|
|
|
return;
|
|
|
|
|
2015-06-18 12:37:43 +00:00
|
|
|
for (i = 0; i < svc->nsocks; i++) {
|
|
|
|
virNetSocketRemoveIOCallback(svc->socks[i]);
|
2011-08-04 08:54:58 +00:00
|
|
|
virNetSocketClose(svc->socks[i]);
|
2015-06-18 12:37:43 +00:00
|
|
|
virObjectUnref(svc);
|
|
|
|
}
|
2011-08-04 08:54:58 +00:00
|
|
|
}
|