]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_io: set exitcode on failure appropriately
authorDave Chinner <dchinner@redhat.com>
Wed, 8 Apr 2020 13:48:15 +0000 (09:48 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 8 Apr 2020 13:48:15 +0000 (09:48 -0400)
Many operations don't set the exitcode when they fail, resulting
in xfs_io exiting with a zero (no failure) exit code despite the
command failing and returning an error. The command return code is
really a boolean to tell the libxcmd command loop whether to
continue processing or not, while exitcode is the actual xfs_io exit
code returned to the parent on exit.

This patchset just makes the code do the right thing. It's not the
nicest code, but it's a start at producing correct behaviour.

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
32 files changed:
io/attr.c
io/copy_file_range.c
io/cowextsize.c
io/encrypt.c
io/fadvise.c
io/fiemap.c
io/file.c
io/fsmap.c
io/fsync.c
io/getrusage.c
io/imap.c
io/inject.c
io/link.c
io/log_writes.c
io/madvise.c
io/mincore.c
io/mmap.c
io/open.c
io/parent.c
io/pread.c
io/prealloc.c
io/pwrite.c
io/readdir.c
io/reflink.c
io/resblks.c
io/seek.c
io/sendfile.c
io/shutdown.c
io/stat.c
io/sync_file_range.c
io/truncate.c
io/utimes.c

index 69b32956ab8898af51dc1179730b29765efb92aa..80e285147acb2975bd21ec5d5cafc916b17a29d0 100644 (file)
--- a/io/attr.c
+++ b/io/attr.c
@@ -162,13 +162,15 @@ lsattr_callback(
        if (recurse_dir && !S_ISDIR(stat->st_mode))
                return 0;
 
-       if ((fd = open(path, O_RDONLY)) == -1)
+       if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
-       else if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0)
+               exitcode = 1;
+       } else if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, path, strerror(errno));
-       else
+               exitcode = 1;
+       } else
                printxattr(fsx.fsx_xflags, 0, 1, path, 0, 1);
 
        if (fd != -1)
@@ -205,6 +207,7 @@ lsattr_f(
                        vflag = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&lsattr_cmd);
                }
        }
@@ -215,6 +218,7 @@ lsattr_f(
        } else if ((xfsctl(name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, name, strerror(errno));
+               exitcode = 1;
        } else {
                printxattr(fsx.fsx_xflags, vflag, !aflag, name, vflag, !aflag);
                if (aflag) {
@@ -241,15 +245,19 @@ chattr_callback(
        if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else if (xfsctl(path, fd, FS_IOC_FSGETXATTR, &attr) < 0) {
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else {
                attr.fsx_xflags |= orflags;
                attr.fsx_xflags &= ~andflags;
-               if (xfsctl(path, fd, FS_IOC_FSSETXATTR, &attr) < 0)
+               if (xfsctl(path, fd, FS_IOC_FSSETXATTR, &attr) < 0) {
                        fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
                                progname, path, strerror(errno));
+                       exitcode = 1;
+               }
        }
 
        if (fd != -1)
@@ -285,6 +293,7 @@ chattr_f(
                                if (!p->flag) {
                                        fprintf(stderr, _("%s: unknown flag\n"),
                                                progname);
+                                       exitcode = 1;
                                        return 0;
                                }
                        }
@@ -299,12 +308,14 @@ chattr_f(
                                if (!p->flag) {
                                        fprintf(stderr, _("%s: unknown flag\n"),
                                                progname);
+                                       exitcode = 1;
                                        return 0;
                                }
                        }
                } else {
                        fprintf(stderr, _("%s: bad chattr command, not +/-X\n"),
                                progname);
+                       exitcode = 1;
                        return 0;
                }
        }
@@ -315,12 +326,15 @@ chattr_f(
        } else if (xfsctl(name, file->fd, FS_IOC_FSGETXATTR, &attr) < 0) {
                fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
                        progname, name, strerror(errno));
+               exitcode = 1;
        } else {
                attr.fsx_xflags |= orflags;
                attr.fsx_xflags &= ~andflags;
-               if (xfsctl(name, file->fd, FS_IOC_FSSETXATTR, &attr) < 0)
+               if (xfsctl(name, file->fd, FS_IOC_FSSETXATTR, &attr) < 0) {
                        fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
                                progname, name, strerror(errno));
+                       exitcode = 1;
+               }
        }
        return 0;
 }
index 4c4332c6e5eccb04b0da8b5f39c1fc79e1e80780..685250471020fcdef38eca22083cf856922e1f0d 100644 (file)
@@ -89,6 +89,7 @@ copy_range_f(int argc, char **argv)
                        src_off = cvtnum(fsblocksize, fssectsize, optarg);
                        if (src_off < 0) {
                                printf(_("invalid source offset -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -96,6 +97,7 @@ copy_range_f(int argc, char **argv)
                        dst_off = cvtnum(fsblocksize, fssectsize, optarg);
                        if (dst_off < 0) {
                                printf(_("invalid destination offset -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -103,6 +105,7 @@ copy_range_f(int argc, char **argv)
                        llen = cvtnum(fsblocksize, fssectsize, optarg);
                        if (llen == -1LL) {
                                printf(_("invalid length -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        /*
@@ -112,6 +115,7 @@ copy_range_f(int argc, char **argv)
                        if ((size_t)llen != llen) {
                                errno = EOVERFLOW;
                                perror("copy_range");
+                               exitcode = 1;
                                return 0;
                        }
                        len = llen;
@@ -122,23 +126,29 @@ copy_range_f(int argc, char **argv)
                        if (src_file_nr < 0 || src_file_nr >= filecount) {
                                printf(_("file value %d is out of range (0-%d)\n"),
                                        src_file_nr, filecount - 1);
+                               exitcode = 1;
                                return 0;
                        }
                        /* Expect no src_path arg */
                        src_path_arg = 0;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&copy_range_cmd);
                }
        }
 
-       if (optind != argc - src_path_arg)
+       if (optind != argc - src_path_arg) {
+               exitcode = 1;
                return command_usage(&copy_range_cmd);
+       }
 
        if (src_path_arg) {
                fd = openfile(argv[optind], NULL, IO_READONLY, 0, NULL);
-               if (fd < 0)
+               if (fd < 0) {
+                       exitcode = 1;
                        return 0;
+               }
        } else {
                fd = filetable[src_file_nr].fd;
        }
@@ -158,6 +168,8 @@ copy_range_f(int argc, char **argv)
        ret = copy_file_range_cmd(fd, &src_off, &dst_off, len);
 out:
        close(fd);
+       if (ret < 0)
+               exitcode = 1;
        return ret;
 }
 
index da5c6680c7d27f34ce00fb2746b33c8246cc01f3..549634438aa4c31281078b5166937d304201f831 100644 (file)
@@ -39,6 +39,7 @@ get_cowextsize(const char *path, int fd)
        if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
                        progname, path, strerror(errno));
+               exitcode = 1;
                return 0;
        }
        printf("[%u] %s\n", fsx.fsx_cowextsize, path);
@@ -53,11 +54,13 @@ set_cowextsize(const char *path, int fd, long extsz)
 
        if (fstat64(fd, &stat) < 0) {
                perror("fstat64");
+               exitcode = 1;
                return 0;
        }
        if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
                        progname, path, strerror(errno));
+               exitcode = 1;
                return 0;
        }
 
@@ -72,6 +75,7 @@ set_cowextsize(const char *path, int fd, long extsz)
        if ((xfsctl(path, fd, FS_IOC_FSSETXATTR, &fsx)) < 0) {
                printf("%s: XFS_IOC_FSSETXATTR %s: %s\n",
                        progname, path, strerror(errno));
+               exitcode = 1;
                return 0;
        }
 
@@ -154,6 +158,7 @@ cowextsize_f(
                if (cowextsize < 0) {
                        printf(_("non-numeric cowextsize argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else {
index 01b7e0df8a6e1976472e45807173072645caa1ad..1b347dc1afdb55c43139e55cbc0a5809db86b317 100644 (file)
@@ -603,6 +603,7 @@ set_encpolicy_f(int argc, char **argv)
                                fprintf(stderr,
                                        _("invalid contents encryption mode: %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -611,6 +612,7 @@ set_encpolicy_f(int argc, char **argv)
                                fprintf(stderr,
                                        _("invalid filenames encryption mode: %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -618,6 +620,7 @@ set_encpolicy_f(int argc, char **argv)
                        if (!parse_byte_value(optarg, &flags)) {
                                fprintf(stderr, _("invalid flags: %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -628,6 +631,7 @@ set_encpolicy_f(int argc, char **argv)
                                fprintf(stderr,
                                        _("invalid policy version: %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        if (val == 1) /* Just to avoid annoying people... */
@@ -636,14 +640,17 @@ set_encpolicy_f(int argc, char **argv)
                        break;
                }
                default:
+                       exitcode = 1;
                        return command_usage(&set_encpolicy_cmd);
                }
        }
        argc -= optind;
        argv += optind;
 
-       if (argc > 1)
+       if (argc > 1) {
+               exitcode = 1;
                return command_usage(&set_encpolicy_cmd);
+       }
 
        /*
         * If unspecified, the key descriptor or identifier defaults to all 0's.
@@ -652,8 +659,10 @@ set_encpolicy_f(int argc, char **argv)
        memset(&key_spec, 0, sizeof(key_spec));
        if (argc > 0) {
                version = str2keyspec(argv[0], version, &key_spec);
-               if (version < 0)
+               if (version < 0) {
+                       exitcode = 1;
                        return 0;
+               }
        }
        if (version < 0) /* version unspecified? */
                version = FSCRYPT_POLICY_V1;
@@ -735,6 +744,7 @@ add_enckey_f(int argc, char **argv)
                                goto out;
                        break;
                default:
+                       exitcode = 1;
                        retval = command_usage(&add_enckey_cmd);
                        goto out;
                }
@@ -743,6 +753,7 @@ add_enckey_f(int argc, char **argv)
        argv += optind;
 
        if (argc != 0) {
+               exitcode = 1;
                retval = command_usage(&add_enckey_cmd);
                goto out;
        }
@@ -760,6 +771,7 @@ add_enckey_f(int argc, char **argv)
                        fprintf(stderr,
                                _("Invalid key; got > FSCRYPT_MAX_KEY_SIZE (%d) bytes on stdin!\n"),
                                FSCRYPT_MAX_KEY_SIZE);
+                       exitcode = 1;
                        goto out;
                }
                arg->raw_size = raw_size;
@@ -794,17 +806,22 @@ rm_enckey_f(int argc, char **argv)
                        ioc = FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&rm_enckey_cmd);
                }
        }
        argc -= optind;
        argv += optind;
 
-       if (argc != 1)
+       if (argc != 1) {
+               exitcode = 1;
                return command_usage(&rm_enckey_cmd);
+       }
 
-       if (str2keyspec(argv[0], -1, &arg.key_spec) < 0)
+       if (str2keyspec(argv[0], -1, &arg.key_spec) < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        if (ioctl(file->fd, ioc, &arg) != 0) {
                fprintf(stderr, _("Error removing encryption key: %s\n"),
@@ -834,8 +851,10 @@ enckey_status_f(int argc, char **argv)
 
        memset(&arg, 0, sizeof(arg));
 
-       if (str2keyspec(argv[1], -1, &arg.key_spec) < 0)
+       if (str2keyspec(argv[1], -1, &arg.key_spec) < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        if (ioctl(file->fd, FS_IOC_GET_ENCRYPTION_KEY_STATUS, &arg) != 0) {
                fprintf(stderr, _("Error getting encryption key status: %s\n"),
index 4089a0eb2b2e87528a2fe997fde2fcfb3c0e0b07..60cc0f0884652c61beaca40a24abd41d56624652 100644 (file)
@@ -65,19 +65,23 @@ fadvise_f(
                        range = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&fadvise_cmd);
                }
        }
        if (range) {
                size_t  blocksize, sectsize;
 
-               if (optind != argc - 2)
+               if (optind != argc - 2) {
+                       exitcode = 1;
                        return command_usage(&fadvise_cmd);
+               }
                init_cvtnum(&blocksize, &sectsize);
                offset = cvtnum(blocksize, sectsize, argv[optind]);
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                optind++;
@@ -85,14 +89,17 @@ fadvise_f(
                if (length < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else if (optind != argc) {
+               exitcode = 1;
                return command_usage(&fadvise_cmd);
        }
 
        if (posix_fadvise(file->fd, offset, length, advise) < 0) {
                perror("fadvise");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 485bae16ebaa9a1ac92e0c31e0834be9e51d1026..f0c74dfe606db8c95269ed26e583fbc1b213bfab 100644 (file)
@@ -257,6 +257,7 @@ fiemap_f(
                        vflag++;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&fiemap_cmd);
                }
        }
@@ -266,6 +267,7 @@ fiemap_f(
                start_offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
                if (start_offset < 0) {
                        printf("non-numeric offset argument -- %s\n", argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                last_logical = start_offset;
@@ -277,6 +279,7 @@ fiemap_f(
                length = cvtnum(fsblocksize, fssectsize, argv[optind]);
                if (length < 0) {
                        printf("non-numeric len argument -- %s\n", argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                range_end = start_offset + length;
index c45486ecfac2271a48e890d0728f0213e37f1a15..3af829eadb8bbf4f54adfc6957595930c1b35bcd 100644 (file)
--- a/io/file.c
+++ b/io/file.c
@@ -69,6 +69,7 @@ file_f(
        i = atoi(argv[1]);
        if (i < 0 || i >= filecount) {
                printf(_("value %d is out of range (0-%d)\n"), i, filecount-1);
+               exitcode = 1;
        } else {
                file = &filetable[i];
                filelist_f();
index feacb264a9d0755968e3ded9f9eab772c49e6059..4b2175957f9c69e8ccbfa56dddb02d2587dd2dac 100644 (file)
@@ -417,13 +417,16 @@ fsmap_f(
                        vflag++;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&fsmap_cmd);
                }
        }
 
        if ((dflag + lflag + rflag > 1) || (mflag > 0 && vflag > 0) ||
-           (argc > optind && dflag + lflag + rflag == 0))
+           (argc > optind && dflag + lflag + rflag == 0)) {
+               exitcode = 1;
                return command_usage(&fsmap_cmd);
+       }
 
        if (argc > optind) {
                start = cvtnum(fsblocksize, fssectsize, argv[optind]);
@@ -431,6 +434,7 @@ fsmap_f(
                        fprintf(stderr,
                                _("Bad rmap start_bblock %s.\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                start <<= BBSHIFT;
@@ -442,6 +446,7 @@ fsmap_f(
                        fprintf(stderr,
                                _("Bad rmap end_bblock %s.\n"),
                                argv[optind + 1]);
+                       exitcode = 1;
                        return 0;
                }
                end <<= BBSHIFT;
@@ -495,8 +500,8 @@ fsmap_f(
                                " iflags=0x%x [\"%s\"]: %s\n"),
                                progname, head->fmh_iflags, file->name,
                                strerror(errno));
-                       free(head);
                        exitcode = 1;
+                       free(head);
                        return 0;
                }
                if (head->fmh_entries > map_size + 2) {
index e6f2331199be60fc3c99fbd79b8f89e7fd762fee..b425b61222d7693c0398462764c348779a013e39 100644 (file)
@@ -19,6 +19,7 @@ fsync_f(
 {
        if (fsync(file->fd) < 0) {
                perror("fsync");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -31,6 +32,7 @@ fdatasync_f(
 {
        if (fdatasync(file->fd) < 0) {
                perror("fdatasync");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 6962913df44f6ab9b5cf2df8d8bef6fc72bfaff0..11f86529bf7765e8faecb135d2d2018dfb594f8a 100644 (file)
@@ -51,6 +51,7 @@ getrusage_f(
 
        if (getrusage(RUSAGE_SELF, &rusage) < 0) {
                perror("getrusage");
+               exitcode = 1;
                return 0;
        }
 
index e75dad1a5de93bba3184e4e3ee8776254396f81a..837b338215ae908807effa659dd36591ab5e22f2 100644 (file)
--- a/io/imap.c
+++ b/io/imap.c
@@ -31,6 +31,7 @@ imap_f(int argc, char **argv)
        error = -xfrog_inumbers_alloc_req(nent, 0, &ireq);
        if (error) {
                xfrog_perror(error, "alloc req");
+               exitcode = 1;
                return 0;
        }
 
index cabfc3e362d94b1d2035c99a084c7fab4e7ca7a7..4191c84ead4114f702b69305fab1cd22c2d550a4 100644 (file)
@@ -123,6 +123,7 @@ inject_f(
                        command = XFS_IOC_ERROR_CLEARALL;
                if ((xfsctl(file->name, file->fd, command, &error)) < 0) {
                        perror("XFS_IOC_ERROR_INJECTION");
+                       exitcode = 1;
                        continue;
                }
        }
index f4f4b1396951f3b66e426d60bb44dc3b1f5e68ae..8d255dee6f5f7e212838ebabf07ed8678d60a428 100644 (file)
--- a/io/link.c
+++ b/io/link.c
@@ -35,6 +35,7 @@ flink_f(
 
        if (linkat(file->fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) < 0) {
                perror("flink");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 9c2285fed9ebc7d41a28766ea7c8699514c9586a..20049d1866f0a6a5fc4a0a3339a2a54fa2fc55d4 100644 (file)
@@ -15,10 +15,10 @@ static cmdinfo_t log_writes_cmd;
 static int
 mark_log(const char *device, const char *mark)
 {
-       struct dm_task  *dmt;
-       const int       size = 80;
-       char            message[size];
-       int             len, ret = 0;
+       struct dm_task  *dmt;
+       const int       size = 80;
+       char            message[size];
+       int             len, ret = 0;
 
        len = snprintf(message, size, "mark %s", mark);
        if (len >= size) {
@@ -47,14 +47,13 @@ out:
 
 static int
 log_writes_f(
-       int                     argc,
-       char                    **argv)
+       int             argc,
+       char            **argv)
 {
-       const char      *device = NULL;
-       const char      *mark = NULL;
-       int             c;
+       const char      *device = NULL;
+       const char      *mark = NULL;
+       int             c;
 
-       exitcode = 1;
        while ((c = getopt(argc, argv, "d:m:")) != EOF) {
                switch (c) {
                case 'd':
@@ -64,15 +63,18 @@ log_writes_f(
                        mark = optarg;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&log_writes_cmd);
                }
        }
 
-       if (device == NULL || mark == NULL)
+       if (device == NULL || mark == NULL) {
+               exitcode = 1;
                return command_usage(&log_writes_cmd);
+       }
 
-       if (mark_log(device, mark))
-               exitcode = 0;
+       if (!mark_log(device, mark))
+               exitcode = 1;
 
        return 0;
 }
index 9f6c010d8a33d510ce961d079b23f7de62562185..bde31539b606b88542c122749b10985aeb0b501b 100644 (file)
@@ -60,6 +60,7 @@ madvise_f(
                        advise = MADV_WILLNEED;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&madvise_cmd);
                }
        }
@@ -73,6 +74,7 @@ madvise_f(
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                optind++;
@@ -80,23 +82,29 @@ madvise_f(
                if (llength < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                } else if (llength > (size_t)llength) {
                        printf(_("length argument too large -- %lld\n"),
                                (long long)llength);
+                       exitcode = 1;
                        return 0;
                } else
                        length = (size_t)llength;
        } else {
+               exitcode = 1;
                return command_usage(&madvise_cmd);
        }
 
        start = check_mapping_range(mapping, offset, length, 1);
-       if (!start)
+       if (!start) {
+               exitcode = 1;
                return 0;
+       }
 
        if (madvise(start, length, advise) < 0) {
                perror("madvise");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 239134fedc8bdf423c93b57d08797b0f2a6d801a..67f1d6c4b6125551f78606fb4950a6d40893a42c 100644 (file)
@@ -34,36 +34,44 @@ mincore_f(
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[1]);
+                       exitcode = 1;
                        return 0;
                }
                llength = cvtnum(blocksize, sectsize, argv[2]);
                if (llength < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[2]);
+                       exitcode = 1;
                        return 0;
                } else if (llength > (size_t)llength) {
                        printf(_("length argument too large -- %lld\n"),
                                (long long)llength);
+                       exitcode = 1;
                        return 0;
                } else
                        length = (size_t)llength;
        } else {
+               exitcode = 1;
                return command_usage(&mincore_cmd);
        }
 
        start = check_mapping_range(mapping, offset, length, 1);
-       if (!start)
+       if (!start) {
+               exitcode = 1;
                return 0;
+       }
 
        vec = calloc(length/pagesize, sizeof(unsigned char));
        if (!vec) {
                perror("calloc");
+               exitcode = 1;
                return 0;
        }
 
        if (mincore(start, length, vec) < 0) {
                perror("mincore");
                free(vec);
+               exitcode = 1;
                return 0;
        }
 
index f9383e5e790de7b599671df21a981dd956306a43..8c048a0ab6d00bbfb5421a8112e5f38a927a6269 100644 (file)
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -113,6 +113,7 @@ mapset_f(
        i = atoi(argv[1]);
        if (i < 0 || i >= mapcount) {
                printf("value %d is out of range (0-%d)\n", i, mapcount);
+               exitcode = 1;
        } else {
                mapping = &maptable[i];
                maplist_f();
@@ -162,6 +163,7 @@ mmap_f(
                fprintf(stderr, file ?
                        _("no mapped regions, try 'help mmap'\n") :
                        _("no files are open, try 'help open'\n"));
+               exitcode = 1;
                return 0;
        } else if (argc == 2) {
                if (mapping)
@@ -169,9 +171,11 @@ mmap_f(
                fprintf(stderr, file ?
                        _("no mapped regions, try 'help mmap'\n") :
                        _("no files are open, try 'help open'\n"));
+               exitcode = 1;
                return 0;
        } else if (!file) {
                fprintf(stderr, _("no files are open, try 'help open'\n"));
+               exitcode = 1;
                return 0;
        }
 
@@ -205,30 +209,36 @@ mmap_f(
                        length2 = cvtnum(blocksize, sectsize, optarg);
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&mmap_cmd);
                }
        }
        if (!prot)
                prot = PROT_READ | PROT_WRITE | PROT_EXEC;
 
-       if (optind != argc - 2)
+       if (optind != argc - 2) {
+               exitcode = 1;
                return command_usage(&mmap_cmd);
+       }
 
        offset = cvtnum(blocksize, sectsize, argv[optind]);
        if (offset < 0) {
                printf(_("non-numeric offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        length = cvtnum(blocksize, sectsize, argv[optind]);
        if (length < 0) {
                printf(_("non-numeric length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
        filename = strdup(file->name);
        if (!filename) {
                perror("strdup");
+               exitcode = 1;
                return 0;
        }
 
@@ -248,6 +258,7 @@ mmap_f(
        if (address == MAP_FAILED) {
                perror("mmap");
                free(filename);
+               exitcode = 1;
                return 0;
        }
 
@@ -259,6 +270,7 @@ mmap_f(
                mapcount = 0;
                munmap(address, length);
                free(filename);
+               exitcode = 1;
                return 0;
        }
 
@@ -313,6 +325,7 @@ msync_f(
                        flags |= MS_SYNC;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&msync_cmd);
                }
        }
@@ -326,6 +339,7 @@ msync_f(
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                optind++;
@@ -333,18 +347,25 @@ msync_f(
                if (length < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else {
+               exitcode = 1;
                return command_usage(&msync_cmd);
        }
 
        start = check_mapping_range(mapping, offset, length, 1);
-       if (!start)
+       if (!start) {
+               exitcode = 1;
                return 0;
+       }
 
-       if (msync(start, length, flags) < 0)
+       if (msync(start, length, flags) < 0) {
                perror("msync");
+               exitcode = 1;
+               return 0;
+       }
 
        return 0;
 }
@@ -399,6 +420,7 @@ mread_f(
                        dump = 1;       /* mapping offset dump */
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&mread_cmd);
                }
        }
@@ -412,6 +434,7 @@ mread_f(
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                optind++;
@@ -419,6 +442,7 @@ mread_f(
                if (length < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else {
@@ -426,16 +450,20 @@ mread_f(
        }
 
        start = check_mapping_range(mapping, offset, length, 0);
-       if (!start)
+       if (!start) {
+               exitcode = 1;
                return 0;
+       }
        dumpoffset = offset - mapping->offset;
        if (dump == 2)
                printoffset = offset;
        else
                printoffset = dumpoffset;
 
-       if (alloc_buffer(pagesize, 0, 0) < 0)
+       if (alloc_buffer(pagesize, 0, 0) < 0) {
+               exitcode = 1;
                return 0;
+       }
        bp = (char *)io_buffer;
 
        dumplen = length % pagesize;
@@ -487,6 +515,7 @@ munmap_f(
 
        if (munmap(mapping->addr, mapping->length) < 0) {
                perror("munmap");
+               exitcode = 1;
                return 0;
        }
        free(mapping->name);
@@ -558,6 +587,7 @@ mwrite_f(
                        }
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&mwrite_cmd);
                }
        }
@@ -571,6 +601,7 @@ mwrite_f(
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
                optind++;
@@ -578,15 +609,19 @@ mwrite_f(
                if (length < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else {
+               exitcode = 1;
                return command_usage(&mwrite_cmd);
        }
 
        start = check_mapping_range(mapping, offset, length, 0);
-       if (!start)
+       if (!start) {
+               exitcode = 1;
                return 0;
+       }
 
        offset -= mapping->offset;
        if (rflag) {
@@ -642,17 +677,21 @@ mremap_f(
                        flags = MREMAP_MAYMOVE;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&mremap_cmd);
                }
        }
 
-       if (optind != argc - 1)
+       if (optind != argc - 1) {
+               exitcode = 1;
                return command_usage(&mremap_cmd);
+       }
 
        new_length = cvtnum(blocksize, sectsize, argv[optind]);
        if (new_length < 0) {
                printf(_("non-numeric offset argument -- %s\n"),
                        argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
@@ -662,13 +701,14 @@ mremap_f(
        else
                new_addr = mremap(mapping->addr, mapping->length,
                                  new_length, flags, new_addr);
-       if (new_addr == MAP_FAILED)
+       if (new_addr == MAP_FAILED) {
                perror("mremap");
-       else {
-               mapping->addr = new_addr;
-               mapping->length = new_length;
+               exitcode = 1;
+               return 0;
        }
 
+       mapping->addr = new_addr;
+       mapping->length = new_length;
        return 0;
 }
 #endif /* HAVE_MREMAP */
index 12990642b7395bcba4fcc854634f5220b163d06a..9a8b5e5c59040ce18badf4da8ab19d1f36ed6ad4 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -244,6 +244,7 @@ open_f(
                if (file)
                        return stat_f(argc, argv);
                fprintf(stderr, _("no files are open, try 'help open'\n"));
+               exitcode = 1;
                return 0;
        }
 
@@ -266,6 +267,7 @@ open_f(
                        mode = strtoul(optarg, &sp, 0);
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric mode -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -295,32 +297,43 @@ open_f(
                        flags |= IO_NOFOLLOW;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&open_cmd);
                }
        }
 
-       if (optind != argc - 1)
+       if (optind != argc - 1) {
+               exitcode = 1;
                return command_usage(&open_cmd);
+       }
 
        if ((flags & (IO_READONLY|IO_TMPFILE)) == (IO_READONLY|IO_TMPFILE)) {
                fprintf(stderr, _("-T and -r options are incompatible\n"));
+               exitcode = 1;
                return -1;
        }
 
        if ((flags & (IO_PATH|IO_NOFOLLOW)) &&
            (flags & ~(IO_PATH|IO_NOFOLLOW))) {
                fprintf(stderr, _("-P and -L are incompatible with the other options\n"));
+               exitcode = 1;
                return -1;
        }
 
        fd = openfile(argv[optind], &geometry, flags, mode, &fsp);
-       if (fd < 0)
+       if (fd < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        if (!platform_test_xfs_fd(fd))
                flags |= IO_FOREIGN;
 
-       addfile(argv[optind], fd, &geometry, flags, &fsp);
+       if (addfile(argv[optind], fd, &geometry, flags, &fsp) != 0) {
+               exitcode = 1;
+               return 0;
+       }
+
        return 0;
 }
 
@@ -334,6 +347,7 @@ close_f(
 
        if (close(file->fd) < 0) {
                perror("close");
+               exitcode = 1;
                return 0;
        }
        free(file->name);
@@ -389,9 +403,12 @@ lsproj_callback(
        if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else {
                if (getprojid(path, fd, &projid) == 0)
                        printf("[%u] %s\n", (unsigned int)projid, path);
+               else
+                       exitcode = 1;
                close(fd);
        }
        return 0;
@@ -417,19 +434,23 @@ lsproj_f(
                        recurse_dir = 0;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&lsproj_cmd);
                }
        }
 
-       if (argc != optind)
+       if (argc != optind) {
+               exitcode = 1;
                return command_usage(&lsproj_cmd);
+       }
 
        if (recurse_all || recurse_dir)
                nftw(file->name, lsproj_callback,
                        100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
-       else if (getprojid(file->name, file->fd, &projid) < 0)
+       else if (getprojid(file->name, file->fd, &projid) < 0) {
                perror("getprojid");
-       else
+               exitcode = 1;
+       } else
                printf(_("projid = %u\n"), (unsigned int)projid);
        return 0;
 }
@@ -461,9 +482,12 @@ chproj_callback(
        if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else {
-               if (setprojid(path, fd, prid) < 0)
+               if (setprojid(path, fd, prid) < 0) {
                        perror("setprojid");
+                       exitcode = 1;
+               }
                close(fd);
        }
        return 0;
@@ -488,24 +512,30 @@ chproj_f(
                        recurse_dir = 0;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&chproj_cmd);
                }
        }
 
-       if (argc != optind + 1)
+       if (argc != optind + 1) {
+               exitcode = 1;
                return command_usage(&chproj_cmd);
+       }
 
        prid = prid_from_string(argv[optind]);
        if (prid == -1) {
                printf(_("invalid project ID -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
        if (recurse_all || recurse_dir)
                nftw(file->name, chproj_callback,
                        100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
-       else if (setprojid(file->name, file->fd, prid) < 0)
+       else if (setprojid(file->name, file->fd, prid) < 0) {
                perror("setprojid");
+               exitcode = 1;
+       }
        return 0;
 }
 
@@ -529,7 +559,7 @@ get_extsize(const char *path, int fd)
        if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                printf("%s: FS_IOC_FSGETXATTR %s: %s\n",
                        progname, path, strerror(errno));
-               return 0;
+               return -1;
        }
        printf("[%u] %s\n", fsx.fsx_extsize, path);
        return 0;
@@ -543,12 +573,12 @@ set_extsize(const char *path, int fd, long extsz)
 
        if (fstat(fd, &stat) < 0) {
                perror("fstat");
-               return 0;
+               return -1;
        }
        if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
                printf("%s: FS_IOC_FSGETXATTR %s: %s\n",
                        progname, path, strerror(errno));
-               return 0;
+               return -1;
        }
 
        if (S_ISREG(stat.st_mode)) {
@@ -557,14 +587,14 @@ set_extsize(const char *path, int fd, long extsz)
                fsx.fsx_xflags |= FS_XFLAG_EXTSZINHERIT;
        } else {
                printf(_("invalid target file type - file %s\n"), path);
-               return 0;
+               return -1;
        }
        fsx.fsx_extsize = extsz;
 
        if ((xfsctl(path, fd, FS_IOC_FSSETXATTR, &fsx)) < 0) {
                printf("%s: FS_IOC_FSSETXATTR %s: %s\n",
                        progname, path, strerror(errno));
-               return 0;
+               return -1;
        }
 
        return 0;
@@ -585,8 +615,10 @@ get_extsize_callback(
        if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else {
-               get_extsize(path, fd);
+               if (get_extsize(path, fd) < 0)
+                       exitcode = 1;
                close(fd);
        }
        return 0;
@@ -607,8 +639,10 @@ set_extsize_callback(
        if ((fd = open(path, O_RDONLY)) == -1) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
+               exitcode = 1;
        } else {
-               set_extsize(path, fd, extsize);
+               if (set_extsize(path, fd, extsize) < 0)
+                       exitcode = 1;
                close(fd);
        }
        return 0;
@@ -635,6 +669,7 @@ extsize_f(
                        recurse_dir = 0;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&extsize_cmd);
                }
        }
@@ -644,20 +679,23 @@ extsize_f(
                if (extsize < 0) {
                        printf(_("non-numeric extsize argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        return 0;
                }
        } else {
                extsize = -1;
        }
 
-       if (recurse_all || recurse_dir)
+       if (recurse_all || recurse_dir) {
                nftw(file->name, (extsize >= 0) ?
                        set_extsize_callback : get_extsize_callback,
                        100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
-       else if (extsize >= 0)
-               set_extsize(file->name, file->fd, extsize);
-       else
-               get_extsize(file->name, file->fd);
+       } else if (extsize >= 0) {
+               if (set_extsize(file->name, file->fd, extsize) < 0)
+                       exitcode = 1;
+       } else if (get_extsize(file->name, file->fd) < 0) {
+               exitcode = 1;
+       }
        return 0;
 }
 
@@ -689,6 +727,7 @@ get_last_inode(void)
        ret = -xfrog_inumbers_alloc_req(IGROUP_NR, 0, &ireq);
        if (ret) {
                xfrog_perror(ret, "alloc req");
+               exitcode = 1;
                return 0;
        }
 
@@ -696,6 +735,7 @@ get_last_inode(void)
                ret = -xfrog_inumbers(&xfd, ireq);
                if (ret) {
                        xfrog_perror(ret, "XFS_IOC_FSINUMBERS");
+                       exitcode = 1;
                        goto out;
                }
 
@@ -744,6 +784,7 @@ inode_f(
                        ret_next = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&inode_cmd);
                }
        }
@@ -761,12 +802,16 @@ inode_f(
        }
 
        /* Extra junk? */
-       if (optind < argc)
+       if (optind < argc) {
+               exitcode = 1;
                return command_usage(&inode_cmd);
+       }
 
        /* -n option requires an inode number */
-       if (ret_next && userino == NULLFSINO)
+       if (ret_next && userino == NULLFSINO) {
+               exitcode = 1;
                return command_usage(&inode_cmd);
+       }
 
        if (userino == NULLFSINO) {
                /* We are finding last inode in use */
index a78b45884be05412ce90632a082325c3077559a7..8f63607ffec29320c06a7c76b7a494ec9bcd1456 100644 (file)
@@ -375,6 +375,7 @@ parent_f(int argc, char **argv)
        if (!fs) {
                fprintf(stderr, _("file argument, \"%s\", is not in a mounted XFS filesystem\n"),
                        file->name);
+               exitcode = 1;
                return 1;
        }
        mntpt = fs->fs_dir;
index d52e21d965f0803e506c5b6742c5e09f91c13230..971dbbc93363c43f08d524a2530e9b771cdb8807 100644 (file)
@@ -387,6 +387,7 @@ pread_f(
                        tmp = cvtnum(fsblocksize, fssectsize, optarg);
                        if (tmp < 0) {
                                printf(_("non-numeric bsize -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        bsize = tmp;
@@ -418,6 +419,7 @@ pread_f(
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric vector count == %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -426,21 +428,26 @@ pread_f(
                        zeed = strtoul(optarg, &sp, 0);
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric seed -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&pread_cmd);
                }
        }
-       if (optind != argc - 2)
+       if (optind != argc - 2) {
+               exitcode = 1;
                return command_usage(&pread_cmd);
+       }
 
        offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (offset < 0 && (direction & (IO_RANDOM|IO_BACKWARD))) {
                eof = -1;       /* read from EOF */
        } else if (offset < 0) {
                printf(_("non-numeric length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
@@ -449,11 +456,14 @@ pread_f(
                eof = -1;       /* read to EOF */
        } else if (count < 0) {
                printf(_("non-numeric length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
-       if (alloc_buffer(bsize, uflag, 0xabababab) < 0)
+       if (alloc_buffer(bsize, uflag, 0xabababab) < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        gettimeofday(&t1, NULL);
        switch (direction) {
@@ -473,8 +483,11 @@ pread_f(
        default:
                ASSERT(0);
        }
-       if (c < 0)
+       if (c < 0) {
+               exitcode = 1;
                return 0;
+       }
+
        if (qflag)
                return 0;
        gettimeofday(&t2, NULL);
index 6d452354ee458fdf1f60ccdc3f54063c65e8bc63..382e811919c674fe29355a5e62b91ad7e444a138 100644 (file)
@@ -76,11 +76,14 @@ allocsp_f(
 {
        xfs_flock64_t   segment;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (xfsctl(file->name, file->fd, XFS_IOC_ALLOCSP64, &segment) < 0) {
                perror("XFS_IOC_ALLOCSP64");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -93,11 +96,14 @@ freesp_f(
 {
        xfs_flock64_t   segment;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (xfsctl(file->name, file->fd, XFS_IOC_FREESP64, &segment) < 0) {
                perror("XFS_IOC_FREESP64");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -110,11 +116,14 @@ resvsp_f(
 {
        xfs_flock64_t   segment;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (xfsctl(file->name, file->fd, XFS_IOC_RESVSP64, &segment) < 0) {
                perror("XFS_IOC_RESVSP64");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -127,11 +136,14 @@ unresvsp_f(
 {
        xfs_flock64_t   segment;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (xfsctl(file->name, file->fd, XFS_IOC_UNRESVSP64, &segment) < 0) {
                perror("XFS_IOC_UNRESVSP64");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -144,11 +156,14 @@ zero_f(
 {
        xfs_flock64_t   segment;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (xfsctl(file->name, file->fd, XFS_IOC_ZERO_RANGE, &segment) < 0) {
                perror("XFS_IOC_ZERO_RANGE");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -204,18 +219,24 @@ fallocate_f(
                        mode = FALLOC_FL_UNSHARE_RANGE;
                        break;
                default:
+                       exitcode = 1;
                        command_usage(&falloc_cmd);
                }
        }
-        if (optind != argc - 2)
+        if (optind != argc - 2) {
+               exitcode = 1;
                 return command_usage(&falloc_cmd);
+       }
 
-       if (!offset_length(argv[optind], argv[optind+1], &segment))
+       if (!offset_length(argv[optind], argv[optind+1], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (fallocate(file->fd, mode,
                        segment.l_start, segment.l_len)) {
                perror("fallocate");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -229,12 +250,15 @@ fpunch_f(
        xfs_flock64_t   segment;
        int             mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (fallocate(file->fd, mode,
                        segment.l_start, segment.l_len)) {
                perror("fallocate");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -248,12 +272,15 @@ fcollapse_f(
        xfs_flock64_t   segment;
        int             mode = FALLOC_FL_COLLAPSE_RANGE;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (fallocate(file->fd, mode,
                        segment.l_start, segment.l_len)) {
                perror("fallocate");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -267,12 +294,15 @@ finsert_f(
        xfs_flock64_t   segment;
        int             mode = FALLOC_FL_INSERT_RANGE;
 
-       if (!offset_length(argv[1], argv[2], &segment))
+       if (!offset_length(argv[1], argv[2], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (fallocate(file->fd, mode,
                        segment.l_start, segment.l_len)) {
                perror("fallocate");
+               exitcode = 1;
                return 0;
        }
        return 0;
@@ -318,12 +348,15 @@ funshare_f(
        int             mode = FALLOC_FL_UNSHARE_RANGE;
        int             index = 1;
 
-       if (!offset_length(argv[index], argv[index + 1], &segment))
+       if (!offset_length(argv[index], argv[index + 1], &segment)) {
+               exitcode = 1;
                return 0;
+       }
 
        if (fallocate(file->fd, mode,
                        segment.l_start, segment.l_len)) {
                perror("fallocate");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 1c28612f3bd6a2849e2b3fae9663e8e23290eece..995f6ece83848cdeaf2dc041ef2cbbcb29243c67 100644 (file)
@@ -295,6 +295,7 @@ pwrite_f(
                        tmp = cvtnum(fsblocksize, fssectsize, optarg);
                        if (tmp < 0) {
                                printf(_("non-numeric bsize -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        bsize = tmp;
@@ -333,6 +334,7 @@ pwrite_f(
                        skip = cvtnum(fsblocksize, fssectsize, optarg);
                        if (skip < 0) {
                                printf(_("non-numeric skip -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -340,6 +342,7 @@ pwrite_f(
                        seed = strtoul(optarg, &sp, 0);
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric seed -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -355,6 +358,7 @@ pwrite_f(
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric vector count == %s\n"),
                                        optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -369,11 +373,13 @@ pwrite_f(
                        zeed = strtoul(optarg, &sp, 0);
                        if (!sp || sp == optarg) {
                                printf(_("non-numeric seed -- %s\n"), optarg);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
                default:
                        /* Handle ifdef'd-out options above */
+                       exitcode = 1;
                        if (c != '?')
                                printf(_("%s: command -%c not supported\n"), argv[0], c);
                        else
@@ -381,28 +387,38 @@ pwrite_f(
                        return 0;
                }
        }
-       if (((skip || dflag) && !infile) || (optind != argc - 2))
+       if (((skip || dflag) && !infile) || (optind != argc - 2)) {
+               exitcode = 1;
                return command_usage(&pwrite_cmd);
-       if (infile && direction != IO_FORWARD)
+       }
+       if (infile && direction != IO_FORWARD) {
+               exitcode = 1;
                return command_usage(&pwrite_cmd);
+       }
        offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (offset < 0) {
                printf(_("non-numeric offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        count = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (count < 0) {
                printf(_("non-numeric length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
-       if (alloc_buffer(bsize, uflag, seed) < 0)
+       if (alloc_buffer(bsize, uflag, seed) < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        c = IO_READONLY | (dflag ? IO_DIRECT : 0);
-       if (infile && ((fd = openfile(infile, NULL, c, 0, NULL)) < 0))
+       if (infile && ((fd = openfile(infile, NULL, c, 0, NULL)) < 0)) {
+               exitcode = 1;
                return 0;
+       }
 
        gettimeofday(&t1, NULL);
        switch (direction) {
@@ -425,20 +441,25 @@ pwrite_f(
                total = 0;
                ASSERT(0);
        }
-       if (c < 0)
+       if (c < 0) {
+               exitcode = 1;
                goto done;
+       }
        if (Wflag) {
                if (fsync(file->fd) < 0) {
                        perror("fsync");
+                       exitcode = 1;
                        goto done;
                }
        }
        if (wflag) {
                if (fdatasync(file->fd) < 0) {
                        perror("fdatasync");
+                       exitcode = 1;
                        goto done;
                }
        }
+
        if (qflag)
                goto done;
        gettimeofday(&t2, NULL);
index 2cb897736faf9b46e3623ba36924b2d64d5c8140..8ac3f988ac2f73c8e45f372755406e2b7e29e7a6 100644 (file)
@@ -151,18 +151,22 @@ readdir_f(
                        verbose = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&readdir_cmd);
                }
        }
 
        dfd = dup(file->fd);
-       if (dfd < 0)
-               return -1;
+       if (dfd < 0) {
+               exitcode = 1;
+               return 0;
+       }
 
        dir = fdopendir(dfd);
        if (!dir) {
                close(dfd);
-               return -1;
+               exitcode = 1;
+               return 0;
        }
 
        if (offset == -1) {
index 26eb2e32442d6e2a8ac5d04fc2ee4c8932c493f2..8e4f389949be17ca1d382457549b6435362efa9b 100644 (file)
@@ -63,6 +63,7 @@ dedupe_ioctl(
                error = ioctl(fd, XFS_IOC_FILE_EXTENT_SAME, args);
                if (error) {
                        perror("XFS_IOC_FILE_EXTENT_SAME");
+                       exitcode = 1;
                        goto done;
                }
                if (info->status < 0) {
@@ -117,34 +118,42 @@ dedupe_f(
                        quiet_flag = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&dedupe_cmd);
                }
        }
-       if (optind != argc - 4)
+       if (optind != argc - 4) {
+               exitcode = 1;
                return command_usage(&dedupe_cmd);
+       }
        infile = argv[optind];
        optind++;
        soffset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (soffset < 0) {
                printf(_("non-numeric src offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        doffset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (doffset < 0) {
                printf(_("non-numeric dest offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        count = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (count < 0) {
                printf(_("non-positive length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
        fd = openfile(infile, NULL, IO_READONLY, 0, NULL);
-       if (fd < 0)
+       if (fd < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        gettimeofday(&t1, NULL);
        total = dedupe_ioctl(fd, soffset, doffset, count, &ops);
@@ -238,11 +247,14 @@ reflink_f(
                        quiet_flag = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&reflink_cmd);
                }
        }
-       if (optind != argc - 4 && optind != argc - 1)
+       if (optind != argc - 4 && optind != argc - 1) {
+               exitcode = 1;
                return command_usage(&reflink_cmd);
+       }
        infile = argv[optind];
        optind++;
        if (optind == argc)
@@ -250,29 +262,37 @@ reflink_f(
        soffset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (soffset < 0) {
                printf(_("non-numeric src offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        doffset = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (doffset < 0) {
                printf(_("non-numeric dest offset argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
        count = cvtnum(fsblocksize, fssectsize, argv[optind]);
        if (count < 0) {
                printf(_("non-positive length argument -- %s\n"), argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
 clone_all:
        fd = openfile(infile, NULL, IO_READONLY, 0, NULL);
-       if (fd < 0)
+       if (fd < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        gettimeofday(&t1, NULL);
        total = reflink_ioctl(fd, soffset, doffset, count, &ops);
-       if (ops == 0 || quiet_flag)
+       if (ops == 0)
+               goto done;
+
+       if (quiet_flag)
                goto done;
        gettimeofday(&t2, NULL);
        t2 = tsub(t2, t1);
index 0dbec09576589ca054a0ba2fde353e30473ad94e..a93b14ff48e5022ba733749ddcb72fcac4ea6540 100644 (file)
@@ -24,15 +24,18 @@ resblks_f(
                blks = cvtnum(file->geom.blocksize, file->geom.sectsize, argv[1]);
                if (blks < 0) {
                        printf(_("non-numeric argument -- %s\n"), argv[1]);
+                       exitcode = 1;
                        return 0;
                }
                res.resblks = blks;
                if (xfsctl(file->name, file->fd, XFS_IOC_SET_RESBLKS, &res) < 0) {
                        perror("XFS_IOC_SET_RESBLKS");
+                       exitcode = 1;
                        return 0;
                }
        } else if (xfsctl(file->name, file->fd, XFS_IOC_GET_RESBLKS, &res) < 0) {
                perror("XFS_IOC_GET_RESBLKS");
+               exitcode = 1;
                return 0;
        }
        printf(_("reserved blocks = %llu\n"),
index 59ba1cfd1db33316f28a989a76656829114cd0eb..6734ecb5691a124995961532f26d47a298b1a072 100644 (file)
--- a/io/seek.c
+++ b/io/seek.c
@@ -120,15 +120,20 @@ seek_f(
                        startflag = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&seek_cmd);
                }
        }
-       if (!(flag & (SEEK_DFLAG | SEEK_HFLAG)) || optind != argc - 1)
+       if (!(flag & (SEEK_DFLAG | SEEK_HFLAG)) || optind != argc - 1) {
+               exitcode = 1;
                return command_usage(&seek_cmd);
+       }
 
        start = offset = cvtnum(fsblocksize, fssectsize, argv[optind]);
-       if (offset < 0)
+       if (offset < 0) {
+               exitcode = 1;
                return command_usage(&seek_cmd);
+       }
 
        /*
         * check to see if the offset is a data or hole entry and
@@ -174,9 +179,10 @@ found_hole:
        for (c = 0; flag; c++) {
                if (offset == -1) {
                        /* print error or eof if the only entry */
-                       if (errno != ENXIO || c == 0 )
+                       if (errno != ENXIO || c == 0 ) {
                                seek_output(startflag, seekinfo[current].name,
                                            start, offset);
+                       }
                        return 0;       /* stop on error or EOF */
                }
 
index 68e607f1b32bb7a0e3ee9baf24a8d60316dbe3e8..ff012c81042deaa357de63f80b17ae2fb7406621 100644 (file)
@@ -88,6 +88,7 @@ sendfile_f(
                        if (fd < 0 || fd >= filecount) {
                                printf(_("value %d is out of range (0-%d)\n"),
                                        fd, filecount-1);
+                               exitcode = 1;
                                return 0;
                        }
                        break;
@@ -95,22 +96,28 @@ sendfile_f(
                        infile = optarg;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&sendfile_cmd);
                }
        }
-       if (infile && fd != -1)
+       if (infile && fd != -1) {
+               exitcode = 1;
                return command_usage(&sendfile_cmd);
+       }
 
        if (!infile)
                fd = filetable[fd].fd;
-       else if ((fd = openfile(infile, NULL, IO_READONLY, 0, NULL)) < 0)
+       else if ((fd = openfile(infile, NULL, IO_READONLY, 0, NULL)) < 0) {
+               exitcode = 1;
                return 0;
+       }
 
        if (optind == argc - 2) {
                offset = cvtnum(blocksize, sectsize, argv[optind]);
                if (offset < 0) {
                        printf(_("non-numeric offset argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        goto done;
                }
                optind++;
@@ -118,6 +125,7 @@ sendfile_f(
                if (count < 0) {
                        printf(_("non-numeric length argument -- %s\n"),
                                argv[optind]);
+                       exitcode = 1;
                        goto done;
                }
        } else {
@@ -125,6 +133,7 @@ sendfile_f(
 
                if (fstat(fd, &stat) < 0) {
                        perror("fstat");
+                       exitcode = 1;
                        goto done;
                }
                count = stat.st_size;
@@ -132,8 +141,11 @@ sendfile_f(
 
        gettimeofday(&t1, NULL);
        c = send_buffer(offset, count, fd, &total);
-       if (c < 0)
+       if (c < 0) {
+               exitcode = 1;
                goto done;
+       }
+
        if (qflag)
                goto done;
        gettimeofday(&t2, NULL);
index 052d3def1d4a64d0a3fadfe4cae94f3c3f5e5db2..3c29ea790643f885bc8c4130a40d7c4d601a5ed1 100644 (file)
@@ -24,12 +24,14 @@ shutdown_f(
                        flag = XFS_FSOP_GOING_FLAGS_LOGFLUSH;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&shutdown_cmd);
                }
        }
 
        if ((xfsctl(file->name, file->fd, XFS_IOC_GOINGDOWN, &flag)) < 0) {
                perror("XFS_IOC_GOINGDOWN");
+               exitcode = 1;
                return 0;
        }
        return 0;
index d125a0f78539779d99a7d0679cdc9cab32ab5c5b..5f513e0ddfc815b396938b0dc6bd514a87cae91a 100644 (file)
--- a/io/stat.c
+++ b/io/stat.c
@@ -137,15 +137,19 @@ stat_f(
                        verbose = 1;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&stat_cmd);
                }
        }
 
-       if (raw && verbose)
+       if (raw && verbose) {
+               exitcode = 1;
                return command_usage(&stat_cmd);
+       }
 
        if (fstat(file->fd, &st) < 0) {
                perror("fstat");
+               exitcode = 1;
                return 0;
        }
 
@@ -185,6 +189,7 @@ statfs_f(
        printf(_("fd.path = \"%s\"\n"), file->name);
        if (platform_fstatfs(file->fd, &st) < 0) {
                perror("fstatfs");
+               exitcode = 1;
        } else {
                printf(_("statfs.f_bsize = %lld\n"), (long long) st.f_bsize);
                printf(_("statfs.f_blocks = %lld\n"), (long long) st.f_blocks);
@@ -200,6 +205,7 @@ statfs_f(
        ret = -xfrog_geometry(file->fd, &fsgeo);
        if (ret) {
                xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
+               exitcode = 1;
        } else {
                printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
                printf(_("geom.agcount = %u\n"), fsgeo.agcount);
@@ -216,6 +222,7 @@ statfs_f(
        }
        if ((xfsctl(file->name, file->fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) {
                perror("XFS_IOC_FSCOUNTS");
+               exitcode = 1;
        } else {
                printf(_("counts.freedata = %llu\n"),
                        (unsigned long long) fscounts.freedata);
@@ -321,6 +328,7 @@ statx_f(
                                if (!p || p == optarg) {
                                        printf(
                                _("non-numeric mask -- %s\n"), optarg);
+                                       exitcode = 1;
                                        return 0;
                                }
                        }
@@ -340,6 +348,7 @@ statx_f(
                        atflag |= AT_STATX_DONT_SYNC;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&statx_cmd);
                }
        }
@@ -350,8 +359,10 @@ statx_f(
        memset(&stx, 0xbf, sizeof(stx));
        if (_statx(file->fd, "", atflag | AT_EMPTY_PATH, mask, &stx) < 0) {
                perror("statx");
+               exitcode = 1;
                return 0;
        }
+       exitcode = 0;
 
        if (raw)
                return dump_raw_statx(&stx);
index 30bbc93d55a15f5cd5202c483ce175c9f3c909d7..94285c22f829d64c2ec45dffb54f7b681b942a8f 100644 (file)
@@ -46,6 +46,7 @@ sync_range_f(
                        sync_mode = SYNC_FILE_RANGE_WRITE;
                        break;
                default:
+                       exitcode = 1;
                        return command_usage(&sync_range_cmd);
                }
        }
@@ -54,13 +55,16 @@ sync_range_f(
        if (!sync_mode)
                sync_mode = SYNC_FILE_RANGE_WRITE;
 
-       if (optind != argc - 2)
+       if (optind != argc - 2) {
+               exitcode = 1;
                return command_usage(&sync_range_cmd);
+       }
        init_cvtnum(&blocksize, &sectsize);
        offset = cvtnum(blocksize, sectsize, argv[optind]);
        if (offset < 0) {
                printf(_("non-numeric offset argument -- %s\n"),
                        argv[optind]);
+               exitcode = 1;
                return 0;
        }
        optind++;
@@ -68,11 +72,13 @@ sync_range_f(
        if (length < 0) {
                printf(_("non-numeric length argument -- %s\n"),
                        argv[optind]);
+               exitcode = 1;
                return 0;
        }
 
        if (sync_file_range(file->fd, offset, length, sync_mode) < 0) {
                perror("sync_file_range");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 5c3f54c4cdf831c9e589e6329bca513a32a1f562..1d049194d38069f608db56ad6282f6970cc1a5ac 100644 (file)
@@ -23,11 +23,13 @@ truncate_f(
        offset = cvtnum(blocksize, sectsize, argv[1]);
        if (offset < 0) {
                printf(_("non-numeric truncate argument -- %s\n"), argv[1]);
+               exitcode = 1;
                return 0;
        }
 
        if (ftruncate(file->fd, offset) < 0) {
                perror("ftruncate");
+               exitcode = 1;
                return 0;
        }
        return 0;
index 40117472e87365eb43fc85e21eb996fcafe1d22b..39127b84a90c7f149f0392363c56ff51779165fb 100644 (file)
@@ -36,17 +36,20 @@ utimes_f(
        result = timespec_from_string(argv[1], argv[2], &t[0]);
        if (result) {
                fprintf(stderr, "Bad value for atime\n");
+               exitcode = 1;
                return 0;
        }
        result = timespec_from_string(argv[3], argv[4], &t[1]);
        if (result) {
                fprintf(stderr, "Bad value for mtime\n");
+               exitcode = 1;
                return 0;
        }
 
        /* Call futimens to update time. */
        if (futimens(file->fd, t)) {
                perror("futimens");
+               exitcode = 1;
                return 0;
        }