From b4efa1b2cbfd45f85439e1bb0a4c4eb719540dcd Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 9 Oct 2009 13:47:37 +0000 Subject: [PATCH] b=19720 i=robert.read i=dmitry.zogin Clean up various warnings stemming from unused variables and unchecked function return values. --- libcfs/include/libcfs/darwin/darwin-prim.h | 2 +- libcfs/include/libcfs/posix/libcfs.h | 2 +- libcfs/include/libcfs/winnt/winnt-prim.h | 2 +- libcfs/libcfs/linux/linux-debug.c | 2 +- lnet/lnet/api-ni.c | 2 +- lnet/selftest/selftest.h | 1 + lnet/utils/debug.c | 14 +++++++--- lnet/utils/lstclient.c | 4 +-- lnet/utils/routerstat.c | 2 +- lustre/liblustre/llite_lib.c | 2 +- lustre/liblustre/tests/recovery_small.c | 6 +++-- lustre/liblustre/tests/sanity.c | 16 ++++++++---- lustre/lvfs/fsfilt.c | 2 +- lustre/mds/handler.c | 2 +- lustre/obdclass/capa.c | 10 +++++-- lustre/obdclass/genops.c | 2 +- lustre/obdfilter/filter.c | 2 +- lustre/ptlrpc/ptlrpcd.c | 2 +- lustre/tests/fsx.c | 16 +++++++++--- lustre/tests/mmap_sanity.c | 42 +++++++++++++++++++++++++----- lustre/utils/lfs.c | 9 +++++-- lustre/utils/liblustreapi.c | 4 +-- lustre/utils/llverdev.c | 5 +++- lustre/utils/lreplicate.c | 3 ++- lustre/utils/mkfs_lustre.c | 23 +++++++++++++--- lustre/utils/mount_lustre.c | 13 +++++++-- lustre/utils/mount_utils.c | 8 +++++- lustre/utils/obd.c | 7 ++++- 28 files changed, 156 insertions(+), 49 deletions(-) diff --git a/libcfs/include/libcfs/darwin/darwin-prim.h b/libcfs/include/libcfs/darwin/darwin-prim.h index 2b877de..ec7036c 100644 --- a/libcfs/include/libcfs/darwin/darwin-prim.h +++ b/libcfs/include/libcfs/darwin/darwin-prim.h @@ -472,7 +472,7 @@ struct __dummy_ ## name ## _struct {} #define inter_module_get(n) cfs_symbol_get(n) #define inter_module_put(n) cfs_symbol_put(n) -static inline int request_module(char *name) +static inline int request_module(const char *name, ...) { return (-EINVAL); } diff --git a/libcfs/include/libcfs/posix/libcfs.h b/libcfs/include/libcfs/posix/libcfs.h index b204213..2173ab9 100644 --- a/libcfs/include/libcfs/posix/libcfs.h +++ b/libcfs/include/libcfs/posix/libcfs.h @@ -241,7 +241,7 @@ static inline void MODULE_AUTHOR(char *name) #define __init #define __exit -static inline int request_module(char *name) +static inline int request_module(const char *name, ...) { return (-EINVAL); } diff --git a/libcfs/include/libcfs/winnt/winnt-prim.h b/libcfs/include/libcfs/winnt/winnt-prim.h index accf7a9..3414023 100644 --- a/libcfs/include/libcfs/winnt/winnt-prim.h +++ b/libcfs/include/libcfs/winnt/winnt-prim.h @@ -745,7 +745,7 @@ struct module { extern struct module libcfs_global_module; #define THIS_MODULE &libcfs_global_module -#define request_module(x) (0) +#define request_module(x, y) (0) #define EXPORT_SYMBOL(s) #define MODULE_AUTHOR(s) #define MODULE_DESCRIPTION(s) diff --git a/libcfs/libcfs/linux/linux-debug.c b/libcfs/libcfs/linux/linux-debug.c index f08be51..f8dab0f 100644 --- a/libcfs/libcfs/linux/linux-debug.c +++ b/libcfs/libcfs/linux/linux-debug.c @@ -212,7 +212,7 @@ void lbug_with_loc(const char *file, const char *func, const int line) static void print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) { - printk(data); + printk("%s", (char *)data); print_symbol(msg, symbol); printk("\n"); } diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index a7a4f2b..86541a7 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -992,7 +992,7 @@ lnet_startup_lndnis (void) #ifdef __KERNEL__ if (lnd == NULL) { LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex); - rc = request_module(libcfs_lnd2modname(lnd_type)); + rc = request_module("%s", libcfs_lnd2modname(lnd_type)); LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex); lnd = lnet_find_lnd_by_type(lnd_type); diff --git a/lnet/selftest/selftest.h b/lnet/selftest/selftest.h index 7312eac..5dc9481 100644 --- a/lnet/selftest/selftest.h +++ b/lnet/selftest/selftest.h @@ -430,6 +430,7 @@ void sfw_unpack_message(srpc_msg_t *msg); void sfw_free_pages(srpc_server_rpc_t *rpc); void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i); int sfw_alloc_pages(srpc_server_rpc_t *rpc, int npages, int sink); +int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply); srpc_client_rpc_t * srpc_create_client_rpc(lnet_process_id_t peer, int service, diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index 3ce3013..8a28b4f 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -363,15 +363,22 @@ static void print_rec(struct dbg_line ***linevp, int used, int fdout) struct dbg_line *line = linev[i]; struct ptldebug_header *hdr = line->hdr; char out[4097]; + char *buf = out; int bytes; + ssize_t bytes_written; bytes = sprintf(out, "%08x:%08x:%u:%u.%06llu:%u:%u:%u:(%s:%u:%s()) %s", hdr->ph_subsys, hdr->ph_mask, hdr->ph_cpu_id, hdr->ph_sec, (unsigned long long)hdr->ph_usec, hdr->ph_stack, hdr->ph_pid, hdr->ph_extern_pid, line->file, hdr->ph_line_num, line->fn, line->text); - - write(fdout, out, bytes); + while (bytes > 0) { + bytes_written = write(fdout, buf, bytes); + if (bytes_written <= 0) + break; + bytes -= bytes_written; + buf += bytes_written; + } free(line->hdr); free(line); } @@ -627,7 +634,8 @@ int jt_dbg_debug_kernel(int argc, char **argv) return 1; } if (argc > 1) { - fdout = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC); + fdout = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR); if (fdout < 0) { fprintf(stderr, "fopen(%s) failed: %s\n", argv[1], strerror(errno)); diff --git a/lnet/utils/lstclient.c b/lnet/utils/lstclient.c index a439645..26a05c9 100644 --- a/lnet/utils/lstclient.c +++ b/lnet/utils/lstclient.c @@ -186,13 +186,13 @@ main(int argc, char **argv) server_mode_flag = 1; break; default: - fprintf(stderr, usage_string); + fprintf(stderr, "%s", usage_string); return -1; } } if (optind != argc || grp == NULL || ses == NULL) { - fprintf(stderr, usage_string); + fprintf(stderr, "%s", usage_string); return -1; } diff --git a/lnet/utils/routerstat.c b/lnet/utils/routerstat.c index e518022..c8adc90 100644 --- a/lnet/utils/routerstat.c +++ b/lnet/utils/routerstat.c @@ -128,7 +128,7 @@ do_stat (int fd) } if (last == 0.0) { - printf ("M %lu(%lu) E %lu S %lu/%llu R %lu/%llu F %lu/%llu D %lu/%llu\n", + printf ("M %lu(%lu) E %lu S %llu/%lu R %llu/%lu F %llu/%lu D %llu/%lu\n", new_counter.msgs_alloc, new_counter.msgs_max, new_counter.errors, new_counter.send_length, new_counter.send_count, diff --git a/lustre/liblustre/llite_lib.c b/lustre/liblustre/llite_lib.c index 7baec8c..bac1928 100644 --- a/lustre/liblustre/llite_lib.c +++ b/lustre/liblustre/llite_lib.c @@ -409,7 +409,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 diff --git a/lustre/liblustre/tests/recovery_small.c b/lustre/liblustre/tests/recovery_small.c index 5e1da4e..66c3d10 100644 --- a/lustre/liblustre/tests/recovery_small.c +++ b/lustre/liblustre/tests/recovery_small.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -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 ((rc = 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) diff --git a/lustre/liblustre/tests/sanity.c b/lustre/liblustre/tests/sanity.c index 0fe2645..c0c3c05 100644 --- a/lustre/liblustre/tests/sanity.c +++ b/lustre/liblustre/tests/sanity.c @@ -579,7 +579,7 @@ static int check_file_size(char *file, long long size) } if (statbuf.st_size != size) { printf("size of %s: %lld != %lld\n", file, - (long long)statbuf.st_size, size); + (long long)statbuf.st_size, (long long )size); return(-1); } return 0; @@ -614,7 +614,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); @@ -731,7 +731,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); @@ -1093,8 +1093,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; @@ -1361,7 +1367,7 @@ int t56(char *name) int fd; size_t nbytes; off_t basep = 0; - ssize_t rc = 0; + long rc = 0; cfs_dirent_t dir; ENTER("getdirentries should fail if nbytes is too small"); diff --git a/lustre/lvfs/fsfilt.c b/lustre/lvfs/fsfilt.c index cb95e85..b14b9f9 100644 --- a/lustre/lvfs/fsfilt.c +++ b/lustre/lvfs/fsfilt.c @@ -114,7 +114,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) diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 00527cb..0c137d9 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -485,7 +485,7 @@ static int __init mds_cmd_init(void) struct lprocfs_static_vars lvars; int rc; - request_module("lquota"); + request_module("%s", "lquota"); mds_quota_interface_ref = PORTAL_SYMBOL_GET(mds_quota_interface); rc = lquota_init(mds_quota_interface_ref); if (rc) { diff --git a/lustre/obdclass/capa.c b/lustre/obdclass/capa.c index ba47564..c15e96d 100644 --- a/lustre/obdclass/capa.c +++ b/lustre/obdclass/capa.c @@ -289,9 +289,12 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) struct blkcipher_desc desc; unsigned int min; int rc; + char alg[CRYPTO_MAX_ALG_NAME+1] = "aes"; ENTRY; - tfm = ll_crypto_alloc_blkcipher("aes", 0, 0 ); + /* passing "aes" in a variable instead of a constant string keeps gcc + * 4.3.2 happy */ + tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 ); if (tfm == NULL) { CERROR("failed to load transform for aes\n"); RETURN(-EFAULT); @@ -341,9 +344,12 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) struct blkcipher_desc desc; unsigned int min; int rc; + char alg[CRYPTO_MAX_ALG_NAME+1] = "aes"; ENTRY; - tfm = ll_crypto_alloc_blkcipher("aes", 0, 0 ); + /* passing "aes" in a variable instead of a constant string keeps gcc + * 4.3.2 happy */ + tfm = ll_crypto_alloc_blkcipher(alg, 0, 0 ); if (tfm == NULL) { CERROR("failed to load transform for aes\n"); RETURN(-EFAULT); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 6e0a2b6..51b4d7e 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -120,7 +120,7 @@ struct obd_type *class_get_type(const char *name) #ifdef CONFIG_KMOD if (!type) { const char *modname = name; - if (!request_module(modname)) { + if (!request_module("%s", modname)) { CDEBUG(D_INFO, "Loaded module '%s'\n", modname); type = class_search_type(name); } else { diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 14f6889..c1aa19d 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -4631,7 +4631,7 @@ static int __init obdfilter_init(void) lprocfs_filter_init_vars(&lvars); - request_module("lquota"); + request_module("%s", "lquota"); OBD_ALLOC(obdfilter_created_scratchpad, OBDFILTER_CREATED_SCRATCHPAD_ENTRIES * sizeof(*obdfilter_created_scratchpad)); diff --git a/lustre/ptlrpc/ptlrpcd.c b/lustre/ptlrpc/ptlrpcd.c index c8f043b..a9f3f9d 100644 --- a/lustre/ptlrpc/ptlrpcd.c +++ b/lustre/ptlrpc/ptlrpcd.c @@ -360,7 +360,7 @@ int ptlrpcd_start(const 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), "%s", name); + strncpy(pc->pc_name, name, sizeof(pc->pc_name) - 1); pc->pc_set = ptlrpc_prep_set(); if (pc->pc_set == NULL) GOTO(out, rc = -ENOMEM); diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index af93599..f645b08 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -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; diff --git a/lustre/tests/mmap_sanity.c b/lustre/tests/mmap_sanity.c index 012c8b9..22ca9bf 100644 --- a/lustre/tests/mmap_sanity.c +++ b/lustre/tests/mmap_sanity.c @@ -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) { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index b5e54b4..0e582ed 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2224,8 +2224,13 @@ static int lfs_flushctx(int argc, char **argv) } } - if (kdestroy) - system("kdestroy > /dev/null"); + if (kdestroy) { + int rc; + if ((rc = system("kdestroy > /dev/null")) != 0) { + rc = WEXITSTATUS(rc); + fprintf(stderr, "error destroying tickets: %d, continuing\n", rc); + } + } if (optind >= argc) { /* flush for all mounted lustre fs. */ diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index f8643c6..d0ae79a 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2677,8 +2677,8 @@ int llapi_changelog_start(void **priv, int flags, const char *device, struct changelog_private *cp; struct changelog_show cs = {}; char mdtname[20]; - char pattern[100]; - char trigger[100]; + char pattern[PATH_MAX]; + char trigger[PATH_MAX]; int fd, rc, pid; /* Find mdtname from path, fsname, mdtname, or mdtname_UUID */ diff --git a/lustre/utils/llverdev.c b/lustre/utils/llverdev.c index 94db011..085b551 100644 --- a/lustre/utils/llverdev.c +++ b/lustre/utils/llverdev.c @@ -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; diff --git a/lustre/utils/lreplicate.c b/lustre/utils/lreplicate.c index b9aeb49..f29dc73 100644 --- a/lustre/utils/lreplicate.c +++ b/lustre/utils/lreplicate.c @@ -1110,7 +1110,8 @@ int lr_write_log() lr_backup_log(); - fd = open(statuslog, O_WRONLY | O_CREAT | O_SYNC); + fd = open(statuslog, O_WRONLY | O_CREAT | O_SYNC, + S_IRUSR | S_IWUSR); if (fd == -1) { fprintf(stderr, "Error opening log file for writing (%s)\n", statuslog); diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index f8be123..95f7260 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -195,7 +195,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) @@ -815,6 +820,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)) { @@ -860,7 +866,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 */ #ifdef TUNEFS @@ -965,8 +976,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 */ diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 52b9989..f8fdb0f 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -326,7 +326,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; } @@ -716,8 +721,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) { diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index b36a1df..d624656 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -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); diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index a912496..4542228 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -953,7 +953,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 */ -- 1.8.3.1