Ignore return values more harder
authorBenjamin Kaduk <kaduk@mit.edu>
Fri, 6 Feb 2015 19:15:11 +0000 (14:15 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 29 May 2015 11:29:42 +0000 (07:29 -0400)
Building on Ubuntu 14.04 with gcc 4.8.2-19ubuntu1, we encounter
fatal warnings about unchecked return values in uss, which is
now always built, as of 00a33b26d74aa067086ddc340efb82184715857f.

Change-Id: I997dcb683e33902c2765121c70bdcf21e9d5e892
Reviewed-on: http://gerrit.openafs.org/11757
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams <3chas3@gmail.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/uss/uss_procs.c

index 4d39f08..4e48071 100644 (file)
@@ -506,7 +506,7 @@ Copy(char *a_from, char *a_to, int a_mode)
 
     int fd1, fd2;
     char buf[BUFSIZ];
-    int cnt, rc;
+    int rcnt, wcnt = -1, rc;
 
     umask(0);
     fd1 = open(a_to, O_EXCL | O_CREAT | O_WRONLY, a_mode);
@@ -537,10 +537,18 @@ Copy(char *a_from, char *a_to, int a_mode)
        close(fd1);
        return (1);
     }
-    while ((cnt = read(fd2, buf, BUFSIZ)) == BUFSIZ)
-       write(fd1, buf, cnt);
-
-    write(fd1, buf, cnt);
+    do {
+       rcnt = read(fd2, buf, BUFSIZ);
+       if (rcnt == -1)
+           break;
+       wcnt = write(fd1, buf, rcnt);
+    } while (rcnt == BUFSIZ && rcnt == wcnt);
+    if (rcnt == -1 || wcnt != rcnt) {
+       uss_procs_PrintErr(line, "read/write error to %s\n", a_to);
+       close(fd1);
+       close(fd2);
+       return (1);
+    }
     rc = close(fd1);
     if (rc) {
        uss_procs_PrintErr(line, "Failed to close '%s' %s\n", a_to,
@@ -608,8 +616,12 @@ Echo(char *a_s, char *a_f, int a_mode)
            return (1);
        }
     }
-    write(fd, a_s, strlen(a_s));
-    write(fd, "\n", 1);
+    if (write(fd, a_s, strlen(a_s)) != strlen(a_s) ||
+       write(fd, "\n", 1) != 1) {
+       uss_procs_PrintErr(line, "Short write to '%s'\n", a_f);
+       close(fd);
+       return (1);
+    }
     if (close(fd)) {
        uss_procs_PrintErr(line, "Failed to close '%s': %s\n", a_f,
                           strerror(errno));