Whamcloud - gitweb
b=19720
authorbrian <brian>
Wed, 9 Sep 2009 20:04:06 +0000 (20:04 +0000)
committerbrian <brian>
Wed, 9 Sep 2009 20:04:06 +0000 (20:04 +0000)
i=adilger

Clean up various warnings stemming from unused variables and unchecked
function return values.

15 files changed:
lustre/include/liblustre.h
lustre/liblustre/llite_lib.c
lustre/liblustre/tests/recovery_small.c
lustre/liblustre/tests/sanity.c
lustre/lvfs/fsfilt.c
lustre/obdclass/genops.c
lustre/ptlrpc/ptlrpcd.c
lustre/tests/fsx.c
lustre/tests/mmap_sanity.c
lustre/utils/llverdev.c
lustre/utils/ltrack_stats.c
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/obd.c

index aa7ddca..9ef8337 100644 (file)
@@ -265,7 +265,7 @@ static inline int misc_deregister(void *foo)
         return 0;
 }
 
-static inline int request_module(char *name)
+static inline int request_module(const char *name, ...)
 {
         return (-EINVAL);
 }
index 651d9f2..46b44fe 100644 (file)
@@ -406,7 +406,7 @@ void __liblustre_cleanup_(void)
          * but it can't fix the situation that liblustre is mounted
          * at "/".
          */
-        chdir("/");
+        if (!chdir("/")) {}
 #if 0
         umount(lustre_path);
 #endif
index 3058a77..66c3d10 100644 (file)
@@ -50,6 +50,7 @@
 #include <fcntl.h>
 #include <sys/queue.h>
 #include <getopt.h>
+#include <sys/wait.h>
 
 #include <sysio.h>
 #include <mount.h>
@@ -149,7 +150,8 @@ void cleanup_dir(const char *path)
             sprintf(cmd,                                                   \
                     "%s %s \"echo %lu > /proc/sys/lustre/fail_loc\"",      \
                     ssh_cmd, mds_server, drop_arr[drop_index].code);       \
-            if (system(cmd)) {                                             \
+            if ((rc = system(cmd)) != 0) {                                 \
+                rc = WEXITSTATUS(rc);                                      \
                 printf("error excuting remote command: %d\n", rc);         \
                 exit(rc);                                                  \
             }                                                              \
@@ -163,7 +165,7 @@ void cleanup_dir(const char *path)
         if (drop_arr[drop_index].name) {                                   \
             sprintf(cmd, "%s %s \"echo 0 > /proc/sys/lustre/fail_loc\"",   \
                     ssh_cmd, mds_server);                                  \
-            system(cmd);                                                   \
+            if (!system(cmd)) {}                                           \
         }                                                                  \
     } while (0)
 
index cb3d672..de17e13 100644 (file)
@@ -576,7 +576,8 @@ static int check_file_size(char *file, off_t size)
                 return(1);
         }
         if (statbuf.st_size != size) {
-                printf("size of %s: %ld != %lld\n", file, statbuf.st_size, (unsigned long long )size);
+                printf("size of %s: %lld != %lld\n", file,
+                       (long long)statbuf.st_size, (long long )size);
                 return(-1);
         }
         return 0;
@@ -611,7 +612,7 @@ int t20(char *name)
         int fd;
         struct iovec iov[2];
         char buf[100];
-        ssize_t ret;
+        long ret;
         ENTER("trap app's general bad pointer for file i/o");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t20_file", lustre_path);
 
@@ -728,7 +729,7 @@ int t22(char *name)
         int fd;
         char *str = "1234567890";
         char buf[100];
-        ssize_t ret;
+        long ret;
         ENTER("make sure O_APPEND take effect");
         snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path);
 
@@ -1090,8 +1091,14 @@ int t52(char *name)
         printf("st_atime=%s", ctime(&statbuf.st_atime));
         atime = statbuf.st_atime;
         for (i = 0; i < 3; i++) {
+                ssize_t num_read;
                 sleep(2);
-                read(fd, buf, sizeof(buf));
+                /* should not ignore read(2)'s return value */
+                num_read = read(fd, buf, sizeof(buf));
+                if (num_read < 0 ) {
+                        printf("read from %s: %s\n", file, strerror(errno));
+                        return -1;
+                }
                 stat(file, &statbuf);
                 printf("st_atime=%s", ctime(&statbuf.st_atime));
                 diff = statbuf.st_atime - atime;
@@ -1358,7 +1365,7 @@ int t56(char *name)
         int fd;
         size_t nbytes;
         off_t basep = 0;
-        ssize_t rc = 0;
+        long rc = 0;
         struct dirent dir;
 
         ENTER("getdirentries should fail if nbytes is too small");
index e650f8e..0100333 100644 (file)
@@ -113,7 +113,7 @@ struct fsfilt_operations *fsfilt_get_ops(const char *type)
                 snprintf(name, sizeof(name) - 1, "fsfilt_%s", type);
                 name[sizeof(name) - 1] = '\0';
 
-                if (!(rc = request_module(name))) {
+                if (!(rc = request_module("%s", name))) {
                         fs_ops = fsfilt_search_type(type);
                         CDEBUG(D_INFO, "Loaded module '%s'\n", name);
                         if (!fs_ops)
index 9f3ae9f..2bd00e3 100644 (file)
@@ -121,7 +121,7 @@ struct obd_type *class_get_type(const char *name)
                 const char *modname = name;
                 if (strcmp(modname, LUSTRE_MDT_NAME) == 0)
                         modname = LUSTRE_MDS_NAME;
-                if (!request_module(modname)) {
+                if (!request_module("%s", modname)) {
                         CDEBUG(D_INFO, "Loaded module '%s'\n", modname);
                         type = class_search_type(name);
                 } else {
index fe4a7d6..dde226c 100644 (file)
@@ -290,7 +290,7 @@ int ptlrpcd_start(char *name, struct ptlrpcd_ctl *pc)
         init_completion(&pc->pc_starting);
         init_completion(&pc->pc_finishing);
         spin_lock_init(&pc->pc_lock);
-        snprintf (pc->pc_name, sizeof (pc->pc_name), name);
+        strncpy(pc->pc_name, name, sizeof(pc->pc_name) - 1);
 
         pc->pc_set = ptlrpc_prep_set();
         if (pc->pc_set == NULL)
index dc97fd9..dafa888 100644 (file)
@@ -529,8 +529,15 @@ check_trunc_hack(void)
        struct stat statbuf;
        int fd = get_fd();
 
-       ftruncate(fd, (off_t)0);
-       ftruncate(fd, (off_t)100000);
+        /* should not ignore ftruncate(2)'s return value */
+        if (ftruncate(fd, (off_t)0) < 0) {
+                prterr("trunc_hack: ftruncate(0)");
+                exit(1);
+        }
+        if (ftruncate(fd, (off_t)100000) < 0) {
+                prterr("trunc_hack: ftruncate(100000)");
+                exit(1);
+        }
        if (fstat(fd, &statbuf)) {
                prterr("trunc_hack: fstat");
                statbuf.st_size = -1;
@@ -539,7 +546,10 @@ check_trunc_hack(void)
                prt("no extend on truncate! not posix!\n");
                exit(130);
        }
-       ftruncate(fd, 0);
+        if (ftruncate(fd, 0) < 0) {
+                prterr("trunc_hack: ftruncate(0) (2nd call)");
+                exit(1);
+        }
 }
 
 static char *tf_buf = NULL;
index 1cda15a..596ad8c 100644 (file)
@@ -158,7 +158,11 @@ static int mmap_tst1(char *mnt)
                 perror(mmap_file);
                 return errno;
         }
-        ftruncate(fd, region);
+        if (ftruncate(fd, region) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
 
         ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
         if (ptr == MAP_FAILED) {
@@ -193,7 +197,11 @@ static int mmap_tst2(char *mnt)
                 perror(mmap_file);
                 return errno;
         }
-        ftruncate(fd, page_size);
+        if (ftruncate(fd, page_size) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
 
         ptr = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
         if (ptr == MAP_FAILED) {
@@ -250,7 +258,11 @@ static int mmap_tst3(char *mnt)
                 perror(mmap_file);
                 return errno;
         }
-        ftruncate(fd, region);
+        if (ftruncate(fd, region) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
 
         ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
         if (ptr == MAP_FAILED) {
@@ -328,14 +340,22 @@ static int mmap_tst4(char *mnt)
                 perror(fileb);
                 return errno;
         }
-        ftruncate(fdr, region);
+        if (ftruncate(fdr, region) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
         fdw = open(filea, O_CREAT|O_RDWR, 0600);
         if (fdw < 0) {
                 perror(filea);
                 rc = errno;
                 goto out_close;
         }
-        ftruncate(fdw, region);
+        if (ftruncate(fdw, region) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
         
         ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fdr, 0);
         if (ptr == MAP_FAILED) {
@@ -494,7 +514,11 @@ static int mmap_tst5(char *mnt)
                 perror(mmap_file);
                 return errno;
         }
-        ftruncate(fd, region);
+        if (ftruncate(fd, region) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out_close;
+        }
 
         ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
         if (ptr == MAP_FAILED) {
@@ -549,7 +573,11 @@ static int mmap_tst6(char *mnt)
                 perror(mmap_file);
                 return errno;
         }
-        ftruncate(fd, page_size);
+        if (ftruncate(fd, page_size) < 0) {
+                perror("ftruncate()");
+                rc = errno;
+                goto out;
+        }
 
         fd2 = open(mmap_file2, O_RDWR, 0600);
         if (fd2 < 0) {
index 94db011..085b551 100644 (file)
@@ -502,7 +502,10 @@ int main(int argc, char **argv)
        if (!force && writeoption) {
                printf("%s: permanently overwrite all data on %s (yes/no)? ",
                       progname, devname);
-               scanf("%3s", yesno);
+                if (scanf("%3s", yesno) == EOF && ferror(stdin)) {
+                        perror("reading from stdin");
+                        return -1;
+                }
                if (!(strcasecmp("yes", yesno) || strcasecmp("y", yesno))) {
                        printf("Not continuing due to '%s' response", yesno);
                        return 0;
index b418051..3aee89f 100644 (file)
@@ -207,11 +207,16 @@ pid_t fork_llstat_command(char* llstat_file,char* stats_path)
         pid_t pid_llstat_command;
         FILE *fp_popen, *fp_out;
         char buffer[MAX];
+        int ret;
         
         /* Truncating llstat output file as it will be opened in while
          * loop to append output */
         sprintf(truncate_command,"> %s",llstat_file);
-        system(truncate_command); 
+        if ((ret = system(truncate_command)) != 0) {
+                ret = WEXITSTATUS(ret);
+                printf("error excuting truncate command: %d\n", ret);
+                exit(ret);
+        }
 
         strcat(stats_path, "/stats");
 
@@ -343,7 +348,12 @@ char* get_path_stats(int with_llstat, char* stats_path)
                         /* If flow is here again it means there was an error
                          * and notifying that to user */
                         if (error) {
-                                system("clear");
+                                int ret;
+                                if ((ret = system("clear")) != 0) {
+                                        ret = WEXITSTATUS(ret);
+                                        printf("error excuting clear command: %d\n", ret);
+                                        exit(ret);
+                                }
                                 fprintf(stderr, "Error: Please give correct "
                                         "choice.\n");
                         }
@@ -356,8 +366,11 @@ char* get_path_stats(int with_llstat, char* stats_path)
 
                         printf("\nEnter the lustre client number you want to "
                                "use:");
-                        scanf(" %d", &choice);
-                        error ++;
+                        if (scanf(" %d", &choice) == EOF && ferror(stdin)) {
+                                perror("reading from stdin");
+                                exit(-1);
+                        }
+                        error++;
                 } while (choice > stats_glob_buffer.gl_pathc || choice < 1);
                 strcpy(stats_path, stats_glob_buffer.gl_pathv[choice - 1]);
         } else {
index 79d2bd1..a10b616 100644 (file)
@@ -193,7 +193,12 @@ int get_os_version()
                         fprintf(stderr, "%s: Warning: Can't resolve kernel "
                                 "version, assuming 2.6\n", progname);
                 else {
-                        read(fd, release, 4);
+                        if (read(fd, release, 4) < 0) {
+                                fprintf(stderr, "reading from /proc/sys/kernel"
+                                                "/osrelease: %s\n", strerror(errno));
+                                close(fd);
+                                exit(-1);
+                        }
                         close(fd);
                 }
                 if (strncmp(release, "2.4.", 4) == 0)
@@ -740,6 +745,7 @@ int write_local_files(struct mkfs_opts *mop)
         char *dev;
         FILE *filep;
         int ret = 0;
+        size_t num;
 
         /* Mount this device temporarily in order to write these files */
         if (!mkdtemp(mntpt)) {
@@ -785,7 +791,12 @@ int write_local_files(struct mkfs_opts *mop)
                         progname, filepnm, strerror(errno));
                 goto out_umnt;
         }
-        fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
+        num = fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
+        if (num < 1 && ferror(filep)) {
+                fprintf(stderr, "%s: Unable to write to file (%s): %s\n",
+                        progname, filepnm, strerror(errno));
+                goto out_umnt;
+        }
         fclose(filep);
 
         /* COMPAT_146 */
@@ -892,8 +903,14 @@ int read_local_files(struct mkfs_opts *mop)
         sprintf(filepnm, "%s/mountdata", tmpdir);
         filep = fopen(filepnm, "r");
         if (filep) {
+                size_t num_read;
                 vprint("Reading %s\n", MOUNT_DATA_FILE);
-                fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
+                num_read = fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
+                if (num_read < 1 && ferror(filep)) {
+                        fprintf(stderr, "%s: Unable to read from file (%s): %s\n",
+                                progname, filepnm, strerror(errno));
+                        goto out_close;
+                }
         } else {
                 /* COMPAT_146 */
                 /* Try to read pre-1.6 config from last_rcvd */
index 416e0d6..e22d115 100644 (file)
@@ -317,7 +317,12 @@ int read_file(char *path, char *buf, int size)
         if (fd == NULL)
                 return errno;
 
-        fgets(buf, size, fd);
+        /* should not ignore fgets(3)'s return value */
+        if (!fgets(buf, size, fd)) {
+                fprintf(stderr, "reading from %s: %s", path, strerror(errno));
+                fclose(fd);
+                return 1;
+        }
         fclose(fd);
         return 0;
 }
@@ -706,8 +711,12 @@ int main(int argc, char *const argv[])
                 /* May as well try to clean up loop devs */
                 if (strncmp(usource, "/dev/loop", 9) == 0) {
                         char cmd[256];
+                        int ret;
                         sprintf(cmd, "/sbin/losetup -d %s", usource);
-                        system(cmd);
+                        if ((ret = system(cmd)) < 0)
+                                rc = errno;
+                        else if (ret > 0)
+                                rc = WEXITSTATUS(ret);
                 }
 
         } else if (!nomtab) {
index 9253251..530c9bf 100644 (file)
@@ -131,8 +131,14 @@ int get_mountdata(char *dev, struct lustre_disk_data *mo_ldd)
         sprintf(filepnm, "%s/mountdata", tmpdir);
         filep = fopen(filepnm, "r");
         if (filep) {
+                size_t num_read;
                 vprint("Reading %s\n", MOUNT_DATA_FILE);
-                fread(mo_ldd, sizeof(*mo_ldd), 1, filep);
+                num_read = fread(mo_ldd, sizeof(*mo_ldd), 1, filep);
+                if (num_read < 1 && ferror(filep)) {
+                        fprintf(stderr, "%s: Unable to read from file (%s): %s\n",
+                                progname, filepnm, strerror(errno));
+                        goto out_close;
+                }
        } else {
                 verrprint("%s: Unable to read %d.%d config %s.\n",
                           progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
index 1ce3fc8..b400074 100644 (file)
@@ -963,7 +963,12 @@ try_mdc:
                 goto fail;
 
 got_one:
-        fgets(buf, sizeof(buf), fp);
+        /* should not ignore fgets(3)'s return value */
+        if (!fgets(buf, sizeof(buf), fp)) {
+                fprintf(stderr, "reading from %s: %s", buf, strerror(errno));
+                fclose(fp);
+                return;
+        }
         fclose(fp);
 
         /* trim trailing newlines */