]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
check return status of all write/fwrite functions as required by glibc 2.4
authorNeil Brown <neilb@suse.de>
Mon, 29 May 2006 02:06:32 +0000 (02:06 +0000)
committerNeil Brown <neilb@suse.de>
Mon, 29 May 2006 02:06:32 +0000 (02:06 +0000)
From: Luca Berra <bluca@vodka.it>

glibc 2.4 is pedantic on ignoring return values from fprintf, fwrite and
write, so now we check the rval and actually do something with it.
in the Grow.c case i only print a warning, since i don't think we can do
anything in case we fail invalidating those superblocks (is should never
happen, but then...)

Signed-off-by: Neil Brown <neilb@suse.de>
Assemble.c
Grow.c
Monitor.c
bitmap.c
mdadm.h
super0.c
super1.c

index 816a88e0f797c1784af805903aa0f0559b2b41ae..cb97f8cd59a491684d6531318aaae0aecad6ab5e 100644 (file)
@@ -451,7 +451,9 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
 
                        if (strcmp(update, "uuid")==0 &&
                            ident->bitmap_fd)
-                               bitmap_update_uuid(ident->bitmap_fd, info.uuid);
+                               if (bitmap_update_uuid(ident->bitmap_fd, info.uuid) != 0)
+                                       fprintf(stderr, Name ": Could not update uuid on %s.\n",
+                                               devname);
                } else
 #endif
                {
diff --git a/Grow.c b/Grow.c
index 8c8aa285240b5278a911a47b97aa1be0badc6990..61347b7b12df021b43516ffe8dc147dc0f49e51d 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -801,7 +801,10 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                memset(&bsb, 0, sizeof(bsb));
                for (i=odisks; i<d ; i++) {
                        lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0);
-                       write(fdlist[i], &bsb, sizeof(bsb));
+                       if (write(fdlist[i], &bsb, sizeof(bsb)) < 0) {
+                               fprintf(stderr, Name ": %s: failed to invalidate metadata for raid disk %d\n",
+                                       devname, i);
+                       }
                }
 
                /* unsuspend. */
index 7314cdcd2b780366b1f66cd7eff1ffbb435407ac..246b9c501d1fcbe378eedc543106fd8171c8921e 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -521,7 +521,7 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
                                int n;
                                fprintf(mp, "\nP.S. The /proc/mdstat file current contains the following:\n\n");
                                while ( (n=fread(buf, 1, sizeof(buf), mdstat)) > 0)
-                                       fwrite(buf, 1, n, mp);
+                                       n=fwrite(buf, 1, n, mp); /* yes, i don't care about the result */
                                fclose(mdstat);
                        }
                        fclose(mp);
index 8210278f356910fda95c9ac741475d8afcd80c17..59410d543e67c41285391a568e679711d88a5a22 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -399,16 +399,22 @@ out:
        return rv;
 }
 
-void bitmap_update_uuid(int fd, int *uuid)
+int bitmap_update_uuid(int fd, int *uuid)
 {
        struct bitmap_super_s bm;
-       lseek(fd, 0, 0);
+       if (lseek(fd, 0, 0) != 0)
+               return 1;
        if (read(fd, &bm, sizeof(bm)) != sizeof(bm))
-               return;
+               return 1;
        if (bm.magic != __cpu_to_le32(BITMAP_MAGIC))
-               return;
+               return 1;
        memcpy(bm.uuid, uuid, 16);
+       if (lseek(fd, 0, 0) != 0)
+               return 2;
+       if (write(fd, &bm, sizeof(bm)) != sizeof(bm)) {
+               lseek(fd, 0, 0);
+               return 2;
+       }
        lseek(fd, 0, 0);
-       write(fd, &bm, sizeof(bm));
-       lseek(fd, 0, 0);
+       return 0;
 }
diff --git a/mdadm.h b/mdadm.h
index 46d4ec0b9845317b415ed9e3e939db58a2c7b229..848c6f1ad9a6609fadcd5c76cc1043956734391c 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -381,7 +381,7 @@ extern int CreateBitmap(char *filename, int force, char uuid[16],
                        unsigned long long array_size,
                        int major);
 extern int ExamineBitmap(char *filename, int brief, struct supertype *st);
-extern void bitmap_update_uuid(int fd, int *uuid);
+extern int bitmap_update_uuid(int fd, int *uuid);
 
 extern int md_get_version(int fd);
 extern int get_linux_version(void);
index 4d0230049a860c9ef7c427a8ef37c39a550ff7d1..f14f076cad58a79aef83a32e826789275f368463 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -625,7 +625,8 @@ static int store_super0(struct supertype *st, int fd, void *sbv)
        if (super->state & (1<<MD_SB_BITMAP_PRESENT)) {
                struct bitmap_super_s * bm = (struct bitmap_super_s*)(super+1);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC)
-                       write(fd, bm, sizeof(*bm));
+                       if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
+                           return 5;
        }
 
        fsync(fd);
index 8f648f6742efe34a257c2e3e2e02499c5630ed65..28332cd2a2d6dff41d9880af7213c3e59e4afeaf 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -715,7 +715,8 @@ static int store_super1(struct supertype *st, int fd, void *sbv)
                        (((char*)sb)+1024);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
                        locate_bitmap1(st, fd, sbv);
-                       write(fd, bm, sizeof(*bm));
+                       if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
+                           return 5;
                }
        }
        fsync(fd);