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

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