mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
rpc: remove "spawnDaemon" parameter
The "spawnDaemon" and "binary" parameters are co-dependant, with the latter non-NULL, if-and-only-if the former is true. Getting rid of the "spawnDaemon" parameter simplifies life for the callers and eliminates an error checking scenario. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
46980c29ef
commit
48f66cfe3e
@ -222,7 +222,7 @@ remoteAdminPrivNew(const char *sock_path)
|
|||||||
if (!(priv = virObjectLockableNew(remoteAdminPrivClass)))
|
if (!(priv = virObjectLockableNew(remoteAdminPrivClass)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(priv->client = virNetClientNewUNIX(sock_path, false, NULL)))
|
if (!(priv->client = virNetClientNewUNIX(sock_path, NULL)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
|
if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
|
||||||
|
@ -208,7 +208,6 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool privileged,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(client = virNetClientNewUNIX(lockdpath,
|
if (!(client = virNetClientNewUNIX(lockdpath,
|
||||||
daemonPath != NULL,
|
|
||||||
daemonPath)))
|
daemonPath)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ virLogManagerConnect(bool privileged,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(client = virNetClientNewUNIX(logdpath,
|
if (!(client = virNetClientNewUNIX(logdpath,
|
||||||
daemonPath != NULL,
|
|
||||||
daemonPath)))
|
daemonPath)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ virLXCMonitor *virLXCMonitorNew(virDomainObj *vm,
|
|||||||
|
|
||||||
sockpath = g_strdup_printf("%s/%s.sock", socketdir, vm->def->name);
|
sockpath = g_strdup_printf("%s/%s.sock", socketdir, vm->def->name);
|
||||||
|
|
||||||
if (!(mon->client = virNetClientNewUNIX(sockpath, false, NULL)))
|
if (!(mon->client = virNetClientNewUNIX(sockpath, NULL)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virNetClientRegisterAsyncIO(mon->client) < 0)
|
if (virNetClientRegisterAsyncIO(mon->client) < 0)
|
||||||
|
@ -3761,8 +3761,7 @@ qemuMigrationSrcConnect(virQEMUDriver *driver,
|
|||||||
break;
|
break;
|
||||||
case MIGRATION_DEST_CONNECT_SOCKET:
|
case MIGRATION_DEST_CONNECT_SOCKET:
|
||||||
if (virNetSocketNewConnectUNIX(spec->dest.socket.path,
|
if (virNetSocketNewConnectUNIX(spec->dest.socket.path,
|
||||||
false, NULL,
|
NULL, &sock) == 0) {
|
||||||
&sock) == 0) {
|
|
||||||
fd_qemu = virNetSocketDupFD(sock, true);
|
fd_qemu = virNetSocketDupFD(sock, true);
|
||||||
virObjectUnref(sock);
|
virObjectUnref(sock);
|
||||||
}
|
}
|
||||||
|
@ -1022,7 +1022,6 @@ doRemoteOpen(virConnectPtr conn,
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
case REMOTE_DRIVER_TRANSPORT_UNIX:
|
case REMOTE_DRIVER_TRANSPORT_UNIX:
|
||||||
if (!(priv->client = virNetClientNewUNIX(sockname,
|
if (!(priv->client = virNetClientNewUNIX(sockname,
|
||||||
flags & REMOTE_DRIVER_OPEN_AUTOSTART,
|
|
||||||
daemon_path)))
|
daemon_path)))
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
|
@ -431,8 +431,7 @@ int main(int argc, char **argv)
|
|||||||
flags,
|
flags,
|
||||||
&daemon_path);
|
&daemon_path);
|
||||||
|
|
||||||
if (virNetSocketNewConnectUNIX(sock_path, flags & REMOTE_DRIVER_OPEN_AUTOSTART,
|
if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) {
|
||||||
daemon_path, &sock) < 0) {
|
|
||||||
g_printerr(_("%s: cannot connect to '%s': %s\n"),
|
g_printerr(_("%s: cannot connect to '%s': %s\n"),
|
||||||
argv[0], sock_path, virGetLastErrorMessage());
|
argv[0], sock_path, virGetLastErrorMessage());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -366,12 +366,11 @@ virNetClientFindDefaultSshKey(const char *homedir, char **retPath)
|
|||||||
|
|
||||||
|
|
||||||
virNetClient *virNetClientNewUNIX(const char *path,
|
virNetClient *virNetClientNewUNIX(const char *path,
|
||||||
bool spawnDaemon,
|
const char *spawnDaemonPath)
|
||||||
const char *binary)
|
|
||||||
{
|
{
|
||||||
virNetSocket *sock;
|
virNetSocket *sock;
|
||||||
|
|
||||||
if (virNetSocketNewConnectUNIX(path, spawnDaemon, binary, &sock) < 0)
|
if (virNetSocketNewConnectUNIX(path, spawnDaemonPath, &sock) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return virNetClientNew(sock, NULL);
|
return virNetClientNew(sock, NULL);
|
||||||
|
@ -48,8 +48,7 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy,
|
|||||||
bool readonly);
|
bool readonly);
|
||||||
|
|
||||||
virNetClient *virNetClientNewUNIX(const char *path,
|
virNetClient *virNetClientNewUNIX(const char *path,
|
||||||
bool spawnDaemon,
|
const char *spawnDaemonPath);
|
||||||
const char *binary);
|
|
||||||
|
|
||||||
virNetClient *virNetClientNewTCP(const char *nodename,
|
virNetClient *virNetClientNewTCP(const char *nodename,
|
||||||
const char *service,
|
const char *service,
|
||||||
|
@ -664,8 +664,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
|
|||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int virNetSocketNewConnectUNIX(const char *path,
|
int virNetSocketNewConnectUNIX(const char *path,
|
||||||
bool spawnDaemon,
|
const char *spawnDaemonPath,
|
||||||
const char *binary,
|
|
||||||
virNetSocket **retsock)
|
virNetSocket **retsock)
|
||||||
{
|
{
|
||||||
char *lockpath = NULL;
|
char *lockpath = NULL;
|
||||||
@ -678,25 +677,15 @@ int virNetSocketNewConnectUNIX(const char *path,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool daemonLaunched = false;
|
bool daemonLaunched = false;
|
||||||
|
|
||||||
VIR_DEBUG("path=%s spawnDaemon=%d binary=%s", path, spawnDaemon,
|
VIR_DEBUG("path=%s spawnDaemonPath=%s", path, NULLSTR(spawnDaemonPath));
|
||||||
NULLSTR(binary));
|
|
||||||
|
|
||||||
memset(&localAddr, 0, sizeof(localAddr));
|
memset(&localAddr, 0, sizeof(localAddr));
|
||||||
memset(&remoteAddr, 0, sizeof(remoteAddr));
|
memset(&remoteAddr, 0, sizeof(remoteAddr));
|
||||||
|
|
||||||
remoteAddr.len = sizeof(remoteAddr.data.un);
|
remoteAddr.len = sizeof(remoteAddr.data.un);
|
||||||
|
|
||||||
if (spawnDaemon) {
|
if (spawnDaemonPath) {
|
||||||
g_autofree char *binname = NULL;
|
g_autofree char *binname = g_path_get_basename(spawnDaemonPath);
|
||||||
|
|
||||||
if (!binary) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Auto-spawn of daemon requested, "
|
|
||||||
"but no binary specified"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
binname = g_path_get_basename(binary);
|
|
||||||
rundir = virGetUserRuntimeDirectory();
|
rundir = virGetUserRuntimeDirectory();
|
||||||
|
|
||||||
if (g_mkdir_with_parents(rundir, 0700) < 0) {
|
if (g_mkdir_with_parents(rundir, 0700) < 0) {
|
||||||
@ -741,7 +730,7 @@ int virNetSocketNewConnectUNIX(const char *path,
|
|||||||
VIR_DEBUG("connect() failed: retries=%d errno=%d", retries, errno);
|
VIR_DEBUG("connect() failed: retries=%d errno=%d", retries, errno);
|
||||||
|
|
||||||
retries--;
|
retries--;
|
||||||
if (!spawnDaemon ||
|
if (!spawnDaemonPath ||
|
||||||
retries == 0 ||
|
retries == 0 ||
|
||||||
(errno != ENOENT && errno != ECONNREFUSED)) {
|
(errno != ENOENT && errno != ECONNREFUSED)) {
|
||||||
virReportSystemError(errno, _("Failed to connect socket to '%s'"),
|
virReportSystemError(errno, _("Failed to connect socket to '%s'"),
|
||||||
@ -750,7 +739,7 @@ int virNetSocketNewConnectUNIX(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!daemonLaunched) {
|
if (!daemonLaunched) {
|
||||||
if (virNetSocketForkDaemon(binary) < 0)
|
if (virNetSocketForkDaemon(spawnDaemonPath) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
daemonLaunched = true;
|
daemonLaunched = true;
|
||||||
@ -785,8 +774,7 @@ int virNetSocketNewConnectUNIX(const char *path,
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int virNetSocketNewConnectUNIX(const char *path G_GNUC_UNUSED,
|
int virNetSocketNewConnectUNIX(const char *path G_GNUC_UNUSED,
|
||||||
bool spawnDaemon G_GNUC_UNUSED,
|
const char *spawnDaemonPath,
|
||||||
const char *binary G_GNUC_UNUSED,
|
|
||||||
virNetSocket **retsock G_GNUC_UNUSED)
|
virNetSocket **retsock G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virReportSystemError(ENOSYS, "%s",
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
@ -65,8 +65,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
|
|||||||
virNetSocket **addr);
|
virNetSocket **addr);
|
||||||
|
|
||||||
int virNetSocketNewConnectUNIX(const char *path,
|
int virNetSocketNewConnectUNIX(const char *path,
|
||||||
bool spawnDaemon,
|
const char *spawnDaemonPath,
|
||||||
const char *binary,
|
|
||||||
virNetSocket **addr);
|
virNetSocket **addr);
|
||||||
|
|
||||||
int virNetSocketNewConnectCommand(virCommand *cmd,
|
int virNetSocketNewConnectCommand(virCommand *cmd,
|
||||||
|
@ -131,7 +131,7 @@ testSocketClient(void *opaque)
|
|||||||
virNetSocket *csock = NULL;
|
virNetSocket *csock = NULL;
|
||||||
|
|
||||||
if (data->path) {
|
if (data->path) {
|
||||||
if (virNetSocketNewConnectUNIX(data->path, false,
|
if (virNetSocketNewConnectUNIX(data->path,
|
||||||
NULL, &csock) < 0)
|
NULL, &csock) < 0)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -339,7 +339,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
|
|||||||
if (virNetSocketListen(lsock, 0) < 0)
|
if (virNetSocketListen(lsock, 0) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virNetSocketNewConnectUNIX(path, false, NULL, &csock) < 0)
|
if (virNetSocketNewConnectUNIX(path, NULL, &csock) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STRNEQ(virNetSocketLocalAddrStringSASL(csock), "127.0.0.1;0")) {
|
if (STRNEQ(virNetSocketLocalAddrStringSASL(csock), "127.0.0.1;0")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user