]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
In recent Fedora builds, the '-D _FORTIFY_SOURCE=2' compile nfs-utils-1-1-6-rc3
authorSteve Dickson <steved@redhat.com>
Mon, 23 Mar 2009 21:13:01 +0000 (17:13 -0400)
committerSteve Dickson <steved@redhat.com>
Mon, 23 Mar 2009 21:13:01 +0000 (17:13 -0400)
flag has been set. This cause warnings to be generated when
return values from reads/writes (and other calls) are not
checked. The patch address those warnings.

Signed-off-by: Steve Dickson <steved@redhat.com>
support/nfs/cacheio.c
tools/locktest/testlk.c
utils/gssd/svcgssd.c
utils/idmapd/idmapd.c
utils/mount/fstab.c
utils/statd/monitor.c
utils/statd/sm-notify.c
utils/statd/statd.c

index 48292f8a5d49841c48f323c1b5977691396ef6be..f30373402d0888009abd53f07f14da690c45f6dd 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
+#include <errno.h>
 
 void qword_add(char **bpp, int *lp, char *str)
 {
 
 void qword_add(char **bpp, int *lp, char *str)
 {
@@ -125,7 +126,10 @@ void qword_print(FILE *f, char *str)
        char *bp = qword_buf;
        int len = sizeof(qword_buf);
        qword_add(&bp, &len, str);
        char *bp = qword_buf;
        int len = sizeof(qword_buf);
        qword_add(&bp, &len, str);
-       fwrite(qword_buf, bp-qword_buf, 1, f);
+       if (fwrite(qword_buf, bp-qword_buf, 1, f) != 1) {
+               xlog_warn("qword_print: fwrite failed: errno %d (%s)",
+                       errno, strerror(errno));
+       }
 }
 
 void qword_printhex(FILE *f, char *str, int slen)
 }
 
 void qword_printhex(FILE *f, char *str, int slen)
@@ -133,7 +137,10 @@ void qword_printhex(FILE *f, char *str, int slen)
        char *bp = qword_buf;
        int len = sizeof(qword_buf);
        qword_addhex(&bp, &len, str, slen);
        char *bp = qword_buf;
        int len = sizeof(qword_buf);
        qword_addhex(&bp, &len, str, slen);
-       fwrite(qword_buf, bp-qword_buf, 1, f);
+       if (fwrite(qword_buf, bp-qword_buf, 1, f) != 1) {
+               xlog_warn("qword_printhex: fwrite failed: errno %d (%s)",
+                       errno, strerror(errno));
+       }
 }
 
 void qword_printint(FILE *f, int num)
 }
 
 void qword_printint(FILE *f, int num)
@@ -318,7 +325,10 @@ cache_flush(int force)
                sprintf(path, "/proc/net/rpc/%s/flush", cachelist[c]);
                fd = open(path, O_RDWR);
                if (fd >= 0) {
                sprintf(path, "/proc/net/rpc/%s/flush", cachelist[c]);
                fd = open(path, O_RDWR);
                if (fd >= 0) {
-                       write(fd, stime, strlen(stime));
+                       if (write(fd, stime, strlen(stime)) != strlen(stime)) {
+                               xlog_warn("Writing to '%s' failed: errno %d (%s)",
+                               path, errno, strerror(errno));
+                       }
                        close(fd);
                }
        }
                        close(fd);
                }
        }
index b392f711fcb9eea9edfc3b62e42ae7750bfa2c35..82ed7657051d381e3e437a2dbcf0b4ba0005365e 100644 (file)
@@ -81,7 +81,7 @@ main(int argc, char **argv)
                if (fl.l_type == F_UNLCK) {
                        printf("%s: no conflicting lock\n", fname);
                } else {
                if (fl.l_type == F_UNLCK) {
                        printf("%s: no conflicting lock\n", fname);
                } else {
-                       printf("%s: conflicting lock by %d on (%ld;%ld)\n",
+                       printf("%s: conflicting lock by %d on (%lld;%lld)\n",
                                fname, fl.l_pid, fl.l_start, fl.l_len);
                }
                return 0;
                                fname, fl.l_pid, fl.l_start, fl.l_len);
                }
                return 0;
index f97dcd37cfadf9c1fbf2021cc524b19f0b013a40..6ca0e8d762bf2ae36c321b97bb54f7efbfafd6cf 100644 (file)
@@ -132,7 +132,11 @@ release_parent(void)
        int status;
 
        if (pipefds[1] > 0) {
        int status;
 
        if (pipefds[1] > 0) {
-               write(pipefds[1], &status, 1);
+               if (write(pipefds[1], &status, 1) != 1) {
+                       printerr(1, 
+                               "WARN: writing to parent pipe failed: errno %d (%s)\n",
+                               errno, strerror(errno));
+               }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
index c1cf4eb40e09471a5ff3c58141b2bb276c3881c5..b690e21fae9697a4e9ec6d0dc5221759576cacb3 100644 (file)
@@ -169,7 +169,10 @@ flush_nfsd_cache(char *path, time_t now)
        fd = open(path, O_RDWR);
        if (fd == -1)
                return -1;
        fd = open(path, O_RDWR);
        if (fd == -1)
                return -1;
-       write(fd, stime, strlen(stime));
+       if (write(fd, stime, strlen(stime)) != strlen(stime)) {
+               errx(1, "Flushing nfsd cache failed: errno %d (%s)",
+                       errno, strerror(errno));
+       }
        close(fd);
        return 0;
 }
        close(fd);
        return 0;
 }
@@ -988,7 +991,10 @@ release_parent(void)
        int status;
 
        if (pipefds[1] > 0) {
        int status;
 
        if (pipefds[1] > 0) {
-               write(pipefds[1], &status, 1);
+               if (write(pipefds[1], &status, 1) != 1) {
+                       err(1, "Writing to parent pipe failed: errno %d (%s)\n",
+                               errno, strerror(errno));
+               }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
index e19e58b0d95fa9d246e6a0034adf5480644bf6c2..7668167ba61edaec579c222b5e8ba3cd4d3f6068 100644 (file)
@@ -546,8 +546,12 @@ update_mtab (const char *dir, struct mntent *instead)
           * from the present mtab before renaming.
           */
            struct stat sbuf;
           * from the present mtab before renaming.
           */
            struct stat sbuf;
-           if (stat (MOUNTED, &sbuf) == 0)
-               chown (MOUNTED_TEMP, sbuf.st_uid, sbuf.st_gid);
+           if (stat (MOUNTED, &sbuf) == 0) {
+                       if (chown (MOUNTED_TEMP, sbuf.st_uid, sbuf.st_gid) < 0) {
+                               nfs_error(_("%s: error changing owner of %s: %s"),
+                                       progname, MOUNTED_TEMP, strerror (errno));
+                       }
+               }
        }
 
        /* rename mtemp to mtab */
        }
 
        /* rename mtemp to mtab */
index 169cd78ac82b17a99c5ce90850bb97f4d4fac901..a2c9e2b091c126d2d24b84a870f946f1f479ca68 100644 (file)
@@ -204,7 +204,10 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
                        e += sprintf(e, "%02x", 0xff & (argp->priv[i]));
                if (e+1-buf != LINELEN) abort();
                e += sprintf(e, " %s %s\n", mon_name, my_name);
                        e += sprintf(e, "%02x", 0xff & (argp->priv[i]));
                if (e+1-buf != LINELEN) abort();
                e += sprintf(e, " %s %s\n", mon_name, my_name);
-               write(fd, buf, e-buf);
+               if (write(fd, buf, e-buf) != (e-buf)) {
+                       note(N_WARNING, "writing to %s failed: errno %d (%s)",
+                               path, errno, strerror(errno));
+               }
        }
 
        free(path);
        }
 
        free(path);
index d58e0be421859ed6c59880e917d53a53a874b877..f1fc619a9b4c3ab9398e27d073af588d81bdf31a 100644 (file)
@@ -782,7 +782,10 @@ static int record_pid(void)
        fd = open("/var/run/sm-notify.pid", O_CREAT|O_EXCL|O_WRONLY, 0600);
        if (fd < 0)
                return 0;
        fd = open("/var/run/sm-notify.pid", O_CREAT|O_EXCL|O_WRONLY, 0600);
        if (fd < 0)
                return 0;
-       write(fd, pid, strlen(pid));
+       if (write(fd, pid, strlen(pid)) != strlen(pid))  {
+               nsm_log(LOG_WARNING, "Writing to pid file failed: errno %d(%s)",
+                       errno, strerror(errno));
+       }
        close(fd);
        return 1;
 }
        close(fd);
        return 1;
 }
@@ -818,12 +821,16 @@ static void drop_privs(void)
 static void set_kernel_nsm_state(int state)
 {
        int fd;
 static void set_kernel_nsm_state(int state)
 {
        int fd;
+       const char *file = "/proc/sys/fs/nfs/nsm_local_state";
 
 
-       fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY);
+       fd = open(file ,O_WRONLY);
        if (fd >= 0) {
                char buf[20];
                snprintf(buf, sizeof(buf), "%d", state);
        if (fd >= 0) {
                char buf[20];
                snprintf(buf, sizeof(buf), "%d", state);
-               write(fd, buf, strlen(buf));
+               if (write(fd, buf, strlen(buf)) != strlen(buf)) {
+                       nsm_log(LOG_WARNING, "Writing to '%s' failed: errno %d (%s)",
+                               file, errno, strerror(errno));
+               }
                close(fd);
        }
 }
                close(fd);
        }
 }
index 6da2ab283d145284d2f919e7c3ec3faf35933463..1c5247ea2365aa0112ecda69956b95e04862d014 100644 (file)
@@ -179,14 +179,20 @@ static void create_pidfile(void)
                    pidfile, strerror(errno));
        fprintf(fp, "%d\n", getpid());
        pidfd = dup(fileno(fp));
                    pidfile, strerror(errno));
        fprintf(fp, "%d\n", getpid());
        pidfd = dup(fileno(fp));
-       if (fclose(fp) < 0)
-               note(N_WARNING, "Flushing pid file failed.\n");
+       if (fclose(fp) < 0) {
+               note(N_WARNING, "Flushing pid file failed: errno %d (%s)\n",
+                       errno, strerror(errno));
+       }
 }
 
 static void truncate_pidfile(void)
 {
 }
 
 static void truncate_pidfile(void)
 {
-       if (pidfd >= 0)
-               ftruncate(pidfd, 0);
+       if (pidfd >= 0) {
+               if (ftruncate(pidfd, 0) < 0) {
+                       note(N_WARNING, "truncating pid file failed: errno %d (%s)\n",
+                               errno, strerror(errno));
+               }
+       }
 }
 
 static void drop_privs(void)
 }
 
 static void drop_privs(void)
@@ -207,9 +213,12 @@ static void drop_privs(void)
        /* better chown the pid file before dropping, as if it
         * if over nfs we might loose access
         */
        /* better chown the pid file before dropping, as if it
         * if over nfs we might loose access
         */
-       if (pidfd >= 0)
-               fchown(pidfd, st.st_uid, st.st_gid);
-
+       if (pidfd >= 0) {
+               if (fchown(pidfd, st.st_uid, st.st_gid) < 0) {
+                       note(N_ERROR, "Unable to change owner of %s: %d (%s)",
+                                       SM_DIR, strerror (errno));
+               }
+       }
        setgroups(0, NULL);
        if (setgid(st.st_gid) == -1
            || setuid(st.st_uid) == -1) {
        setgroups(0, NULL);
        if (setgid(st.st_gid) == -1
            || setuid(st.st_uid) == -1) {
@@ -495,7 +504,10 @@ int main (int argc, char **argv)
        /* If we got this far, we have successfully started, so notify parent */
        if (pipefds[1] > 0) {
                status = 0;
        /* If we got this far, we have successfully started, so notify parent */
        if (pipefds[1] > 0) {
                status = 0;
-               write(pipefds[1], &status, 1);
+               if (write(pipefds[1], &status, 1) != 1) {
+                       note(N_WARNING, "writing to parent pipe failed: errno %d (%s)\n",
+                               errno, strerror(errno));
+               }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
                close(pipefds[1]);
                pipefds[1] = -1;
        }
@@ -534,17 +546,23 @@ static void
 load_state_number(void)
 {
        int fd;
 load_state_number(void)
 {
        int fd;
+       const char *file = "/proc/sys/fs/nfs/nsm_local_state";
 
        if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1)
                return;
 
 
        if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1)
                return;
 
-       read(fd, &MY_STATE, sizeof(MY_STATE));
+       if (read(fd, &MY_STATE, sizeof(MY_STATE)) != sizeof(MY_STATE)) {
+               note(N_WARNING, "Unable to read state from '%s': errno %d (%s)",
+                               SM_STAT_PATH, errno, strerror(errno));
+       }
        close(fd);
        close(fd);
-       fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY);
+       fd = open(file, O_WRONLY);
        if (fd >= 0) {
                char buf[20];
                snprintf(buf, sizeof(buf), "%d", MY_STATE);
        if (fd >= 0) {
                char buf[20];
                snprintf(buf, sizeof(buf), "%d", MY_STATE);
-               write(fd, buf, strlen(buf));
+               if (write(fd, buf, strlen(buf)) != strlen(buf))
+                       note(N_WARNING, "Writing to '%s' failed: errno %d (%s)",
+                               file, errno, strerror(errno));
                close(fd);
        }
 
                close(fd);
        }