Fix some warn_unused_result compile warnings
authorStelian Pop <stelian@popies.net>
Fri, 11 Jun 2010 11:19:17 +0000 (11:19 +0000)
committerStelian Pop <stelian@popies.net>
Fri, 11 Jun 2010 11:19:17 +0000 (11:19 +0000)
CHANGES
common/dumprmt.c
restore/dirs.c
restore/symtab.c
restore/tape.c
restore/utilities.c
restore/xattr.c
rmt/cipher.c
rmt/rmt.c

diff --git a/CHANGES b/CHANGES
index dcdf0463529f9b631db98336062c63751b3ad97d..8ff2dfd105ed0fffe7a680de6cc87bb850fa6f80 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,4 @@
-$Id: CHANGES,v 1.315 2010/06/11 09:57:31 stelian Exp $
+$Id: CHANGES,v 1.316 2010/06/11 11:19:17 stelian Exp $
 
 Changes between versions 0.4b42 and 0.4b43 (released ?????????????)
 ===================================================================
@@ -57,6 +57,8 @@ Changes between versions 0.4b42 and 0.4b43 (released ?????????????)
 12.    Extract dumped UNIX sockets instead of ignoring them.
        (Sourceforge bug #3007216).
 
+13.    Compiler warning fixes (mainly warn_unused_result ones).
+
 Changes between versions 0.4b41 and 0.4b42 (released June 18, 2009)
 ===================================================================
 
index e05325c564d84be2c05316be1694cc5548503078..ba824f27d70593fef1917c75a12cc8ad9f2f5420 100644 (file)
@@ -37,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: dumprmt.c,v 1.29 2006/03/13 10:33:44 stelian Exp $";
+       "$Id: dumprmt.c,v 1.30 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -342,8 +342,10 @@ rmtwrite(const char *buf, size_t count)
        char line[30];
 
        (void)snprintf(line, sizeof (line), "W%ld\n", (long)count);
-       write(tormtape, line, strlen(line));
-       write(tormtape, buf, count);
+       if (write(tormtape, line, strlen(line)) != strlen(line))
+               return -1;
+       if (write(tormtape, buf, count) != count)
+               return -1;
        return (rmtreply("write"));
 }
 
index 2717f9421dc0b2588132e3682a9c9358299df867..b987b6999bc69f09343201e2f596ed23db5e23fe 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: dirs.c,v 1.35 2008/04/17 15:16:47 stelian Exp $";
+       "$Id: dirs.c,v 1.36 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -495,7 +495,7 @@ putent(struct direct *dp)
        if (dirloc + dp->d_reclen > DIRBLKSIZ) {
                ((struct direct *)(dirbuf + prev))->d_reclen =
                    DIRBLKSIZ - prev;
-               if ( fwrite(dirbuf, 1, DIRBLKSIZ, df) != DIRBLKSIZ )
+               if ( fwrite(dirbuf, DIRBLKSIZ, 1, df) != 1 )
                        err(1,"cannot write to file %s", dirfile);
                dirloc = 0;
        }
@@ -683,13 +683,17 @@ setdirmodes(int flags)
        clearerr(mf);
        for (;;) {
                char xattr[XATTR_MAXSIZE];
-               (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf);
-               if (feof(mf))
-                       break;
-               if (node.xattr) {
-                       (void) fread(xattr, 1, XATTR_MAXSIZE, mf);
+               if (fread((char *)&node, sizeof(struct modeinfo), 1, mf) != 1) {
                        if (feof(mf))
                                break;
+                       err(1, "fread");
+               }
+               if (node.xattr) {
+                       if (fread(xattr, XATTR_MAXSIZE, 1, mf) != 1) {
+                               if (feof(mf))
+                                       break;
+                               err(1, "fread");
+                       }
                }
                ep = lookupino(node.ino);
                if (command == 'i' || command == 'x') {
@@ -708,7 +712,8 @@ setdirmodes(int flags)
                        panic("cannot find directory inode %d\n", node.ino);
                } else {
                        cp = myname(ep);
-                       (void) chown(cp, node.uid, node.gid);
+                       if (chown(cp, node.uid, node.gid) < 0)
+                               warn("chown");
                        (void) chmod(cp, node.mode);
                        utimes(cp, node.timep);
                        if (node.xattr)
@@ -757,13 +762,17 @@ comparedirmodes(void)
        clearerr(mf);
        for (;;) {
                char xattr[XATTR_MAXSIZE];
-               (void) fread((char *)&node, 1, sizeof(struct modeinfo), mf);
-               if (feof(mf))
-                       break;
-               if (node.xattr) {
-                       (void) fread(xattr, 1, XATTR_MAXSIZE, mf);
+               if (fread((char *)&node, sizeof(struct modeinfo), 1, mf) != 1) {
                        if (feof(mf))
                                break;
+                       err(1, "fread");
+               }
+               if (node.xattr) {
+                       if (fread(xattr, XATTR_MAXSIZE, 1, mf) != 1) {
+                               if (feof(mf))
+                                       break;
+                               err(1, "fread");
+                       }
                }
                ep = lookupino(node.ino);
                if (ep == NULL) {
@@ -928,10 +937,10 @@ savemodeinfo(dump_ino_t ino, struct dinode *dip, char *xattr) {
        node.uid = dip->di_uid;
        node.gid = dip->di_gid;
        node.xattr = xattr ? 1 : 0;
-       if ( fwrite((char *)&node, 1, sizeof(struct modeinfo), mf) != sizeof(struct modeinfo) )
+       if ( fwrite((char *)&node, sizeof(struct modeinfo), 1, mf) != 1 )
                err(1,"cannot write to file %s", modefile);
        if (xattr)
-               if ( fwrite(xattr, 1, XATTR_MAXSIZE, mf) != XATTR_MAXSIZE)
+               if ( fwrite(xattr, XATTR_MAXSIZE, 1, mf) != 1 )
                        err(1,"cannot write to file %s", modefile);
 }
 
index 7e5605730db48ce73ca6472178b1bcd6f5b668cd..c3c941e21f685e9709b20485fe4786286c88bdd8 100644 (file)
@@ -37,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: symtab.c,v 1.27 2005/07/07 09:16:08 stelian Exp $";
+       "$Id: symtab.c,v 1.28 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 /*
@@ -568,8 +568,8 @@ dumpsymtable(char *filename, long checkpt)
        for (i = WINO; i <= maxino; i++) {
                for (ep = lookupino(i); ep != NULL; ep = ep->e_links) {
                        ep->e_index = mynum++;
-                       (void) fwrite(ep->e_name, sizeof(char),
-                              (int)allocsize(ep->e_namlen), fd);
+                       (void) fwrite(ep->e_name, (int)allocsize(ep->e_namlen),
+                                     sizeof(char), fd);
                }
        }
        /*
@@ -587,7 +587,7 @@ dumpsymtable(char *filename, long checkpt)
                                        if (temphash[j])
                                                temphash[j] = (struct entry *)ep->e_entries[j]->e_index;
                                }
-                               fwrite(temphash, dirhash_size, sizeof(struct entry *), fd);
+                               fwrite(temphash, sizeof(struct entry *), dirhash_size, fd);
                        }
                }
        }
index 395c99e9a81fb7a806a2acdca977653277c0146a..45d156f5abd02dfeff2b2fd718f9daf7b29ff8f6 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.98 2010/06/11 09:57:31 stelian Exp $";
+       "$Id: tape.c,v 1.99 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -522,7 +522,8 @@ again:
                do      {
                        fprintf(stderr, "Specify next volume # (none if no more volumes): ");
                        (void) fflush(stderr);
-                       (void) fgets(buf, TP_BSIZE, terminal);
+                       if (!fgets(buf, TP_BSIZE, terminal))
+                               break;
                } while (!feof(terminal) && buf[0] == '\n');
                if (feof(terminal))
                        exit(1);
@@ -585,7 +586,8 @@ again:
                fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
 #endif
                (void) fflush(stderr);
-               (void) fgets(buf, TP_BSIZE, terminal);
+               if (fgets(buf, TP_BSIZE, terminal))
+                       exit(1);
                if (feof(terminal))
                        exit(1);
                if (!strcmp(buf, "none\n")) {
@@ -872,8 +874,10 @@ extractfile(struct entry *ep, int doremove)
                        }
                        close(sk);
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -929,7 +933,8 @@ extractfile(struct entry *ep, int doremove)
                        skipfile();
 
 #ifdef HAVE_LCHOWN
-               (void) lchown(name, luid, lgid);
+               if (lchown(name, luid, lgid) < 0)
+                       warn("%s: lchown", name);
 #endif
                extractattr(name);
                return (GOOD);
@@ -952,8 +957,10 @@ extractfile(struct entry *ep, int doremove)
                                return (FAIL);
                        }
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -990,8 +997,10 @@ extractfile(struct entry *ep, int doremove)
                                return (FAIL);
                        }
                }
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -1039,8 +1048,10 @@ extractfile(struct entry *ep, int doremove)
                }
                else
                        skipfile();
-               (void) chown(name, luid, lgid);
-               (void) chmod(name, mode);
+               if (chown(name, luid, lgid) < 0)
+                       warn("%s: chown", name);
+               if (chmod(name, mode) < 0)
+                       warn("%s: chmod", name);
                extractattr(name);
                utimes(name, timep);
                if (flags)
@@ -1260,8 +1271,10 @@ extractresourceufs(char *name)
                /* and add the resource data from tape */
                getfile(xtrfile, xtrskip);
 
-               (void) fchown(ofile, uid, gid);
-               (void) fchmod(ofile, mode);
+               if (fchown(ofile, uid, gid) < 0)
+                       warn("%s: fchown", name);
+               if (fchmod(ofile, mode) < 0)
+                       warn("%s: fchmod", name);
                (void) close(ofile);
                utimes(oFileRsrc, timep);
                (void) lsetflags(oFileRsrc, flags);
@@ -1413,7 +1426,8 @@ loop:
                last_write_was_hole = 1;
        }
        if (last_write_was_hole) {
-               FTRUNCATE(ofile, origsize);
+               if (FTRUNCATE(ofile, origsize) < 0)
+                       warn("%s: ftruncate", curfile.name);
        }
        if (!readingmaps) 
                findinode(&spcl);
@@ -2407,8 +2421,8 @@ decompress_tapebuf(struct tapebuf *tpbin, int readsize)
        }
        if (reason) {
                if (lengtherr)
-                       fprintf(stderr, "%s compressed block: %d expected: %u\n",
-                               lengtherr, readsize, tpbin->length + PREFIXSIZE);
+                       fprintf(stderr, "%s compressed block: %d expected: %lu\n",
+                               lengtherr, readsize, (unsigned long)tpbin->length + PREFIXSIZE);
                fprintf(stderr, "decompression error, block %ld: %s\n",
                        tpblksread+1, reason);
                if (!cresult)
index 4dbc13fd139bf31d8c1e8311f411dbc10a4ead8a..67b223ee26542298de4794621dfb8d3fb000fb3f 100644 (file)
@@ -37,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: utilities.c,v 1.29 2005/07/07 09:16:08 stelian Exp $";
+       "$Id: utilities.c,v 1.30 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -488,7 +488,8 @@ panic(fmt, va_alist)
                return;
        if (reply("abort") == GOOD) {
                if (reply("dump core") == GOOD) {
-                       fchdir(wdfd);
+                       if (fchdir(wdfd) < 0)
+                               warn("fchdir");
                        abort();
                }
                exit(1);
index ccc01c14c21e74177ce4b4af95cdf4f227b79991..ddabfa2e9f38e8eb8db728836d73efc97cbdfe41 100644 (file)
@@ -29,7 +29,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: xattr.c,v 1.6 2010/03/08 10:40:52 stelian Exp $";
+       "$Id: xattr.c,v 1.7 2010/06/11 11:19:17 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -91,9 +91,11 @@ struct ext2_xattr_entry {
 #define EXT2_XATTR_PAD_BITS            2
 #define EXT2_XATTR_PAD         (1<<EXT2_XATTR_PAD_BITS)
 #define EXT2_XATTR_ROUND               (EXT2_XATTR_PAD-1)
+#ifndef EXT2_XATTR_LEN
 #define EXT2_XATTR_LEN(name_len) \
        (((name_len) + EXT2_XATTR_ROUND + \
        sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
+#endif
 #define EXT2_XATTR_NEXT(entry) \
        ( (struct ext2_xattr_entry *)( \
          (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
@@ -306,7 +308,7 @@ posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) {
        if (!buffer)
                return real_size;
        if (real_size > size) {
-               fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, size);
+               fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, (int)size);
                return -1;
        }
 
@@ -463,7 +465,7 @@ xattr_cb_compare(char *name, char *value, int valuelen, int isSELinux, void *pri
                
                valuesz = strlen(con) + 1;
                valuef[0] = 0;
-               strncat(valuef, con, sizeof valuef);
+               strncat(valuef, con, sizeof(valuef) - 1);
                freecon(con);
        }
        else {
@@ -615,7 +617,7 @@ xattr_walk(char *buffer, int (*xattr_cb)(char *, char *, int, int, void *), void
                        if (!transselinuxarg)
                                err = security_canonicalize_context(value, &con);
                        else {
-                               strncat(value, transselinuxarg, sizeof value);
+                               strncat(value, transselinuxarg, sizeof(value) - 1);
                                err = security_canonicalize_context_raw(value, &con);
                        }
                        
@@ -626,7 +628,7 @@ xattr_walk(char *buffer, int (*xattr_cb)(char *, char *, int, int, void *), void
 
                        size = strlen(con) + 1;
                        value[0] = 0;
-                       strncat(value, con, sizeof value);
+                       strncat(value, con, sizeof(value) - 1);
                        freecon(con);
                }
 #endif
index 48da098f2c3c7e1788de19aae8872b235c3b7c8b..8ad219c2c9ef935cacf1906e9ed6562d474b9748 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <syslog.h>
+#include <string.h>
 #include <strings.h>
 #include <errno.h>
 #include <openssl/evp.h>
@@ -51,7 +52,10 @@ cipher(char *buf, int buflen, int do_encrypt)
                        return NULL;
                }
                buf[0] = '\0';
-               fgets(buf, sizeof buf, fp);
+               if (!fgets(buf, sizeof buf, fp)) {
+                       syslog(LOG_ERR, "Error reading key file %s: %m", keyfile);
+                       return NULL;
+               }
                fclose(fp);
                i = strlen(buf);
                if ((i > 0) &&
index 05874a3f6a52f2d2e01d833c3747deb8d0efc6e8..863f12651c68bd103a1972fd52a2078a889ead97 100644 (file)
--- a/rmt/rmt.c
+++ b/rmt/rmt.c
@@ -37,7 +37,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: rmt.c,v 1.28 2003/11/22 16:52:16 stelian Exp $";
+       "$Id: rmt.c,v 1.29 2010/06/11 11:19:18 stelian Exp $";
 #endif /* not linux */
 
 /*
@@ -310,8 +310,10 @@ top:
                cp = record;
 #endif
                (void)sprintf(resp, "A%lld\n", (long long)rval);
-               (void)write(1, resp, strlen(resp));
-               (void)write(1, cp, rval);
+               if (write(1, resp, strlen(resp)) != strlen(resp))
+                       goto ioerror;
+               if (write(1, cp, rval) != rval)
+                       goto ioerror;
                block += n >> 10;
                goto top;
 
@@ -475,13 +477,17 @@ top:
                        mtget.mt_fileno = swaplong(mtget.mt_fileno);
                        mtget.mt_blkno = swaplong(mtget.mt_blkno);
                        (void)sprintf(resp, "A%lld\n", (long long)rval);
-                       (void)write(1, resp, strlen(resp));
-                       (void)write(1, (char *)&mtget, sizeof (mtget));
+                       if (write(1, resp, strlen(resp)) != strlen(resp))
+                               goto ioerror;
+                       if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget))
+                               goto ioerror;
                  } else {
                        rval = sizeof (mtget);
                        (void)sprintf(resp, "A%lld\n", (long long)rval);
-                       (void)write(1, resp, strlen(resp));
-                       (void)write(1, (char *)&mtget, sizeof (mtget));
+                       if (write(1, resp, strlen(resp)) != strlen(resp))
+                               goto ioerror;
+                       if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget))
+                               goto ioerror;
                  }
                  goto top;
                }
@@ -546,7 +552,8 @@ top:
 respond:
        DEBUG1("rmtd: A %lld\n", (long long)rval);
        (void)sprintf(resp, "A%lld\n", (long long)rval);
-       (void)write(1, resp, strlen(resp));
+       if (write(1, resp, strlen(resp)) != strlen(resp))
+               goto ioerror;
        goto top;
 ioerror:
        error(errno);
@@ -593,7 +600,8 @@ error(int num)
 
        DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));
        (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num));
-       (void)write(1, resp, strlen(resp));
+       if (write(1, resp, strlen(resp)) != strlen(resp))
+               DEBUG("rmtd: write error\n");
 }
 
 static unsigned long