]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
fix add_dev() handling of broken links
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index f073bce0ad5ad2e1129e7bafef3947b6ce770363..b2fbec7a91c7f3f2059c66b6ed0488d156b73ca7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -467,8 +467,10 @@ int devlist_ready = 0;
 int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
 {
        struct stat st;
+
        if (S_ISLNK(stb->st_mode)) {
-               stat(name, &st);
+               if (stat(name, &st) != 0)
+                       return 0;
                stb = &st;
        }
 
@@ -828,6 +830,32 @@ int open_dev_excl(int devnum)
        return -1;
 }
 
+int same_dev(char *one, char *two)
+{
+       struct stat st1, st2;
+       if (stat(one, &st1) != 0)
+               return 0;
+       if (stat(two, &st2) != 0)
+               return 0;
+       if ((st1.st_mode & S_IFMT) != S_IFBLK)
+               return 0;
+       if ((st2.st_mode & S_IFMT) != S_IFBLK)
+               return 0;
+       return st1.st_rdev == st2.st_rdev;
+}
+
+void wait_for(char *dev)
+{
+       int i;
+
+       for (i=0 ; i<25 ; i++) {
+               struct stat stb;
+               if (stat(dev, &stb) == 0)
+                       return;
+               usleep(200000);
+       }
+}
+
 struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
 
 #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
@@ -1209,7 +1237,7 @@ int start_mdmon(int devnum)
                NULL
        };
 
-       if (env_no_mdmon())
+       if (check_env("MDADM_NO_MDMON"))
                return 0;
 
        len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf));
@@ -1248,9 +1276,9 @@ int start_mdmon(int devnum)
        return 0;
 }
 
-int env_no_mdmon(void)
+int check_env(char *name)
 {
-       char *val = getenv("MDADM_NO_MDMON");
+       char *val = getenv(name);
 
        if (val && atoi(val) == 1)
                return 1;
@@ -1299,15 +1327,6 @@ void append_metadata_update(struct supertype *st, void *buf, int len)
        *st->update_tail = mu;
        st->update_tail = &mu->next;
 }
-
-struct superswitch *find_metadata_methods(char *vers)
-{
-       if (strcmp(vers, "ddf") == 0)
-               return &super_ddf;
-       if (strcmp(vers, "imsm") == 0)
-               return &super_imsm;
-       return NULL;
-}
 #endif /* MDASSEMBLE */
 
 #ifdef __TINYC__