goto cleanup;
}
-static virDrvOpenStatus
-remoteOpen (virConnectPtr conn,
- virConnectAuthPtr auth,
- int flags)
+static struct private_data *
+remoteAllocPrivateData(virConnectPtr conn)
{
struct private_data *priv;
- int ret, rflags = 0;
-
- if (inside_daemon)
- return VIR_DRV_OPEN_DECLINED;
-
if (VIR_ALLOC(priv) < 0) {
- virReportOOMError (conn);
- return VIR_DRV_OPEN_ERROR;
+ virReportOOMError(conn);
+ return NULL;
}
if (virMutexInit(&priv->lock) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot initialize mutex"));
VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
+ return NULL;
}
remoteDriverLock(priv);
priv->localUses = 1;
priv->watch = -1;
+ priv->sock = -1;
+
+ return priv;
+}
+
+static int
+remoteOpenSecondaryDriver(virConnectPtr conn,
+ virConnectAuthPtr auth,
+ int flags,
+ struct private_data **priv)
+{
+ int ret;
+ int rflags = 0;
+
+ if (!((*priv) = remoteAllocPrivateData(conn)))
+ return VIR_DRV_OPEN_ERROR;
+
+ if (flags & VIR_CONNECT_RO)
+ rflags |= VIR_DRV_OPEN_REMOTE_RO;
+ rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
+
+ ret = doRemoteOpen(conn, *priv, auth, rflags);
+ if (ret != VIR_DRV_OPEN_SUCCESS) {
+ remoteDriverUnlock(*priv);
+ VIR_FREE(*priv);
+ } else {
+ (*priv)->localUses = 1;
+ remoteDriverUnlock(*priv);
+ }
+
+ return ret;
+}
+
+static virDrvOpenStatus
+remoteOpen (virConnectPtr conn,
+ virConnectAuthPtr auth,
+ int flags)
+{
+ struct private_data *priv;
+ int ret, rflags = 0;
+
+ if (inside_daemon)
+ return VIR_DRV_OPEN_DECLINED;
+
+ if (!(priv = remoteAllocPrivateData(conn)))
+ return VIR_DRV_OPEN_ERROR;
if (flags & VIR_CONNECT_RO)
rflags |= VIR_DRV_OPEN_REMOTE_RO;
#endif
}
- priv->sock = -1;
ret = doRemoteOpen(conn, priv, auth, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->privateData = NULL;
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- virReportOOMError (conn);
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->networkPrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->networkPrivateData = priv;
- }
return ret;
}
}
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- virReportOOMError (NULL);
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->storagePrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->storagePrivateData = priv;
- }
return ret;
}
}
* which doesn't have its own impl of the network APIs.
*/
struct private_data *priv;
- int ret, rflags = 0;
- if (VIR_ALLOC(priv) < 0) {
- virReportOOMError (NULL);
- return VIR_DRV_OPEN_ERROR;
- }
- if (virMutexInit(&priv->lock) < 0) {
- error(conn, VIR_ERR_INTERNAL_ERROR,
- _("cannot initialize mutex"));
- VIR_FREE(priv);
- return VIR_DRV_OPEN_ERROR;
- }
- if (flags & VIR_CONNECT_RO)
- rflags |= VIR_DRV_OPEN_REMOTE_RO;
- rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
-
- priv->sock = -1;
- ret = doRemoteOpen(conn, priv, auth, rflags);
- if (ret != VIR_DRV_OPEN_SUCCESS) {
- conn->devMonPrivateData = NULL;
- VIR_FREE(priv);
- } else {
- priv->localUses = 1;
+ int ret;
+ ret = remoteOpenSecondaryDriver(conn,
+ auth,
+ flags,
+ &priv);
+ if (ret == VIR_DRV_OPEN_SUCCESS)
conn->devMonPrivateData = priv;
- }
return ret;
}
}
thiscall->err.domain == VIR_FROM_REMOTE &&
thiscall->err.code == VIR_ERR_RPC &&
thiscall->err.level == VIR_ERR_ERROR &&
+ thiscall->err.message &&
STRPREFIX(*thiscall->err.message, "unknown procedure")) {
rv = -2;
} else {
&thiscall->err);
rv = -1;
}
+ xdr_free((xdrproc_t)xdr_remote_error, (char *)&thiscall->err);
} else {
rv = 0;
}
freeaddrinfo (res);
if (!priv->addrlen) {
- virReportSystemError(conn, saved_errno,
- _("unable to connect to '%s:%s'"),
- host, port);
+ /* Don't raise error when unprivileged, since proxy takes over */
+ if (xenHavePrivilege())
+ virReportSystemError(conn, saved_errno,
+ _("unable to connect to '%s:%s'"),
+ host, port);
return -1;
}
* @flags: combination of virDrvOpenFlag(s)
*
* Creates a localhost Xen Daemon connection
- * Note: this doesn't try to check if the connection actually works
*
* Returns 0 in case of success, -1 in case of error.
*/
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
{
- int ret;
+ char *port = NULL;
+ int ret = VIR_DRV_OPEN_ERROR;
/* Switch on the scheme, which we expect to be NULL (file),
* "http" or "xen".
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
goto failed;
}
- ret = xenDaemonOpen_unix(conn, conn->uri->path);
- if (ret < 0)
- goto failed;
-
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+ if (xenDaemonOpen_unix(conn, conn->uri->path) < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
}
else if (STRCASEEQ (conn->uri->scheme, "xen")) {
/*
* try first to open the unix socket
*/
- ret = xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket");
- if (ret < 0)
- goto try_http;
- ret = xend_detect_config_version(conn);
- if (ret != -1)
+ if (xenDaemonOpen_unix(conn, "/var/lib/xend/xend-socket") == 0 &&
+ xend_detect_config_version(conn) != -1)
goto done;
- try_http:
/*
* try though http on port 8000
*/
- ret = xenDaemonOpen_tcp(conn, "localhost", "8000");
- if (ret < 0)
- goto failed;
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+ if (xenDaemonOpen_tcp(conn, "localhost", "8000") < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
} else if (STRCASEEQ (conn->uri->scheme, "http")) {
- char *port;
if (virAsprintf(&port, "%d", conn->uri->port) == -1)
goto failed;
- ret = xenDaemonOpen_tcp(conn, conn->uri->server, port);
- VIR_FREE(port);
- if (ret < 0)
- goto failed;
- ret = xend_detect_config_version(conn);
- if (ret == -1)
+
+ if (xenDaemonOpen_tcp(conn, conn->uri->server, port) < 0 ||
+ xend_detect_config_version(conn) == -1)
goto failed;
} else {
virXendError(NULL, VIR_ERR_NO_CONNECT, __FUNCTION__);
}
done:
- return(ret);
+ ret = VIR_DRV_OPEN_SUCCESS;
failed:
- return(-1);
+ VIR_FREE(port);
+ return ret;
}