]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib/fs: avoid double call to mkdir on make_path()
authorAndrea Claudi <aclaudi@redhat.com>
Mon, 22 Feb 2021 18:14:31 +0000 (19:14 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 23 Feb 2021 02:20:44 +0000 (18:20 -0800)
make_path() function calls mkdir two times in a row. The first one it
stores mkdir return code, and then it calls it again to check for errno.

This seems unnecessary, as we can use the return code from the first
call and check for errno if not 0.

Fixes: ac3415f5c1b1d ("lib/fs: Fix and simplify make_path()")
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/fs.c

index 4b90a704647ab6dc446de2f7a4edf8d09ecb3bdd..2ae506ecc501b53da18dfc66734472eaacf3fbd2 100644 (file)
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -253,7 +253,7 @@ int make_path(const char *path, mode_t mode)
                        *delim = '\0';
 
                rc = mkdir(dir, mode);
-               if (mkdir(dir, mode) != 0 && errno != EEXIST) {
+               if (rc && errno != EEXIST) {
                        fprintf(stderr, "mkdir failed for %s: %s\n",
                                dir, strerror(errno));
                        goto out;