summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorKarel Zak2017-08-21 11:11:11 +0200
committerKarel Zak2017-08-21 11:11:11 +0200
commitc38018028946a45e131e91af68cd8090f74a8c1f (patch)
treec926dc443bfc91275249abe4fb4a3105103f86b6 /disk-utils
parentlook: use WORDLIST environment variable to find word list (diff)
downloadkernel-qcow2-util-linux-c38018028946a45e131e91af68cd8090f74a8c1f.tar.gz
kernel-qcow2-util-linux-c38018028946a45e131e91af68cd8090f74a8c1f.tar.xz
kernel-qcow2-util-linux-c38018028946a45e131e91af68cd8090f74a8c1f.zip
isosize: iterate over all arguments even when something fails
Earlier the command exit too early if one of the arguments failed. After this change all arguments are examined, and command return value will have information what happen during processing. Based on patch from Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/isosize.817
-rw-r--r--disk-utils/isosize.c41
2 files changed, 45 insertions, 13 deletions
diff --git a/disk-utils/isosize.8 b/disk-utils/isosize.8
index 44ac124ea..baa5f7d2a 100644
--- a/disk-utils/isosize.8
+++ b/disk-utils/isosize.8
@@ -32,6 +32,23 @@ filesystem can be marginally larger than the actual size of the
iso9660 filesystem. One reason for this is that cd writers
are allowed to add "run out" sectors at the end of an iso9660
image.
+.SH "EXIT STATUS"
+.RS
+.PD 0
+.TP
+.B 0
+success
+.TP
+.B 1
+generic failure, such as invalid usage
+.TP
+.B 32
+all failed
+.TP
+.B 64
+some failed
+.PD
+.RE
.SH AVAILABILITY
The isosize command is part of the util-linux package and is available from
.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
diff --git a/disk-utils/isosize.c b/disk-utils/isosize.c
index 5fbbbfc76..21133e0d7 100644
--- a/disk-utils/isosize.c
+++ b/disk-utils/isosize.c
@@ -30,6 +30,9 @@
#include "strutils.h"
#include "closestream.h"
+#define ISOSIZE_EXIT_ALLFAILED 32
+#define ISOSIZE_EXIT_SOMEOK 64
+
static int is_iso(int fd)
{
char label[8];
@@ -86,22 +89,26 @@ static int isonum_733(unsigned char *p, int xflag)
return (le);
}
-static void isosize(int argc, char *filenamep, int xflag, long divisor)
+static int isosize(int argc, char *filenamep, int xflag, long divisor)
{
- int fd, nsecs, ssize;
+ int fd, nsecs, ssize, rc = -1;
unsigned char volume_space_size[8];
unsigned char logical_block_size[4];
- if ((fd = open(filenamep, O_RDONLY)) < 0)
- err(EXIT_FAILURE, _("cannot open %s"), filenamep);
+ if ((fd = open(filenamep, O_RDONLY)) < 0) {
+ warn(_("cannot open %s"), filenamep);
+ goto done;
+ }
if (is_iso(fd))
warnx(_("%s: might not be an ISO filesystem"), filenamep);
- if (pread(fd, volume_space_size, sizeof(volume_space_size), 0x8050) <= 0 ||
- pread(fd, logical_block_size, sizeof(logical_block_size), 0x8080) <= 0) {
+ if (pread(fd, volume_space_size, sizeof(volume_space_size), 0x8050) != sizeof(volume_space_size) ||
+ pread(fd, logical_block_size, sizeof(logical_block_size), 0x8080) != sizeof(logical_block_size)) {
if (errno)
- err(EXIT_FAILURE, _("read error on %s"), filenamep);
- errx(EXIT_FAILURE, _("read error on %s"), filenamep);
+ warn(_("read error on %s"), filenamep);
+ else
+ warnx(_("read error on %s"), filenamep);
+ goto done;
}
nsecs = isonum_733(volume_space_size, xflag);
@@ -123,7 +130,11 @@ static void isosize(int argc, char *filenamep, int xflag, long divisor)
printf("%lld\n", (product * ssize) / divisor);
}
- close(fd);
+ rc = 0;
+done:
+ if (fd >= 0)
+ close(fd);
+ return rc;
}
static void __attribute__((__noreturn__)) usage(void)
@@ -149,7 +160,7 @@ static void __attribute__((__noreturn__)) usage(void)
int main(int argc, char **argv)
{
- int j, ct, opt, xflag = 0;
+ int j, ct_err = 0, ct, opt, xflag = 0;
long divisor = 0;
static const struct option longopts[] = {
@@ -191,8 +202,12 @@ int main(int argc, char **argv)
errtryhelp(EXIT_FAILURE);
}
- for (j = optind; j < argc; j++)
- isosize(ct, argv[j], xflag, divisor);
+ for (j = optind; j < argc; j++) {
+ if (isosize(ct, argv[j], xflag, divisor) != 0)
+ ct_err++;
+ }
- return EXIT_SUCCESS;
+ return ct == ct_err ? ISOSIZE_EXIT_ALLFAILED : /* all failed */
+ ct_err ? ISOSIZE_EXIT_SOMEOK : /* some ok */
+ EXIT_SUCCESS; /* all success */
}