[PATCH 21/75] rpc: Drop virAsprintf() and virAsprintfQuiet() retval checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These functions can't fail really. Drop checking of their retval
then.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/rpc/virnetclient.c        | 23 +++++++--------------
 src/rpc/virnetlibsshsession.c | 17 ++++-----------
 src/rpc/virnetsocket.c        |  3 +--
 src/rpc/virnetsshsession.c    | 18 +++++-----------
 src/rpc/virnettlscontext.c    | 39 ++++++++++++-----------------------
 5 files changed, 30 insertions(+), 70 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 678e6f7815..a423f4db2f 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -343,8 +343,7 @@ virNetClientCheckKeyExists(const char *homedir,
 {
     char *path;
 
-    if (virAsprintf(&path, "%s/.ssh/%s", homedir, name) < 0)
-        return -1;
+    virAsprintf(&path, "%s/.ssh/%s", homedir, name);
 
     if (!(virFileExists(path))) {
         VIR_FREE(path);
@@ -565,10 +564,8 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
         knownhosts = g_strdup(knownHostsPath);
     } else {
         confdir = virGetUserConfigDirectory();
-        if (confdir) {
-            if (virAsprintf(&knownhosts, "%s/known_hosts", confdir) < 0)
-                goto cleanup;
-        }
+        if (confdir)
+            virAsprintf(&knownhosts, "%s/known_hosts", confdir);
     }
 
     if (privkeyPath) {
@@ -602,16 +599,10 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
     if (!(nc = virBufferContentAndReset(&buf)))
         goto no_memory;
 
-    if (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) < 0)
-        goto cleanup;
+    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);
 
     if (virNetSocketNewConnectLibssh(host, port,
                                      family,
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 0b98236f38..4a9f976914 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -341,15 +341,9 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess)
             if (!keyhashstr)
                 return -1;
 
-            if (virAsprintf(&tmp,
-                            _("Accept SSH host key with hash '%s' for "
-                              "host '%s:%d' (%s/%s)?"),
-                            keyhashstr,
-                            sess->hostname, sess->port,
-                            "y", "n") < 0) {
-                ssh_string_free_char(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");
             askKey.prompt = tmp;
 
             if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) {
@@ -530,10 +524,7 @@ virNetLibsshAuthenticatePrivkey(virNetLibsshSessionPtr sess,
 
     VIR_DEBUG("sess=%p", sess);
 
-    if (virAsprintf(&tmp, "%s.pub", priv->filename) < 0) {
-        err = SSH_AUTH_ERROR;
-        goto error;
-    }
+    virAsprintf(&tmp, "%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 6574ee0d16..2b66bc609b 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -698,8 +698,7 @@ int virNetSocketNewConnectUNIX(const char *path,
             goto cleanup;
         }
 
-        if (virAsprintf(&lockpath, "%s/%s.lock", rundir, binname) < 0)
-            goto cleanup;
+        virAsprintf(&lockpath, "%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 931c7091cc..384bedfc34 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -365,15 +365,9 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
             keyhashstr = virBufferContentAndReset(&buff);
 
             askKey.type = VIR_CRED_ECHOPROMPT;
-            if (virAsprintf((char **)&askKey.prompt,
-                            _("Accept SSH host key with hash '%s' for "
-                              "host '%s:%d' (%s/%s)?"),
-                            keyhashstr,
-                            sess->hostname, sess->port,
-                            "y", "n") < 0) {
-                VIR_FREE(keyhashstr);
-                return -1;
-            }
+            virAsprintf((char **)&askKey.prompt,
+                        _("Accept SSH host key with hash '%s' for " "host '%s:%d' (%s/%s)?"),
+                        keyhashstr, sess->hostname, sess->port, "y", "n");
 
             if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) {
                 virReportError(VIR_ERR_SSH, "%s",
@@ -634,10 +628,8 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
         return -1;
     }
 
-    if (virAsprintf((char **)&retr_passphrase.prompt,
-                    _("Passphrase for key '%s'"),
-                    priv->filename) < 0)
-        return -1;
+    virAsprintf((char **)&retr_passphrase.prompt,
+                _("Passphrase for key '%s'"), priv->filename);
 
     if (sess->cred->cb(&retr_passphrase, 1, sess->cred->cbdata)) {
         virReportError(VIR_ERR_SSH, "%s",
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 2420ad8681..af6d29b376 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -796,19 +796,13 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
      */
     if (pkipath) {
         VIR_DEBUG("Told to use TLS credentials in %s", pkipath);
-        if ((virAsprintf(cacert, "%s/%s", pkipath,
-                         "cacert.pem")) < 0)
-            goto error;
-        if ((virAsprintf(cacrl, "%s/%s", pkipath,
-                         "cacrl.pem")) < 0)
-            goto error;
-        if ((virAsprintf(key, "%s/%s", pkipath,
-                         isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
-            goto error;
+        virAsprintf(cacert, "%s/%s", pkipath, "cacert.pem");
+        virAsprintf(cacrl, "%s/%s", pkipath, "cacrl.pem");
+        virAsprintf(key, "%s/%s", pkipath,
+                    isServer ? "serverkey.pem" : "clientkey.pem");
 
-        if ((virAsprintf(cert, "%s/%s", pkipath,
-                         isServer ? "servercert.pem" : "clientcert.pem")) < 0)
-             goto error;
+        virAsprintf(cert, "%s/%s", pkipath,
+                    isServer ? "servercert.pem" : "clientcert.pem");
     } else if (tryUserPkiPath) {
         /* Check to see if $HOME/.pki contains at least one of the
          * files and if so, use that
@@ -818,26 +812,19 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
         if (!userdir)
             goto error;
 
-        if (virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir) < 0)
-            goto error;
+        virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir);
 
         VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path);
 
-        if ((virAsprintf(cacert, "%s/%s", user_pki_path,
-                         "cacert.pem")) < 0)
-            goto error;
+        virAsprintf(cacert, "%s/%s", user_pki_path, "cacert.pem");
 
-        if ((virAsprintf(cacrl, "%s/%s", user_pki_path,
-                         "cacrl.pem")) < 0)
-            goto error;
+        virAsprintf(cacrl, "%s/%s", user_pki_path, "cacrl.pem");
 
-        if ((virAsprintf(key, "%s/%s", user_pki_path,
-                         isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
-            goto error;
+        virAsprintf(key, "%s/%s", user_pki_path,
+                    isServer ? "serverkey.pem" : "clientkey.pem");
 
-        if ((virAsprintf(cert, "%s/%s", user_pki_path,
-                         isServer ? "servercert.pem" : "clientcert.pem")) < 0)
-            goto error;
+        virAsprintf(cert, "%s/%s", user_pki_path,
+                    isServer ? "servercert.pem" : "clientcert.pem");
 
         /*
          * If some of the files can't be found, fallback
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux