viced/callback.c: Ignore dump write errors harder
authorJeffrey Hutzelman <jhutz@cmu.edu>
Wed, 19 Jun 2013 03:12:46 +0000 (23:12 -0400)
committerDerrick Brashear <shadow@your-file-system.com>
Wed, 19 Jun 2013 16:54:59 +0000 (09:54 -0700)
When writing a callback state dump, test the return values from
write(2), but don't do anything based on the test.  This avoids
compiler warnings when building on Ubuntu 12.10, with gcc 4.7.2 and
eglibc 2.15-0ubuntu20.1.  This adds a new macro, WriteBytes(), which
handles writing a requested number of bytes to a file and ignoring
errors.

Change-Id: Icead6b25a290cea09a91184dc12b7449cfaaf6f7
Reviewed-on: http://gerrit.openafs.org/9991
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/viced/callback.c

index 5460702..edc2c63 100644 (file)
@@ -2646,6 +2646,8 @@ cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
 }
 #endif /* AFS_DEMAND_ATTACH_FS */
 
+#define DumpBytes(fd,buf,req) if (write(fd, buf, req) < 0) ; /* don't care */
+
 static int
 DumpCallBackState_r(void)
 {
@@ -2663,19 +2665,23 @@ DumpCallBackState_r(void)
                 AFSDIR_SERVER_CBKDUMP_FILEPATH));
        return 0;
     }
-    (void)write(fd, &magic, sizeof(magic));
-    (void)write(fd, &now, sizeof(now));
-    (void)write(fd, &cbstuff, sizeof(cbstuff));
-    (void)write(fd, TimeOuts, sizeof(TimeOuts));
-    (void)write(fd, timeout, sizeof(timeout));
-    (void)write(fd, &tfirst, sizeof(tfirst));
+    /*
+     * Collect but ignoring the return value of write(2) here,
+     * to avoid compiler warnings on some platforms.
+     */
+    DumpBytes(fd, &magic, sizeof(magic));
+    DumpBytes(fd, &now, sizeof(now));
+    DumpBytes(fd, &cbstuff, sizeof(cbstuff));
+    DumpBytes(fd, TimeOuts, sizeof(TimeOuts));
+    DumpBytes(fd, timeout, sizeof(timeout));
+    DumpBytes(fd, &tfirst, sizeof(tfirst));
     freelisthead = cbtoi((struct CallBack *)CBfree);
-    (void)write(fd, &freelisthead, sizeof(freelisthead));      /* This is a pointer */
+    DumpBytes(fd, &freelisthead, sizeof(freelisthead));        /* This is a pointer */
     freelisthead = fetoi((struct FileEntry *)FEfree);
-    (void)write(fd, &freelisthead, sizeof(freelisthead));      /* This is a pointer */
-    (void)write(fd, HashTable, sizeof(HashTable));
-    (void)write(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks);    /* CB stuff */
-    (void)write(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks);    /* FE stuff */
+    DumpBytes(fd, &freelisthead, sizeof(freelisthead));        /* This is a pointer */
+    DumpBytes(fd, HashTable, sizeof(HashTable));
+    DumpBytes(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks);      /* CB stuff */
+    DumpBytes(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks);      /* FE stuff */
     close(fd);
 
     return 0;