[PATCH] utils: check flags and errno before reporting errno

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

 



>From 099707463944faeae75da640b0d1d780cb675406 Mon Sep 17 00:00:00 2001
From: Bihong Yu <yubihong@xxxxxxxxxx>
Date: Tue, 16 Jun 2020 22:08:55 +0800
Subject: [PATCH] utils: check flags and errno before reporting errno

There are races condiction to make '/run/libvirt/qemu/dbus' directory in
virDirCreateNoFork() while concurrent start VMs, and get "failed to create
directory '/run/libvirt/qemu/dbus': File exists" error message. Check flags and
errno before reporting errno after mkdir().

Signed-off-by:Bihong Yu <yubihong@xxxxxxxxxx>
Reviewed-by:Chuan Zheng <zhengchuan@xxxxxxxxxx>
Reviewed-by:alexchen <alex.chen@xxxxxxxxxx>
---
 src/util/virfile.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 20260a2..96ac4e5 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2614,12 +2614,15 @@ virDirCreateNoFork(const char *path,

     if (!((flags & VIR_DIR_CREATE_ALLOW_EXIST) && virFileExists(path))) {
         if (mkdir(path, mode) < 0) {
-            ret = -errno;
-            virReportSystemError(errno, _("failed to create directory '%s'"),
-                                 path);
-            goto error;
+            if (!((flags & VIR_DIR_CREATE_ALLOW_EXIST) && errno == EEXIST)) {
+                ret = -errno;
+                virReportSystemError(errno, _("failed to create directory '%s'"),
+                                     path);
+                goto error;
+            }
+        } else {
+            created = true;
         }
-        created = true;
     }

     if (stat(path, &st) == -1) {
-- 
1.8.3.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