On 10/22/19 10:57 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/rpc/virnetclient.c | 12 ++++++------
src/rpc/virnetlibsshsession.c | 8 ++++----
src/rpc/virnetsocket.c | 2 +-
src/rpc/virnetsshsession.c | 11 ++++++-----
src/rpc/virnettlscontext.c | 26 +++++++++++++-------------
5 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index a423f4db2f..47a17d30f7 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -343,7 +343,7 @@ virNetClientCheckKeyExists(const char *homedir,
{
char *path;
- virAsprintf(&path, "%s/.ssh/%s", homedir, name);
+ path = g_strdup_printf("%s/.ssh/%s", homedir, name);
if (!(virFileExists(path))) {
VIR_FREE(path);
@@ -565,7 +565,7 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
} else {
confdir = virGetUserConfigDirectory();
if (confdir)
- virAsprintf(&knownhosts, "%s/known_hosts", confdir);
+ knownhosts = g_strdup_printf("%s/known_hosts", confdir);
}
if (privkeyPath) {
@@ -599,10 +599,10 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
if (!(nc = virBufferContentAndReset(&buf)))
goto no_memory;
- virAsprintf(&command, "sh -c "
- "'if '%s' -q 2>&1 | grep \"requires an
argument\" >/dev/null 2>&1; then "
- "ARG=-q0;" "else " "ARG=;" "fi;"
"'%s' $ARG -U %s'", nc, nc,
- socketPath);
+ command = g_strdup_printf("sh -c "
+ "'if '%s' -q 2>&1 | grep
\"requires an argument\" >/dev/null 2>&1; then "
+ "ARG=-q0;" "else " "ARG=;"
"fi;" "'%s' $ARG -U %s'", nc, nc,
+ socketPath);
if (virNetSocketNewConnectLibssh(host, port,
family,
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 4a9f976914..2fcc606993 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -341,9 +341,9 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess)
if (!keyhashstr)
return -1;
- virAsprintf(&tmp,
- _("Accept SSH host key with hash '%s' for "
"host '%s:%d' (%s/%s)?"),
- keyhashstr, sess->hostname, sess->port, "y",
"n");
+ tmp = g_strdup_printf(
+ _("Accept SSH host key with hash '%s' for
" "host '%s:%d' (%s/%s)?"),
+ keyhashstr, sess->hostname, sess->port,
"y", "n");
Extra line break after '('.
askKey.prompt = tmp;
if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) {
@@ -524,7 +524,7 @@ virNetLibsshAuthenticatePrivkey(virNetLibsshSessionPtr sess,
VIR_DEBUG("sess=%p", sess);
- virAsprintf(&tmp, "%s.pub", priv->filename);
+ tmp = g_strdup_printf("%s.pub", priv->filename);
/* try to open the public part of the private key */
ret = ssh_pki_import_pubkey_file(tmp, &public_key);
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 2b66bc609b..f2623c58ef 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -698,7 +698,7 @@ int virNetSocketNewConnectUNIX(const char *path,
goto cleanup;
}
- virAsprintf(&lockpath, "%s/%s.lock", rundir, binname);
+ lockpath = g_strdup_printf("%s/%s.lock", rundir, binname);
if ((lockfd = open(lockpath, O_RDWR | O_CREAT, 0600)) < 0 ||
virSetCloseExec(lockfd) < 0) {
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index 384bedfc34..5b87581b62 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -365,9 +365,10 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
keyhashstr = virBufferContentAndReset(&buff);
askKey.type = VIR_CRED_ECHOPROMPT;
- virAsprintf((char **)&askKey.prompt,
- _("Accept SSH host key with hash '%s' for "
"host '%s:%d' (%s/%s)?"),
- keyhashstr, sess->hostname, sess->port, "y",
"n");
+ askKey.prompt = g_strdup_printf(_("Accept SSH host key with hash
'%s' for " "host '%s:%d' (%s/%s)?"),
+ keyhashstr,
+ sess->hostname,
+ sess->port, "y",
"n");
Since the g_strdup_printf() line is already on the large side, I prefer
putting the parameters together in the next line - Like it is already
being done up there where I complained about the extra line break.
Reviewed-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>