return 0;
}
-static inline int request_module(char *name)
+static inline int request_module(const char *name, ...)
{
return (-EINVAL);
}
* but it can't fix the situation that liblustre is mounted
* at "/".
*/
- chdir("/");
+ if (!chdir("/")) {}
#if 0
umount(lustre_path);
#endif
#include <fcntl.h>
#include <sys/queue.h>
#include <getopt.h>
+#include <sys/wait.h>
#include <sysio.h>
#include <mount.h>
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); \
} \
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)
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;
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);
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);
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;
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");
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)
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 {
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)
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;
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;
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) {
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) {
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) {
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) {
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) {
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) {
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;
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");
/* 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");
}
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 {
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)
char *dev;
FILE *filep;
int ret = 0;
+ size_t num;
/* Mount this device temporarily in order to write these files */
if (!mkdtemp(mntpt)) {
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 */
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 */
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;
}
/* 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) {
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);
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 */