[libvirt PATCH 1/4] Use g_strerror instead of virStrerror

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

 



Remove lots of stack-allocated buffers.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/libxl/libxl_conf.c          |  3 +--
 src/libxl/libxl_driver.c        | 11 +++++------
 src/libxl/libxl_logger.c        |  6 ++----
 src/locking/lock_daemon.c       |  9 +++------
 src/logging/log_daemon.c        |  9 +++------
 src/lxc/lxc_container.c         |  3 +--
 src/lxc/lxc_process.c           |  7 +++----
 src/network/bridge_driver.c     |  3 +--
 src/qemu/qemu_capabilities.c    |  3 +--
 src/qemu/qemu_interface.c       |  3 +--
 src/qemu/qemu_process.c         |  9 +++------
 src/remote/remote_daemon.c      | 13 ++++---------
 src/security/security_manager.c |  5 ++---
 src/security/security_selinux.c |  5 ++---
 src/storage/storage_driver.c    |  3 +--
 src/util/viraudit.c             |  3 +--
 src/util/vircommand.c           |  3 +--
 src/util/virfile.c              |  3 +--
 src/util/virhostcpu.c           |  8 +++-----
 src/util/virlockspace.c         |  9 +++------
 src/util/virpci.c               | 12 ++++--------
 src/util/virpidfile.c           |  3 +--
 src/util/virprocess.c           |  3 +--
 src/util/virutil.c              |  6 ++----
 tools/vsh.c                     | 28 ++++++++++------------------
 25 files changed, 60 insertions(+), 110 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 907df525c5..be5fc505fe 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1740,14 +1740,13 @@ libxlDriverConfigNew(void)
 int
 libxlDriverConfigInit(libxlDriverConfigPtr cfg)
 {
-    char ebuf[1024];
     unsigned int free_mem;
 
     if (virFileMakePath(cfg->logDir) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create log dir '%s': %s"),
                        cfg->logDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         return -1;
     }
 
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index f2387e2a20..cc93f1802d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -654,7 +654,6 @@ libxlStateInitialize(bool privileged,
 {
     libxlDriverConfigPtr cfg;
     g_autofree char *driverConf = NULL;
-    char ebuf[1024];
     bool autostart = true;
 
     if (root != NULL) {
@@ -725,35 +724,35 @@ libxlStateInitialize(bool privileged,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create state dir '%s': %s"),
                        cfg->stateDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         goto error;
     }
     if (virFileMakePath(cfg->libDir) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create lib dir '%s': %s"),
                        cfg->libDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         goto error;
     }
     if (virFileMakePath(cfg->saveDir) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create save dir '%s': %s"),
                        cfg->saveDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         goto error;
     }
     if (virFileMakePath(cfg->autoDumpDir) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create dump dir '%s': %s"),
                        cfg->autoDumpDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         goto error;
     }
     if (virFileMakePath(cfg->channelDir) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to create channel dir '%s': %s"),
                        cfg->channelDir,
-                       virStrerror(errno, ebuf, sizeof(ebuf)));
+                       g_strerror(errno));
         goto error;
     }
 
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index 1581a3070c..379d7a8d00 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -67,7 +67,6 @@ libvirt_vmessage(xentoollog_logger *logger_in,
     char timestamp[VIR_TIME_STRING_BUFLEN];
     char *message = NULL;
     char *start, *end;
-    char ebuf[1024];
 
     VIR_DEBUG("libvirt_vmessage: context='%s' format='%s'", context, format);
 
@@ -104,7 +103,7 @@ libvirt_vmessage(xentoollog_logger *logger_in,
     fprintf(logFile, "%s", message);
 
     if (errnoval >= 0)
-        fprintf(logFile, ": %s", virStrerror(errnoval, ebuf, sizeof(ebuf)));
+        fprintf(logFile, ": %s", g_strerror(errnoval));
 
     fputc('\n', logFile);
     fflush(logFile);
@@ -192,14 +191,13 @@ libxlLoggerOpenFile(libxlLoggerPtr logger,
     char *path = NULL;
     FILE *logFile = NULL;
     char *domidstr = NULL;
-    char ebuf[1024];
 
     path = g_strdup_printf("%s/%s.log", logger->logDir, name);
     domidstr = g_strdup_printf("%d", id);
 
     if (!(logFile = fopen(path, "a"))) {
         VIR_WARN("Failed to open log file %s: %s",
-                 path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 path, g_strerror(errno));
         goto cleanup;
     }
     ignore_value(virHashAddEntry(logger->files, domidstr, logFile));
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 245155206a..a258f7e6f1 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -1225,9 +1225,8 @@ int main(int argc, char **argv) {
         old_umask = umask(077);
     VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
     if (virFileMakePath(run_dir) < 0) {
-        char ebuf[1024];
         VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
-                  virStrerror(errno, ebuf, sizeof(ebuf)));
+                  g_strerror(errno));
         ret = VIR_LOCK_DAEMON_ERR_RUNDIR;
         umask(old_umask);
         goto cleanup;
@@ -1253,17 +1252,15 @@ int main(int argc, char **argv) {
         };
 
         if (godaemon) {
-            char ebuf[1024];
-
             if (chdir("/") < 0) {
                 VIR_ERROR(_("cannot change to root directory: %s"),
-                          virStrerror(errno, ebuf, sizeof(ebuf)));
+                          g_strerror(errno));
                 goto cleanup;
             }
 
             if ((statuswrite = virLockDaemonForkIntoBackground(argv[0])) < 0) {
                 VIR_ERROR(_("Failed to fork as daemon: %s"),
-                          virStrerror(errno, ebuf, sizeof(ebuf)));
+                          g_strerror(errno));
                 goto cleanup;
             }
         }
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 47377deb4f..3319bf1f6f 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -993,9 +993,8 @@ int main(int argc, char **argv) {
         old_umask = umask(077);
     VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
     if (virFileMakePath(run_dir) < 0) {
-        char ebuf[1024];
         VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
-                  virStrerror(errno, ebuf, sizeof(ebuf)));
+                  g_strerror(errno));
         ret = VIR_LOG_DAEMON_ERR_RUNDIR;
         umask(old_umask);
         goto cleanup;
@@ -1023,17 +1022,15 @@ int main(int argc, char **argv) {
         };
 
         if (godaemon) {
-            char ebuf[1024];
-
             if (chdir("/") < 0) {
                 VIR_ERROR(_("cannot change to root directory: %s"),
-                          virStrerror(errno, ebuf, sizeof(ebuf)));
+                          g_strerror(errno));
                 goto cleanup;
             }
 
             if ((statuswrite = virLogDaemonForkIntoBackground(argv[0])) < 0) {
                 VIR_ERROR(_("Failed to fork as daemon: %s"),
-                          virStrerror(errno, ebuf, sizeof(ebuf)));
+                          g_strerror(errno));
                 goto cleanup;
             }
         }
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index ec7104f88a..1c28ecfdb7 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -566,12 +566,11 @@ static int lxcContainerUnmountSubtree(const char *prefix,
     for (i = 0; i < nmounts; i++) {
         VIR_DEBUG("Umount %s", mounts[i]);
         if (umount(mounts[i]) < 0) {
-            char ebuf[1024];
             failedUmount = mounts[i];
             saveErrno = errno;
             VIR_WARN("Failed to unmount '%s', trying to detach subtree '%s': %s",
                      failedUmount, mounts[nmounts-1],
-                     virStrerror(errno, ebuf, sizeof(ebuf)));
+                     g_strerror(errno));
             break;
         }
     }
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index cd0026f78f..5199f3806e 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -135,14 +135,13 @@ static void
 lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg,
                               virDomainObjPtr vm)
 {
-    char ebuf[1024];
     char *file = NULL;
 
     file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
 
     if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
         VIR_WARN("Failed to remove domain XML for %s: %s",
-                 vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 vm->def->name, g_strerror(errno));
     VIR_FREE(file);
 }
 
@@ -1410,7 +1409,7 @@ int virLXCProcessStart(virConnectPtr conn,
     if (safewrite(logfd, timestamp, strlen(timestamp)) < 0 ||
         safewrite(logfd, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
         VIR_WARN("Unable to write timestamp to logfile: %s",
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
     }
     VIR_FREE(timestamp);
 
@@ -1418,7 +1417,7 @@ int virLXCProcessStart(virConnectPtr conn,
     virCommandWriteArgLog(cmd, logfd);
     if ((pos = lseek(logfd, 0, SEEK_END)) < 0)
         VIR_WARN("Unable to seek to end of logfile: %s",
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
 
     VIR_DEBUG("Launching container");
     virCommandRawStatus(cmd);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 369e80a889..ae52455761 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -996,11 +996,10 @@ networkKillDaemon(pid_t pid,
             if (errno == ESRCH) {
                 ret = 0;
             } else {
-                char ebuf[1024];
                 VIR_WARN("Failed to terminate %s process %d "
                          "for network '%s' with SIG%s: %s",
                          daemonName, pid, networkName, signame,
-                         virStrerror(errno, ebuf, sizeof(ebuf)));
+                         g_strerror(errno));
             }
             return ret;
         }
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a75ca0574d..1a599a8787 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4646,10 +4646,9 @@ virQEMUCapsIsValid(void *data,
     }
 
     if (stat(qemuCaps->binary, &sb) < 0) {
-        char ebuf[1024];
         VIR_DEBUG("Failed to stat QEMU binary '%s': %s",
                   qemuCaps->binary,
-                  virStrerror(errno, ebuf, sizeof(ebuf)));
+                  g_strerror(errno));
         return false;
     }
 
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index 8a01eecd83..2b24c73d65 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -351,7 +351,6 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
     } while (*tapfd < 0 && errno == EINTR);
 
     if (*tapfd < 0) {
-        char ebuf[1024];
         char *errstr = NULL;
 
         if (!(cmdstr = virCommandToString(cmd, false)))
@@ -363,7 +362,7 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
 
         virReportError(VIR_ERR_INTERNAL_ERROR,
             _("%s: failed to communicate with bridge helper: %s%s"),
-            cmdstr, virStrerror(errno, ebuf, sizeof(ebuf)),
+            cmdstr, g_strerror(errno),
             NULLSTR_EMPTY(errstr));
         VIR_FREE(errstr);
         goto cleanup;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 499d39a920..c138ef9af4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -105,7 +105,6 @@ static void
 qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
                               virDomainObjPtr vm)
 {
-    char ebuf[1024];
     g_autofree char *file = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
@@ -114,13 +113,13 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
 
     if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
         VIR_WARN("Failed to remove domain XML for %s: %s",
-                 vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 vm->def->name, g_strerror(errno));
 
     if (priv->pidfile &&
         unlink(priv->pidfile) < 0 &&
         errno != ENOENT)
         VIR_WARN("Failed to remove PID file for %s: %s",
-                 vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 vm->def->name, g_strerror(errno));
 }
 
 
@@ -8320,13 +8319,11 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc)
     virDomainObjEndAPI(&proc->vm);
 
     if (proc->pid != 0) {
-        char ebuf[1024];
-
         VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
         if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
             VIR_ERROR(_("Failed to kill process %lld: %s"),
                       (long long)proc->pid,
-                      virStrerror(errno, ebuf, sizeof(ebuf)));
+                      g_strerror(errno));
 
         proc->pid = 0;
     }
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 37e53a87cc..f3b3c70ebf 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -189,12 +189,10 @@ static int daemonForkIntoBackground(const char *argv0)
             VIR_FORCE_CLOSE(statuspipe[0]);
 
             if (ret != 1) {
-                char ebuf[1024];
-
                 fprintf(stderr,
                         _("%s: error: unable to determine if daemon is "
                           "running: %s\n"), argv0,
-                        virStrerror(errno, ebuf, sizeof(ebuf)));
+                        g_strerror(errno));
                 exit(EXIT_FAILURE);
             } else if (status != 0) {
                 fprintf(stderr,
@@ -1194,17 +1192,15 @@ int main(int argc, char **argv) {
               NULLSTR(sock_file_adm));
 
     if (godaemon) {
-        char ebuf[1024];
-
         if (chdir("/") < 0) {
             VIR_ERROR(_("cannot change to root directory: %s"),
-                      virStrerror(errno, ebuf, sizeof(ebuf)));
+                      g_strerror(errno));
             goto cleanup;
         }
 
         if ((statuswrite = daemonForkIntoBackground(argv[0])) < 0) {
             VIR_ERROR(_("Failed to fork as daemon: %s"),
-                      virStrerror(errno, ebuf, sizeof(ebuf)));
+                      g_strerror(errno));
             goto cleanup;
         }
     }
@@ -1227,9 +1223,8 @@ int main(int argc, char **argv) {
         old_umask = umask(077);
     VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
     if (virFileMakePath(run_dir) < 0) {
-        char ebuf[1024];
         VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
-                  virStrerror(errno, ebuf, sizeof(ebuf)));
+                  g_strerror(errno));
         ret = VIR_DAEMON_ERR_RUNDIR;
         goto cleanup;
     }
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index 9f4bd7f8df..fe032746ff 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -1407,7 +1407,6 @@ virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr G_GNUC_UNUSED,
         return;
 
     for (i = 0; i < (*state)->nfds; i++) {
-        char ebuf[1024];
         const char *path = (*state)->paths[i];
         int fd = (*state)->fds[i];
 
@@ -1415,12 +1414,12 @@ virSecurityManagerMetadataUnlock(virSecurityManagerPtr mgr G_GNUC_UNUSED,
          * happen on VIR_CLOSE() anyway. But let's play it nice. */
         if (virFileUnlock(fd, METADATA_OFFSET, METADATA_LEN) < 0) {
             VIR_WARN("Unable to unlock fd %d path %s: %s",
-                     fd, path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                     fd, path, g_strerror(errno));
         }
 
         if (VIR_CLOSE(fd) < 0) {
             VIR_WARN("Unable to close fd %d path %s: %s",
-                     fd, path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                     fd, path, g_strerror(errno));
         }
     }
 
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e9aa8af877..c94f31727c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1451,7 +1451,6 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManagerPtr mgr,
     struct stat buf;
     security_context_t fcon = NULL;
     char *newpath = NULL;
-    char ebuf[1024];
     int rc;
     int ret = -1;
 
@@ -1465,7 +1464,7 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManagerPtr mgr,
 
     if (virFileResolveLink(path, &newpath) < 0) {
         VIR_WARN("cannot resolve symlink %s: %s", path,
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
         goto cleanup;
     }
 
@@ -1492,7 +1491,7 @@ virSecuritySELinuxRestoreFileLabel(virSecurityManagerPtr mgr,
     if (!recall || rc == -2) {
         if (stat(newpath, &buf) != 0) {
             VIR_WARN("cannot stat %s: %s", newpath,
-                     virStrerror(errno, ebuf, sizeof(ebuf)));
+                     g_strerror(errno));
             goto cleanup;
         }
 
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 1c56527e38..2db763caa5 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -900,9 +900,8 @@ storagePoolUndefine(virStoragePoolPtr pool)
 
     if (autostartLink && unlink(autostartLink) < 0 &&
         errno != ENOENT && errno != ENOTDIR) {
-        char ebuf[1024];
         VIR_ERROR(_("Failed to delete autostart link '%s': %s"),
-                  autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
+                  autostartLink, g_strerror(errno));
     }
 
     event = virStoragePoolEventLifecycleNew(def->name,
diff --git a/src/util/viraudit.c b/src/util/viraudit.c
index 13421653b9..6729790a26 100644
--- a/src/util/viraudit.c
+++ b/src/util/viraudit.c
@@ -121,9 +121,8 @@ void virAuditSend(virLogSourcePtr source,
             VIR_WARN("Unknown audit record type %d", type);
         else if (audit_log_user_message(auditfd, record_types[type], str, NULL,
                                         clientaddr, clienttty, success) < 0) {
-            char ebuf[1024];
             VIR_WARN("Failed to send audit message %s: %s",
-                     NULLSTR(str), virStrerror(errno, ebuf, sizeof(ebuf)));
+                     NULLSTR(str), g_strerror(errno));
         }
     }
 #endif
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index c150d99452..9ffa0cf49b 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2061,9 +2061,8 @@ virCommandWriteArgLog(virCommandPtr cmd, int logfd)
     }
 
     if (ioError) {
-        char ebuf[1024];
         VIR_WARN("Unable to write command %s args to logfile: %s",
-                 cmd->args[0], virStrerror(ioError, ebuf, sizeof(ebuf)));
+                 cmd->args[0], g_strerror(ioError));
     }
 }
 
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 589f7ce850..0f31554323 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -127,9 +127,8 @@ int virFileClose(int *fdptr, virFileCloseFlags flags)
                 if (!(flags & VIR_FILE_CLOSE_IGNORE_EBADF))
                     VIR_WARN("Tried to close invalid fd %d", *fdptr);
             } else {
-                char ebuf[1024] G_GNUC_UNUSED;
                 VIR_DEBUG("Failed to close fd %d: %s",
-                          *fdptr, virStrerror(errno, ebuf, sizeof(ebuf)));
+                          *fdptr, g_strerror(errno));
             }
         } else {
             VIR_DEBUG("Closed fd %d", *fdptr);
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 81293eea8c..c1b39e772a 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1228,9 +1228,8 @@ virHostCPUGetMicrocodeVersion(void)
     unsigned int version = 0;
 
     if (virFileReadHeaderQuiet(CPUINFO_PATH, 4096, &outbuf) < 0) {
-        char ebuf[1024];
         VIR_DEBUG("Failed to read microcode version from %s: %s",
-                  CPUINFO_PATH, virStrerror(errno, ebuf, sizeof(ebuf)));
+                  CPUINFO_PATH, g_strerror(errno));
         return 0;
     }
 
@@ -1301,13 +1300,12 @@ virHostCPUGetMSR(unsigned long index,
                  uint64_t *msr)
 {
     VIR_AUTOCLOSE fd = -1;
-    char ebuf[1024];
 
     *msr = 0;
 
     if ((fd = open(MSR_DEVICE, O_RDONLY)) < 0) {
         VIR_DEBUG("Unable to open %s: %s",
-                  MSR_DEVICE, virStrerror(errno, ebuf, sizeof(ebuf)));
+                  MSR_DEVICE, g_strerror(errno));
     } else {
         int rc = pread(fd, msr, sizeof(*msr), index);
 
@@ -1320,7 +1318,7 @@ virHostCPUGetMSR(unsigned long index,
         }
 
         VIR_DEBUG("Cannot read MSR 0x%lx from %s: %s",
-                  index, MSR_DEVICE, virStrerror(errno, ebuf, sizeof(ebuf)));
+                  index, MSR_DEVICE, g_strerror(errno));
     }
 
     VIR_DEBUG("Falling back to KVM ioctl");
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 05517f8b40..9a54192cd1 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -89,17 +89,15 @@ static void virLockSpaceResourceFree(virLockSpaceResourcePtr res)
             } else {
                 if (unlink(res->path) < 0 &&
                     errno != ENOENT) {
-                    char ebuf[1024];
                     VIR_WARN("Failed to unlink resource %s: %s",
-                             res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                             res->path, g_strerror(errno));
                 }
             }
         } else {
             if (unlink(res->path) < 0 &&
                 errno != ENOENT) {
-                char ebuf[1024];
                 VIR_WARN("Failed to unlink resource %s: %s",
-                         res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                         res->path, g_strerror(errno));
             }
         }
     }
@@ -173,9 +171,8 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
              * one that now exists on the filesystem
              */
             if (stat(res->path, &a) < 0) {
-                char ebuf[1024] G_GNUC_UNUSED;
                 VIR_DEBUG("Resource '%s' disappeared: %s",
-                          res->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                          res->path, g_strerror(errno));
                 VIR_FORCE_CLOSE(res->fd);
                 /* Someone else must be racing with us, so try again */
                 continue;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index db9528478d..6c7e6bbcab 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -289,9 +289,8 @@ virPCIDeviceConfigOpenInternal(virPCIDevicePtr dev, bool readonly, bool fatal)
                                  _("Failed to open config space file '%s'"),
                                  dev->path);
         } else {
-            char ebuf[1024];
             VIR_WARN("Failed to open config space file '%s': %s",
-                     dev->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                     dev->path, g_strerror(errno));
         }
         return -1;
     }
@@ -322,9 +321,8 @@ static void
 virPCIDeviceConfigClose(virPCIDevicePtr dev, int cfgfd)
 {
     if (VIR_CLOSE(cfgfd) < 0) {
-        char ebuf[1024];
         VIR_WARN("Failed to close config space file '%s': %s",
-                 dev->path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 dev->path, g_strerror(errno));
     }
 }
 
@@ -340,9 +338,8 @@ virPCIDeviceRead(virPCIDevicePtr dev,
 
     if (lseek(cfgfd, pos, SEEK_SET) != pos ||
         saferead(cfgfd, buf, buflen) != buflen) {
-        char ebuf[1024];
         VIR_WARN("Failed to read from '%s' : %s", dev->path,
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
         return -1;
     }
     return 0;
@@ -407,9 +404,8 @@ virPCIDeviceWrite(virPCIDevicePtr dev,
 {
     if (lseek(cfgfd, pos, SEEK_SET) != pos ||
         safewrite(cfgfd, buf, buflen) != buflen) {
-        char ebuf[1024];
         VIR_WARN("Failed to write to '%s' : %s", dev->path,
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
         return -1;
     }
     return 0;
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index d5aa5f4f84..1a6fbdc552 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -374,9 +374,8 @@ int virPidFileAcquirePath(const char *path,
          * one that now exists on the filesystem
          */
         if (stat(path, &a) < 0) {
-            char ebuf[1024] G_GNUC_UNUSED;
             VIR_DEBUG("Pid file '%s' disappeared: %s",
-                      path, virStrerror(errno, ebuf, sizeof(ebuf)));
+                      path, g_strerror(errno));
             VIR_FORCE_CLOSE(fd);
             /* Someone else must be racing with us, so try again */
             continue;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 436172590e..24135070b7 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -1292,9 +1292,8 @@ virProcessNamespaceAvailable(unsigned int ns)
     cpid = clone(virProcessDummyChild, childStack, flags, NULL);
 
     if (cpid < 0) {
-        char ebuf[1024] G_GNUC_UNUSED;
         VIR_DEBUG("clone call returned %s, container support is not enabled",
-                  virStrerror(errno, ebuf, sizeof(ebuf)));
+                  g_strerror(errno));
         return -1;
     } else if (virProcessWait(cpid, NULL, false) < 0) {
         return -1;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index f77ee05dbf..c4945218e1 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -793,12 +793,11 @@ virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok)
 
     if (!pw) {
         if (rc != 0 && !missing_ok) {
-            char buf[1024];
             /* log the possible error from getpwnam_r. Unfortunately error
              * reporting from this function is bad and we can't really
              * rely on it, so we just report that the user wasn't found */
             VIR_WARN("User record for user '%s' was not found: %s",
-                     name, virStrerror(rc, buf, sizeof(buf)));
+                     name, g_strerror(rc));
         }
 
         ret = 1;
@@ -876,12 +875,11 @@ virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok)
 
     if (!gr) {
         if (rc != 0 && !missing_ok) {
-            char buf[1024];
             /* log the possible error from getgrnam_r. Unfortunately error
              * reporting from this function is bad and we can't really
              * rely on it, so we just report that the user wasn't found */
             VIR_WARN("Group record for user '%s' was not found: %s",
-                     name, virStrerror(rc, buf, sizeof(buf)));
+                     name, g_strerror(rc));
         }
 
         ret = 1;
diff --git a/tools/vsh.c b/tools/vsh.c
index d392f5b05b..0488295c10 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1930,7 +1930,7 @@ vshTTYMakeRaw(vshControl *ctl G_GNUC_UNUSED,
 {
 #ifndef WIN32
     struct termios rawattr = ctl->termattr;
-    char ebuf[1024];
+
 
     if (!ctl->istty) {
         if (report_errors) {
@@ -1946,7 +1946,7 @@ vshTTYMakeRaw(vshControl *ctl G_GNUC_UNUSED,
     if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &rawattr) < 0) {
         if (report_errors)
             vshError(ctl, _("unable to set tty attributes: %s"),
-                     virStrerror(errno, ebuf, sizeof(ebuf)));
+                     g_strerror(errno));
         return -1;
     }
 #endif
@@ -2120,12 +2120,10 @@ vshEventWait(vshControl *ctl)
     assert(ctl->eventPipe[0] >= 0);
     while ((rv = read(ctl->eventPipe[0], &buf, 1)) < 0 && errno == EINTR);
     if (rv != 1) {
-        char ebuf[1024];
-
         if (!rv)
             errno = EPIPE;
         vshError(ctl, _("failed to determine loop exit status: %s"),
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
         return -1;
     }
     return buf;
@@ -2256,13 +2254,11 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
 void
 vshCloseLogFile(vshControl *ctl)
 {
-    char ebuf[1024];
-
     /* log file close */
     if (VIR_CLOSE(ctl->log_fd) < 0) {
         vshError(ctl, _("%s: failed to write log file: %s"),
                  ctl->logfile ? ctl->logfile : "?",
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
     }
 
     if (ctl->logfile) {
@@ -2366,7 +2362,6 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
     char *ret;
     const char *tmpdir;
     int fd;
-    char ebuf[1024];
 
     tmpdir = getenv("TMPDIR");
     if (!tmpdir) tmpdir = "/tmp";
@@ -2374,14 +2369,14 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
     fd = g_mkstemp_full(ret, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR);
     if (fd == -1) {
         vshError(ctl, _("g_mkstemp_full: failed to create temporary file: %s"),
-                 virStrerror(errno, ebuf, sizeof(ebuf)));
+                 g_strerror(errno));
         VIR_FREE(ret);
         return NULL;
     }
 
     if (safewrite(fd, doc, strlen(doc)) == -1) {
         vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
-                 ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 ret, g_strerror(errno));
         VIR_FORCE_CLOSE(fd);
         unlink(ret);
         VIR_FREE(ret);
@@ -2389,7 +2384,7 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc)
     }
     if (VIR_CLOSE(fd) < 0) {
         vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
-                 ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 ret, g_strerror(errno));
         unlink(ret);
         VIR_FREE(ret);
         return NULL;
@@ -2459,12 +2454,11 @@ char *
 vshEditReadBackFile(vshControl *ctl, const char *filename)
 {
     char *ret;
-    char ebuf[1024];
 
     if (virFileReadAll(filename, VSH_MAX_XML_FILE, &ret) == -1) {
         vshError(ctl,
                  _("%s: failed to read temporary file: %s"),
-                 filename, virStrerror(errno, ebuf, sizeof(ebuf)));
+                 filename, g_strerror(errno));
         return NULL;
     }
     return ret;
@@ -2916,9 +2910,8 @@ vshReadlineDeinit(vshControl *ctl)
     if (ctl->historyfile != NULL) {
         if (virFileMakePathWithMode(ctl->historydir, 0755) < 0 &&
             errno != EEXIST) {
-            char ebuf[1024];
             vshError(ctl, _("Failed to create '%s': %s"),
-                     ctl->historydir, virStrerror(errno, ebuf, sizeof(ebuf)));
+                     ctl->historydir, g_strerror(errno));
         } else {
             write_history(ctl->historyfile);
         }
@@ -3155,7 +3148,6 @@ cmdCd(vshControl *ctl, const vshCmd *cmd)
 {
     const char *dir = NULL;
     g_autofree char *dir_malloced = NULL;
-    char ebuf[1024];
 
     if (!ctl->imode) {
         vshError(ctl, "%s", _("cd: command valid only in interactive mode"));
@@ -3169,7 +3161,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd)
 
     if (chdir(dir) == -1) {
         vshError(ctl, _("cd: %s: %s"),
-                 virStrerror(errno, ebuf, sizeof(ebuf)), dir);
+                 g_strerror(errno), dir);
         return false;
     }
 
-- 
2.24.1





[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