Re: [libvirt] [PATCH] split out logfile opening

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

 



On Tue, Jan 06, 2009 at 04:42:15PM +0100, Jim Meyering wrote:
[..snip..] 
> Thanks!
> IMHO, committing your patch as-is, and then making the
> suggested change in a separate change set would be fine.
> Maybe even a little better, since it's easier to see
> what's happening when one doesn't mix code-movement
> changes with "real" changes.
Does the attached patch look ok? I'll apply this together with
0001-split-out-opening-of-the-domain-logfile.patch then.
 -- Guido
>From 4b789b7361e959e5fa1ed6b6c6189ddfaea2cf8a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx>
Date: Thu, 8 Jan 2009 16:41:36 +0100
Subject: [PATCH] use snprintf

---
 src/qemu_driver.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 5229b8a..91d3ed3 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -149,24 +149,21 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
     char logfile[PATH_MAX];
     mode_t logmode;
     uid_t uid = geteuid();
-    int fd = -1;
+    int ret, fd = -1;
 
-    if ((strlen(logDir) + /* path */
-         1 + /* Separator */
-         strlen(name) + /* basename */
-         4 + /* suffix .log */
-         1 /* NULL */) > PATH_MAX) {
+    if ((ret = snprintf(logfile, PATH_MAX, "%s/%s.log", logDir, name)) < 0) {
+        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         _("failed to build logfile name %s/%s.log"),
+                         logDir, name);
+        return -1;
+    }
+    if (ret >= PATH_MAX) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("config file path too long: %s/%s.log"),
                          logDir, name);
         return -1;
     }
 
-    strcpy(logfile, logDir);
-    strcat(logfile, "/");
-    strcat(logfile, name);
-    strcat(logfile, ".log");
-
     logmode = O_CREAT | O_WRONLY;
     if (uid != 0)
         logmode |= O_TRUNC;
-- 
1.6.0.3

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