[libvirt] [PATCH 7/9] remove remainder of offending strerror uses

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

 



From: Jim Meyering <meyering@xxxxxxxxxx>

* qemud/qemud.c (GET_CONF_STR): Use virStrerror, not strerror.
* qemud/remote.c (remoteDispatchDomainBlockPeek): Likewise.
(remoteDispatchDomainMemoryPeek, remoteDispatchAuthSaslInit): Likewise.
(remoteDispatchAuthPolkit): Likewise.
* src/lxc_container.c (lxcContainerAvailable): Likewise.
* src/network_driver.c (networkStartNetworkDaemon): Likewise.
(networkShutdownNetworkDaemon): Likewise.
* src/qemu_conf.c (qemudExtractVersion, qemudNetworkIfaceConnect):
* src/storage_conf.c (virStoragePoolLoadAllConfigs): Likewise.
* src/storage_driver.c (storagePoolUndefine): Likewise.
* src/uml_driver.c (umlStartup, umlStartVMDaemon): Likewise.
* src/util.c (virFileReadAll): Likewise.
* src/uuid.c (virUUIDGenerate): Likewise.
* src/xen_internal.c (get_cpu_flags): Likewise.
---
 qemud/qemud.c        |    5 ++++-
 qemud/remote.c       |   26 ++++++++++++++++++--------
 src/lxc_container.c  |    4 ++--
 src/network_driver.c |   12 +++++++-----
 src/qemu_conf.c      |    8 +++++---
 src/storage_conf.c   |    5 +++--
 src/storage_driver.c |    5 +++--
 src/uml_driver.c     |   16 +++++++++-------
 src/util.c           |    6 ++++--
 src/uuid.c           |    7 +++++--
 src/xen_internal.c   |    5 +++--
 11 files changed, 63 insertions(+), 36 deletions(-)

diff --git a/qemud/qemud.c b/qemud/qemud.c
index 48083df..effb336 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -49,6 +49,7 @@
 #include <netdb.h>

 #include "libvirt_internal.h"
+#include "virterror_internal.h"

 #include "qemud.h"
 #include "util.h"
@@ -2316,7 +2317,9 @@ checkType (virConfValuePtr p, const char *filename,
                 goto free_and_fail;                                     \
             (var_name) = strdup (p->str);                               \
             if ((var_name) == NULL) {                                   \
-                VIR_ERROR(_("remoteReadConfigFile: %s\n"),strerror (errno)); \
+                char ebuf[1024];                                        \
+                VIR_ERROR(_("remoteReadConfigFile: %s\n"),		\
+                          virStrerror(errno, ebuf, sizeof ebuf));       \
                 goto free_and_fail;                                     \
             }                                                           \
         }                                                               \
diff --git a/qemud/remote.c b/qemud/remote.c
index 2e0c48e..78dda42 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -41,6 +41,7 @@
 #include <string.h>
 #include <errno.h>
 #include <fnmatch.h>
+#include "virterror_internal.h"

 #ifdef HAVE_POLKIT
 #include <polkit/polkit.h>
@@ -990,9 +991,11 @@ remoteDispatchDomainBlockPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
     }

     ret->buffer.buffer_len = size;
-    if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) {
+    if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
+        char ebuf[1024];
         virDomainFree (dom);
-        remoteDispatchFormatError (rerr, "%s", strerror (errno));
+        remoteDispatchFormatError (rerr, "%s",
+                                   virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

@@ -1031,16 +1034,18 @@ remoteDispatchDomainMemoryPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
     flags = args->flags;

     if (size > REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX) {
+        virDomainFree (dom);
         remoteDispatchFormatError (rerr,
                                    "%s", _("size > maximum buffer size"));
-        virDomainFree (dom);
         return -1;
     }

     ret->buffer.buffer_len = size;
     if (VIR_ALLOC_N (ret->buffer.buffer_val, size) < 0) {
-        remoteDispatchFormatError (rerr, "%s", strerror (errno));
+        char ebuf[1024];
         virDomainFree (dom);
+        remoteDispatchFormatError (rerr, "%s",
+                                   virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

@@ -2571,9 +2576,10 @@ remoteDispatchAuthSaslInit (struct qemud_server *server,
     /* Get local address in form  IPADDR:PORT */
     salen = sizeof(sa);
     if (getsockname(client->fd, (struct sockaddr*)&sa, &salen) < 0) {
+        char ebuf[1024];
         remoteDispatchFormatError(rerr,
                                   _("failed to get sock address: %s"),
-                                  strerror(errno));
+                                  virStrerror(errno, ebuf, sizeof ebuf));
         goto error;
     }
     if ((localAddr = addrToString(rerr, &sa, salen)) == NULL) {
@@ -2583,8 +2589,9 @@ remoteDispatchAuthSaslInit (struct qemud_server *server,
     /* Get remote address in form  IPADDR:PORT */
     salen = sizeof(sa);
     if (getpeername(client->fd, (struct sockaddr*)&sa, &salen) < 0) {
+        char ebuf[1024];
         remoteDispatchFormatError(rerr, _("failed to get peer address: %s"),
-                                  strerror(errno));
+                                  virStrerror(errno, ebuf, sizeof ebuf));
         VIR_FREE(localAddr);
         goto error;
     }
@@ -3062,7 +3069,9 @@ remoteDispatchAuthPolkit (struct qemud_server *server,
     }

     if (!(pkaction = polkit_action_new())) {
-        VIR_ERROR(_("Failed to create polkit action %s\n"), strerror(errno));
+        char ebuf[1024];
+        VIR_ERROR(_("Failed to create polkit action %s\n"),
+                  virStrerror(errno, ebuf, sizeof ebuf));
         polkit_caller_unref(pkcaller);
         goto authfail;
     }
@@ -3070,9 +3079,10 @@ remoteDispatchAuthPolkit (struct qemud_server *server,

     if (!(pkcontext = polkit_context_new()) ||
         !polkit_context_init(pkcontext, &pkerr)) {
+        char ebuf[1024];
         VIR_ERROR(_("Failed to create polkit context %s\n"),
                   (pkerr ? polkit_error_get_error_message(pkerr)
-                   : strerror(errno)));
+                   : virStrerror(errno, ebuf, sizeof ebuf)));
         if (pkerr)
             polkit_error_free(pkerr);
         polkit_caller_unref(pkcaller);
diff --git a/src/lxc_container.c b/src/lxc_container.c
index ea52eed..f1c523b 100644
--- a/src/lxc_container.c
+++ b/src/lxc_container.c
@@ -668,8 +668,9 @@ int lxcContainerAvailable(int features)
     cpid = clone(lxcContainerDummyChild, childStack, flags, NULL);
     VIR_FREE(stack);
     if (cpid < 0) {
+        char ebuf[1024];
         DEBUG("clone call returned %s, container support is not enabled",
-              strerror(errno));
+              virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     } else {
         waitpid(cpid, &childStatus, 0);
@@ -677,4 +678,3 @@ int lxcContainerAvailable(int features)

     return 0;
 }
-
diff --git a/src/network_driver.c b/src/network_driver.c
index dcc6ad9..8d7340e 100644
--- a/src/network_driver.c
+++ b/src/network_driver.c
@@ -904,17 +904,18 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
  err_delbr2:
     networkRemoveIptablesRules(driver, network);

- err_delbr1:
+ err_delbr1:;
+    char ebuf[1024];
     if (network->def->ipAddress &&
         (err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) {
         networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"),
-                 network->def->bridge, strerror(err));
+                 network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
     }

  err_delbr:
     if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) {
         networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"),
-                 network->def->bridge, strerror(err));
+                 network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
     }

     return -1;
@@ -944,15 +945,16 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,

     networkRemoveIptablesRules(driver, network);

+    char ebuf[1024];
     if (network->def->ipAddress &&
         (err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) {
         networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"),
-                 network->def->bridge, strerror(err));
+                 network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
     }

     if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) {
         networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"),
-                 network->def->bridge, strerror(err));
+                 network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
     }

     /* See if its still alive and really really kill it */
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index ef45b12..6f58ee8 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -517,9 +517,10 @@ int qemudExtractVersion(virConnectPtr conn,
         return -1;

     if (stat(binary, &sb) < 0) {
+        char ebuf[1024];
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("Cannot find QEMU binary %s: %s"), binary,
-                         strerror(errno));
+                         virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

@@ -580,10 +581,11 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
         }
     }

+    char ebuf[1024];
     if (!driver->brctl && (err = brInit(&driver->brctl))) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("cannot initialize bridge support: %s"),
-                         strerror(err));
+                         virStrerror(err, ebuf, sizeof ebuf));
         goto error;
     }

@@ -598,7 +600,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
             qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              _("Failed to add tap interface '%s' "
                                "to bridge '%s' : %s"),
-                             net->ifname, brname, strerror(err));
+                             net->ifname, brname, virStrerror(err, ebuf, sizeof ebuf));
         }
         goto error;
     }
diff --git a/src/storage_conf.c b/src/storage_conf.c
index 7eb89e7..70107a2 100644
--- a/src/storage_conf.c
+++ b/src/storage_conf.c
@@ -1,7 +1,7 @@
 /*
  * storage_conf.c: config handling for storage driver
  *
- * Copyright (C) 2006-2008 Red Hat, Inc.
+ * Copyright (C) 2006-2009 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -1384,10 +1384,11 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn,
     struct dirent *entry;

     if (!(dir = opendir(configDir))) {
+        char ebuf[1024];
         if (errno == ENOENT)
             return 0;
         virStorageLog("Failed to open dir '%s': %s",
-                      configDir, strerror(errno));
+                      configDir, virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

diff --git a/src/storage_driver.c b/src/storage_driver.c
index a456061..d644b63 100644
--- a/src/storage_driver.c
+++ b/src/storage_driver.c
@@ -1,7 +1,7 @@
 /*
  * storage_driver.c: core driver for storage APIs
  *
- * Copyright (C) 2006-2008 Red Hat, Inc.
+ * Copyright (C) 2006-2009 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -567,9 +567,10 @@ storagePoolUndefine(virStoragePoolPtr obj) {
     if (virStoragePoolObjDeleteDef(obj->conn, pool) < 0)
         goto cleanup;

+    char ebuf[1024];
     if (unlink(pool->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
         storageLog("Failed to delete autostart link '%s': %s",
-                   pool->autostartLink, strerror(errno));
+                   pool->autostartLink, virStrerror(errno, ebuf, sizeof ebuf));

     VIR_FREE(pool->configFile);
     VIR_FREE(pool->autostartLink);
diff --git a/src/uml_driver.c b/src/uml_driver.c
index 0fe2fac..48e2d07 100644
--- a/src/uml_driver.c
+++ b/src/uml_driver.c
@@ -376,8 +376,9 @@ umlStartup(void) {
     }

     if (virFileMakePath(uml_driver->monitorDir) < 0) {
+        char ebuf[1024];
         umlLog(VIR_LOG_ERROR, _("Failed to create monitor directory %s: %s"),
-               uml_driver->monitorDir, strerror(errno));
+               uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
         goto error;
     }

@@ -788,29 +789,30 @@ static int umlStartVMDaemon(virConnectPtr conn,
         return -1;
     }

+    char ebuf[1024];
     tmp = progenv;
     while (*tmp) {
         if (safewrite(logfd, *tmp, strlen(*tmp)) < 0)
             umlLog(VIR_LOG_WARN, _("Unable to write envv to logfile: %s\n"),
-                   strerror(errno));
+                   virStrerror(errno, ebuf, sizeof ebuf));
         if (safewrite(logfd, " ", 1) < 0)
             umlLog(VIR_LOG_WARN, _("Unable to write envv to logfile: %s\n"),
-                   strerror(errno));
+                   virStrerror(errno, ebuf, sizeof ebuf));
         tmp++;
     }
     tmp = argv;
     while (*tmp) {
         if (safewrite(logfd, *tmp, strlen(*tmp)) < 0)
             umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile: %s\n"),
-                   strerror(errno));
+                   virStrerror(errno, ebuf, sizeof ebuf));
         if (safewrite(logfd, " ", 1) < 0)
             umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile: %s\n"),
-                   strerror(errno));
+                   virStrerror(errno, ebuf, sizeof ebuf));
         tmp++;
     }
     if (safewrite(logfd, "\n", 1) < 0)
         umlLog(VIR_LOG_WARN, _("Unable to write argv to logfile: %s\n"),
-                 strerror(errno));
+                 virStrerror(errno, ebuf, sizeof ebuf));

     vm->monitor = -1;

@@ -825,7 +827,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
     /* Cleanup intermediate proces */
     if (waitpid(pid, NULL, 0) != pid)
         umlLog(VIR_LOG_WARN, _("failed to wait on process: %d: %s\n"),
-               pid, strerror(errno));
+               pid, virStrerror(errno, ebuf, sizeof ebuf));

     for (i = 0 ; argv[i] ; i++)
         VIR_FREE(argv[i]);
diff --git a/src/util.c b/src/util.c
index 6c29872..1034455 100644
--- a/src/util.c
+++ b/src/util.c
@@ -754,17 +754,19 @@ int virFileReadLimFD(int fd_arg, int maxlen, char **buf)

 int virFileReadAll(const char *path, int maxlen, char **buf)
 {
+    char ebuf[1024];
     FILE *fh = fopen(path, "r");
     if (fh == NULL) {
         virLog("Failed to open file '%s': %s\n",
-               path, strerror(errno));
+               path, virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

     int len = virFileReadLimFP (fh, maxlen, buf);
     fclose(fh);
     if (len < 0) {
-        virLog("Failed to read '%s': %s\n", path, strerror (errno));
+        virLog("Failed to read '%s': %s\n", path,
+               virStrerror(errno, ebuf, sizeof ebuf));
         return -1;
     }

diff --git a/src/uuid.c b/src/uuid.c
index 9d263de..9e9416f 100644
--- a/src/uuid.c
+++ b/src/uuid.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2008 Red Hat, Inc.
+ * Copyright (C) 2007, 2008, 2009 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -36,6 +36,7 @@
 #include "c-ctype.h"
 #include "internal.h"
 #include "util.h"
+#include "virterror_internal.h"

 #define qemudLog(level, msg...) fprintf(stderr, msg)

@@ -99,10 +100,12 @@ virUUIDGenerate(unsigned char *uuid)
     if (uuid == NULL)
         return(-1);

+    char ebuf[1024];
     if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN)))
         qemudLog(QEMUD_WARN,
                  _("Falling back to pseudorandom UUID,"
-                   " failed to generate random bytes: %s"), strerror(err));
+                   " failed to generate random bytes: %s"),
+                 virStrerror(err, ebuf, sizeof ebuf));

     return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
 }
diff --git a/src/xen_internal.c b/src/xen_internal.c
index 9a7272f..4c36b1b 100644
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -1,7 +1,7 @@
 /*
  * xen_internal.c: direct access to Xen hypervisor level
  *
- * Copyright (C) 2005, 2006, 2007, 2008 Red Hat, Inc.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -2265,8 +2265,9 @@ get_cpu_flags(virConnectPtr conn, const char **hvm, int *pae, int *longmode)

     if ((fd = open("/dev/cpu/self/cpuid", O_RDONLY)) == -1 ||
         pread(fd, &regs, sizeof(regs), 0) != sizeof(regs)) {
+        char ebuf[1024];
         virXenError(conn, VIR_ERR_SYSTEM_ERROR,
-            "couldn't read CPU flags: %s", strerror(errno));
+            "couldn't read CPU flags: %s", virStrerror(errno, ebuf, sizeof ebuf));
         goto out;
     }

-- 
1.6.1.2.418.gd79e6

--
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]