Blame SOURCES/0115-lib-fs-Fix-and-simplify-make_path.patch

36cfb7
From 7ab899539b920609712ad24f871b50a19fd8189f Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:08:08 +0200
36cfb7
Subject: [PATCH] lib/fs: Fix and simplify make_path()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit ac3415f5c1b1d
36cfb7
36cfb7
commit ac3415f5c1b1df2d6a4bf770ad52e2e14c09e58e
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Thu Aug 24 11:41:30 2017 +0200
36cfb7
36cfb7
    lib/fs: Fix and simplify make_path()
36cfb7
36cfb7
    Calling stat() before mkdir() is racey: The entry might change in
36cfb7
    between. Also, the call to stat() seems to exist only to check if the
36cfb7
    directory exists already. So simply call mkdir() unconditionally and
36cfb7
    catch only errors other than EEXIST.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 lib/fs.c | 20 +++++---------------
36cfb7
 1 file changed, 5 insertions(+), 15 deletions(-)
36cfb7
36cfb7
diff --git a/lib/fs.c b/lib/fs.c
36cfb7
index 1ff881ecfcd8c..ebe05cd44e11b 100644
36cfb7
--- a/lib/fs.c
36cfb7
+++ b/lib/fs.c
36cfb7
@@ -102,7 +102,6 @@ out:
36cfb7
 int make_path(const char *path, mode_t mode)
36cfb7
 {
36cfb7
 	char *dir, *delim;
36cfb7
-	struct stat sbuf;
36cfb7
 	int rc = -1;
36cfb7
 
36cfb7
 	delim = dir = strdup(path);
36cfb7
@@ -120,20 +119,11 @@ int make_path(const char *path, mode_t mode)
36cfb7
 		if (delim)
36cfb7
 			*delim = '\0';
36cfb7
 
36cfb7
-		if (stat(dir, &sbuf) != 0) {
36cfb7
-			if (errno != ENOENT) {
36cfb7
-				fprintf(stderr,
36cfb7
-					"stat failed for %s: %s\n",
36cfb7
-					dir, strerror(errno));
36cfb7
-				goto out;
36cfb7
-			}
36cfb7
-
36cfb7
-			if (mkdir(dir, mode) != 0) {
36cfb7
-				fprintf(stderr,
36cfb7
-					"mkdir failed for %s: %s\n",
36cfb7
-					dir, strerror(errno));
36cfb7
-				goto out;
36cfb7
-			}
36cfb7
+		rc = mkdir(dir, mode);
36cfb7
+		if (mkdir(dir, mode) != 0 && errno != EEXIST) {
36cfb7
+			fprintf(stderr, "mkdir failed for %s: %s\n",
36cfb7
+				dir, strerror(errno));
36cfb7
+			goto out;
36cfb7
 		}
36cfb7
 
36cfb7
 		if (delim == NULL)
36cfb7
-- 
36cfb7
2.20.1
36cfb7