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:
Daniel P. Berrangé 2021-05-24 15:07:19 +01:00
parent 46980c29ef
commit 48f66cfe3e
12 changed files with 17 additions and 37 deletions

View File

@ -222,7 +222,7 @@ remoteAdminPrivNew(const char *sock_path)
if (!(priv = virObjectLockableNew(remoteAdminPrivClass)))
goto error;
if (!(priv->client = virNetClientNewUNIX(sock_path, false, NULL)))
if (!(priv->client = virNetClientNewUNIX(sock_path, NULL)))
goto error;
if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,

View File

@ -208,7 +208,6 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool privileged,
goto error;
if (!(client = virNetClientNewUNIX(lockdpath,
daemonPath != NULL,
daemonPath)))
goto error;

View File

@ -79,7 +79,6 @@ virLogManagerConnect(bool privileged,
goto error;
if (!(client = virNetClientNewUNIX(logdpath,
daemonPath != NULL,
daemonPath)))
goto error;

View File

@ -151,7 +151,7 @@ virLXCMonitor *virLXCMonitorNew(virDomainObj *vm,
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;
if (virNetClientRegisterAsyncIO(mon->client) < 0)

View File

@ -3761,8 +3761,7 @@ qemuMigrationSrcConnect(virQEMUDriver *driver,
break;
case MIGRATION_DEST_CONNECT_SOCKET:
if (virNetSocketNewConnectUNIX(spec->dest.socket.path,
false, NULL,
&sock) == 0) {
NULL, &sock) == 0) {
fd_qemu = virNetSocketDupFD(sock, true);
virObjectUnref(sock);
}

View File

@ -1022,7 +1022,6 @@ doRemoteOpen(virConnectPtr conn,
#ifndef WIN32
case REMOTE_DRIVER_TRANSPORT_UNIX:
if (!(priv->client = virNetClientNewUNIX(sockname,
flags & REMOTE_DRIVER_OPEN_AUTOSTART,
daemon_path)))
goto failed;

View File

@ -431,8 +431,7 @@ int main(int argc, char **argv)
flags,
&daemon_path);
if (virNetSocketNewConnectUNIX(sock_path, flags & REMOTE_DRIVER_OPEN_AUTOSTART,
daemon_path, &sock) < 0) {
if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) {
g_printerr(_("%s: cannot connect to '%s': %s\n"),
argv[0], sock_path, virGetLastErrorMessage());
exit(EXIT_FAILURE);

View File

@ -366,12 +366,11 @@ virNetClientFindDefaultSshKey(const char *homedir, char **retPath)
virNetClient *virNetClientNewUNIX(const char *path,
bool spawnDaemon,
const char *binary)
const char *spawnDaemonPath)
{
virNetSocket *sock;
if (virNetSocketNewConnectUNIX(path, spawnDaemon, binary, &sock) < 0)
if (virNetSocketNewConnectUNIX(path, spawnDaemonPath, &sock) < 0)
return NULL;
return virNetClientNew(sock, NULL);

View File

@ -48,8 +48,7 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy,
bool readonly);
virNetClient *virNetClientNewUNIX(const char *path,
bool spawnDaemon,
const char *binary);
const char *spawnDaemonPath);
virNetClient *virNetClientNewTCP(const char *nodename,
const char *service,

View File

@ -664,8 +664,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
#ifndef WIN32
int virNetSocketNewConnectUNIX(const char *path,
bool spawnDaemon,
const char *binary,
const char *spawnDaemonPath,
virNetSocket **retsock)
{
char *lockpath = NULL;
@ -678,25 +677,15 @@ int virNetSocketNewConnectUNIX(const char *path,
int ret = -1;
bool daemonLaunched = false;
VIR_DEBUG("path=%s spawnDaemon=%d binary=%s", path, spawnDaemon,
NULLSTR(binary));
VIR_DEBUG("path=%s spawnDaemonPath=%s", path, NULLSTR(spawnDaemonPath));
memset(&localAddr, 0, sizeof(localAddr));
memset(&remoteAddr, 0, sizeof(remoteAddr));
remoteAddr.len = sizeof(remoteAddr.data.un);
if (spawnDaemon) {
g_autofree char *binname = NULL;
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);
if (spawnDaemonPath) {
g_autofree char *binname = g_path_get_basename(spawnDaemonPath);
rundir = virGetUserRuntimeDirectory();
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);
retries--;
if (!spawnDaemon ||
if (!spawnDaemonPath ||
retries == 0 ||
(errno != ENOENT && errno != ECONNREFUSED)) {
virReportSystemError(errno, _("Failed to connect socket to '%s'"),
@ -750,7 +739,7 @@ int virNetSocketNewConnectUNIX(const char *path,
}
if (!daemonLaunched) {
if (virNetSocketForkDaemon(binary) < 0)
if (virNetSocketForkDaemon(spawnDaemonPath) < 0)
goto cleanup;
daemonLaunched = true;
@ -785,8 +774,7 @@ int virNetSocketNewConnectUNIX(const char *path,
}
#else
int virNetSocketNewConnectUNIX(const char *path G_GNUC_UNUSED,
bool spawnDaemon G_GNUC_UNUSED,
const char *binary G_GNUC_UNUSED,
const char *spawnDaemonPath,
virNetSocket **retsock G_GNUC_UNUSED)
{
virReportSystemError(ENOSYS, "%s",

View File

@ -65,8 +65,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
virNetSocket **addr);
int virNetSocketNewConnectUNIX(const char *path,
bool spawnDaemon,
const char *binary,
const char *spawnDaemonPath,
virNetSocket **addr);
int virNetSocketNewConnectCommand(virCommand *cmd,

View File

@ -131,7 +131,7 @@ testSocketClient(void *opaque)
virNetSocket *csock = NULL;
if (data->path) {
if (virNetSocketNewConnectUNIX(data->path, false,
if (virNetSocketNewConnectUNIX(data->path,
NULL, &csock) < 0)
return;
} else {
@ -339,7 +339,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
if (virNetSocketListen(lsock, 0) < 0)
goto cleanup;
if (virNetSocketNewConnectUNIX(path, false, NULL, &csock) < 0)
if (virNetSocketNewConnectUNIX(path, NULL, &csock) < 0)
goto cleanup;
if (STRNEQ(virNetSocketLocalAddrStringSASL(csock), "127.0.0.1;0")) {