From: Benjamin Kaduk Date: Fri, 6 Feb 2015 19:15:11 +0000 (-0500) Subject: Ignore return values more harder X-Git-Tag: openafs-stable-1_8_0pre1~318 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=c19cadbf6a7b625f034f26245dcba225afc03aba Ignore return values more harder 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 Tested-by: BuildBot Reviewed-by: Chas Williams <3chas3@gmail.com> Reviewed-by: Jeffrey Altman --- diff --git a/src/uss/uss_procs.c b/src/uss/uss_procs.c index 4d39f08..4e48071 100644 --- a/src/uss/uss_procs.c +++ b/src/uss/uss_procs.c @@ -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));