]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Add --offroot argument to mdmon
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 50c98c1cabac335052132f4d411846647258a1d6..6985a7076204f6b11cf2b617594d968025ca8307 100644 (file)
--- a/util.c
+++ b/util.c
@@ -363,7 +363,7 @@ int enough_fd(int fd)
        struct mdu_array_info_s array;
        struct mdu_disk_info_s disk;
        int avail_disks = 0;
-       int i;
+       int i, rv;
        char *avail;
 
        if (ioctl(fd, GET_ARRAY_INFO, &array) != 0 ||
@@ -386,9 +386,10 @@ int enough_fd(int fd)
                avail[disk.raid_disk] = 1;
        }
        /* This is used on an active array, so assume it is clean */
-       return enough(array.level, array.raid_disks, array.layout,
-                     1,
-                     avail, avail_disks);
+       rv = enough(array.level, array.raid_disks, array.layout,
+                   1, avail, avail_disks);
+       free(avail);
+       return rv;
 }
 
 
@@ -1127,7 +1128,8 @@ static int get_gpt_last_partition_end(int fd, unsigned long long *endofpart)
 {
        struct GPT gpt;
        unsigned char empty_gpt_entry[16]= {0};
-       struct GPT_part_entry part;
+       struct GPT_part_entry *part;
+       char buf[512];
        unsigned long long curr_part_end;
        unsigned all_partitions, entry_size;
        unsigned part_nr;
@@ -1151,18 +1153,20 @@ static int get_gpt_last_partition_end(int fd, unsigned long long *endofpart)
 
        /* sanity checks */
        if (all_partitions > 1024 ||
-           entry_size > 512)
+           entry_size > sizeof(buf))
                return -1;
 
+       part = (struct GPT_part_entry *)buf;
+
        for (part_nr=0; part_nr < all_partitions; part_nr++) {
                /* read partition entry */
-               if (read(fd, &part, entry_size) != (ssize_t)entry_size)
+               if (read(fd, buf, entry_size) != (ssize_t)entry_size)
                        return 0;
 
                /* is this valid partition? */
-               if (memcmp(part.type_guid, empty_gpt_entry, 16) != 0) {
+               if (memcmp(part->type_guid, empty_gpt_entry, 16) != 0) {
                        /* check the last lba for the current partition */
-                       curr_part_end = __le64_to_cpu(part.ending_lba);
+                       curr_part_end = __le64_to_cpu(part->ending_lba);
                        if (curr_part_end > *endofpart)
                                *endofpart = curr_part_end;
                }
@@ -1594,7 +1598,7 @@ int start_mdmon(int devnum)
        if (check_env("MDADM_NO_MDMON"))
                return 0;
 
-       len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf));
+       len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf)-1);
        if (len > 0) {
                char *sl;
                pathbuf[len] = 0;
@@ -1709,7 +1713,8 @@ int experimental(void)
        if (check_env("MDADM_EXPERIMENTAL"))
                return 1;
        else {
-               fprintf(stderr, Name ": To use this feature MDADM_EXPERIMENTAL enviroment variable has to defined.\n");
+               fprintf(stderr, Name ": To use this feature MDADM_EXPERIMENTAL"
+                               " environment variable has to be defined.\n");
                return 0;
        }
 }