]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add _FORTIFY_SOURCE to mdadm.O2 build.
authorNeilBrown <neilb@suse.de>
Tue, 2 Mar 2010 23:54:17 +0000 (10:54 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 2 Mar 2010 23:54:17 +0000 (10:54 +1100)
When building mdadm.O2, set _FORTIFY_SOURCE to get more
warnings, and also build mdmon.O2 to find warnings in that
code too.
Then fix the warnings.

Suggested-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
Makefile
mdmon.c
restripe.c

diff --git a/Grow.c b/Grow.c
index 4dfa344159040d90ee08eb1f4a0218b835a246d6..d7d84727dc533f8e0118334f6d8694913b1f4661 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -1254,6 +1254,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
  * 
  */
 
  * 
  */
 
+/* FIXME return status is never checked */
 int grow_backup(struct mdinfo *sra,
                unsigned long long offset, /* per device */
                unsigned long stripes, /* per device */
 int grow_backup(struct mdinfo *sra,
                unsigned long long offset, /* per device */
                unsigned long stripes, /* per device */
@@ -1336,16 +1337,16 @@ int grow_backup(struct mdinfo *sra,
                        bsb.sb_csum2 = bsb_csum((char*)&bsb,
                                                ((char*)&bsb.sb_csum2)-((char*)&bsb));
 
                        bsb.sb_csum2 = bsb_csum((char*)&bsb,
                                                ((char*)&bsb.sb_csum2)-((char*)&bsb));
 
-               lseek64(destfd[i], destoffsets[i] - 4096, 0);
-               write(destfd[i], &bsb, 512);
+               rv |= lseek64(destfd[i], destoffsets[i] - 4096, 0);
+               rv = rv ?: write(destfd[i], &bsb, 512);
                if (destoffsets[i] > 4096) {
                if (destoffsets[i] > 4096) {
-                       lseek64(destfd[i], destoffsets[i]+stripes*chunk*odata, 0);
-                       write(destfd[i], &bsb, 512);
+                       rv |= lseek64(destfd[i], destoffsets[i]+stripes*chunk*odata, 0);
+                       rv = rv ?: write(destfd[i], &bsb, 512);
                }
                fsync(destfd[i]);
        }
 
                }
                fsync(destfd[i]);
        }
 
-       return 0;
+       return rv;
 }
 
 /* in 2.6.30, the value reported by sync_completed can be
 }
 
 /* in 2.6.30, the value reported by sync_completed can be
@@ -1358,6 +1359,7 @@ int grow_backup(struct mdinfo *sra,
  * The various caller give appropriate values so that
  * every works.
  */
  * The various caller give appropriate values so that
  * every works.
  */
+/* FIXME return value is often ignored */
 int wait_backup(struct mdinfo *sra,
                unsigned long long offset, /* per device */
                unsigned long long blocks, /* per device */
 int wait_backup(struct mdinfo *sra,
                unsigned long long offset, /* per device */
                unsigned long long blocks, /* per device */
@@ -1371,6 +1373,7 @@ int wait_backup(struct mdinfo *sra,
        int fd = sysfs_get_fd(sra, NULL, "sync_completed");
        unsigned long long completed;
        int i;
        int fd = sysfs_get_fd(sra, NULL, "sync_completed");
        unsigned long long completed;
        int i;
+       int rv;
 
        if (fd < 0)
                return -1;
 
        if (fd < 0)
                return -1;
@@ -1402,24 +1405,26 @@ int wait_backup(struct mdinfo *sra,
                bsb.length = __cpu_to_le64(0);
        }
        bsb.mtime = __cpu_to_le64(time(0));
                bsb.length = __cpu_to_le64(0);
        }
        bsb.mtime = __cpu_to_le64(time(0));
+       rv = 0;
        for (i = 0; i < dests; i++) {
                bsb.devstart = __cpu_to_le64(destoffsets[i]/512);
                bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
                if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0)
                        bsb.sb_csum2 = bsb_csum((char*)&bsb,
                                                ((char*)&bsb.sb_csum2)-((char*)&bsb));
        for (i = 0; i < dests; i++) {
                bsb.devstart = __cpu_to_le64(destoffsets[i]/512);
                bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
                if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0)
                        bsb.sb_csum2 = bsb_csum((char*)&bsb,
                                                ((char*)&bsb.sb_csum2)-((char*)&bsb));
-               lseek64(destfd[i], destoffsets[i]-4096, 0);
-               write(destfd[i], &bsb, 512);
+               rv |= lseek64(destfd[i], destoffsets[i]-4096, 0);
+               rv = rv ?: write(destfd[i], &bsb, 512);
                fsync(destfd[i]);
        }
                fsync(destfd[i]);
        }
-       return 0;
+       return rv;
 }
 
 static void fail(char *msg)
 {
 }
 
 static void fail(char *msg)
 {
-       write(2, msg, strlen(msg));
-       write(2, "\n", 1);
-       exit(1);
+       int rv;
+       rv = write(2, msg, strlen(msg));
+       rv |= write(2, "\n", 1);
+       exit(rv ? 1 : 2);
 }
 
 static char *abuf, *bbuf;
 }
 
 static char *abuf, *bbuf;
@@ -1455,8 +1460,12 @@ static void validate(int afd, int bfd, unsigned long long offset)
                        free(abuf);
                        free(bbuf);
                        abuflen = len;
                        free(abuf);
                        free(bbuf);
                        abuflen = len;
-                       posix_memalign((void**)&abuf, 4096, abuflen);
-                       posix_memalign((void**)&bbuf, 4096, abuflen);
+                       if (posix_memalign((void**)&abuf, 4096, abuflen) ||
+                           posix_memalign((void**)&bbuf, 4096, abuflen)) {
+                               abuflen = 0;
+                               /* just stop validating on mem-alloc failure */
+                               return;
+                       }
                }
 
                lseek64(bfd, offset, 0);
                }
 
                lseek64(bfd, offset, 0);
@@ -1511,7 +1520,9 @@ static int child_grow(int afd, struct mdinfo *sra, unsigned long stripes,
        char *buf;
        int degraded = 0;
 
        char *buf;
        int degraded = 0;
 
-       posix_memalign((void**)&buf, 4096, disks * chunk);
+       if (posix_memalign((void**)&buf, 4096, disks * chunk))
+               /* Don't start the 'reshape' */
+               return 0;
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
        grow_backup(sra, 0, stripes,
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
        grow_backup(sra, 0, stripes,
@@ -1539,7 +1550,8 @@ static int child_shrink(int afd, struct mdinfo *sra, unsigned long stripes,
        int rv;
        int degraded = 0;
 
        int rv;
        int degraded = 0;
 
-       posix_memalign((void**)&buf, 4096, disks * chunk);
+       if (posix_memalign((void**)&buf, 4096, disks * chunk))
+               return 0;
        start = sra->component_size - stripes * chunk/512;
        sysfs_set_num(sra, NULL, "sync_max", start);
        sysfs_set_str(sra, NULL, "sync_action", "reshape");
        start = sra->component_size - stripes * chunk/512;
        sysfs_set_num(sra, NULL, "sync_max", start);
        sysfs_set_str(sra, NULL, "sync_action", "reshape");
@@ -1578,7 +1590,8 @@ static int child_same_size(int afd, struct mdinfo *sra, unsigned long stripes,
        int degraded = 0;
 
 
        int degraded = 0;
 
 
-       posix_memalign((void**)&buf, 4096, disks * chunk);
+       if (posix_memalign((void**)&buf, 4096, disks * chunk))
+               return 0;
 
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
 
        sysfs_set_num(sra, NULL, "suspend_lo", 0);
        sysfs_set_num(sra, NULL, "suspend_hi", 0);
index 1836b4b4d521112fe3ef34915a74d3e77f3c4e6a..a23923c9b6fe0269c8600bbc36a6446565e336a2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -97,6 +97,10 @@ MON_OBJS = mdmon.o monitor.o managemon.o util.o mdstat.o sysfs.o config.o \
        super-ddf.o sha1.o crc32.o msg.o bitmap.o \
        platform-intel.o probe_roms.o
 
        super-ddf.o sha1.o crc32.o msg.o bitmap.o \
        platform-intel.o probe_roms.o
 
+MON_SRCS = mdmon.c monitor.c managemon.c util.c mdstat.c sysfs.c config.c \
+       Kill.c sg_io.c dlink.c ReadMe.c super0.c super1.c super-intel.c \
+       super-ddf.c sha1.c crc32.c msg.c bitmap.c \
+       platform-intel.c probe_roms.c
 
 STATICSRC = pwgr.c
 STATICOBJS = pwgr.o
 
 STATICSRC = pwgr.c
 STATICOBJS = pwgr.o
@@ -138,8 +142,11 @@ mdadm.klibc : $(SRCS) mdadm.h
 mdadm.Os : $(SRCS) mdadm.h
        $(CC) -o mdadm.Os $(CFLAGS)  -DHAVE_STDINT_H -Os $(SRCS)
 
 mdadm.Os : $(SRCS) mdadm.h
        $(CC) -o mdadm.Os $(CFLAGS)  -DHAVE_STDINT_H -Os $(SRCS)
 
-mdadm.O2 : $(SRCS) mdadm.h
-       $(CC) -o mdadm.O2 $(CFLAGS)  -DHAVE_STDINT_H -O2 $(SRCS)
+mdadm.O2 : $(SRCS) mdadm.h mdmon.O2
+       $(CC) -o mdadm.O2 $(CFLAGS)  -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(SRCS)
+
+mdmon.O2 : $(MON_SRCS) mdadm.h mdmon.h
+       $(CC) -o mdmon.O2 $(CFLAGS)  -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(MON_SRCS)
 
 mdmon : $(MON_OBJS)
        $(CC) $(LDFLAGS) -o mdmon $(MON_OBJS) $(LDLIBS)
 
 mdmon : $(MON_OBJS)
        $(CC) $(LDFLAGS) -o mdmon $(MON_OBJS) $(LDLIBS)
diff --git a/mdmon.c b/mdmon.c
index 31d45fd5662b046ba9e967cf48fb82c276f69443..8e62a68b2319e1c3087c485d02aff03beaf516ba 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -176,7 +176,10 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
        fl = fcntl(sock, F_GETFL, 0);
        fl &= ~O_NONBLOCK;
        fcntl(sock, F_SETFL, fl);
        fl = fcntl(sock, F_GETFL, 0);
        fl &= ~O_NONBLOCK;
        fcntl(sock, F_SETFL, fl);
-       read(sock, buf, 100);
+       n = read(sock, buf, 100);
+       /* Ignore result, it is just the wait that
+        * matters 
+        */
 }
 
 void remove_pidfile(char *devname)
 }
 
 void remove_pidfile(char *devname)
index f673206102f0aea0c2b449d6ceb067a4230f1e5d..0f226e37b92850419e264e7c267b612fc6a9536f 100644 (file)
@@ -565,7 +565,8 @@ int restore_stripes(int *dest, unsigned long long *offsets,
 
        int data_disks = raid_disks - (level == 0 ? 0 : level <= 5 ? 1 : 2);
 
 
        int data_disks = raid_disks - (level == 0 ? 0 : level <= 5 ? 1 : 2);
 
-       posix_memalign((void**)&stripe_buf, 4096, raid_disks * chunk_size);
+       if (posix_memalign((void**)&stripe_buf, 4096, raid_disks * chunk_size))
+               stripe_buf = NULL;
        if (zero == NULL) {
                zero = malloc(chunk_size);
                if (zero)
        if (zero == NULL) {
                zero = malloc(chunk_size);
                if (zero)