[Parted-commits] GNU Parted Official Repository: Changes to 'master'
Jim Meyering
meyering at alioth.debian.org
Thu Nov 3 21:08:55 UTC 2011
NEWS | 5 +++++
parted/parted.c | 17 ++++++++++++++---
tests/t0101-print-empty.sh | 4 ++--
tests/t0203-gpt-tiny-device-abort.sh | 2 +-
4 files changed, 22 insertions(+), 6 deletions(-)
New commits:
commit f0e91a88107642b17f1c7801d9326460924a1948
Author: Jim Meyering <meyering at redhat.com>
Date: Thu Nov 3 17:57:19 2011 +0100
parted: exit nonzero for certain failures already diagnosed as "Error"
* parted/parted.c (do_print): Do not exit successfully when issuing
an error about an "unrecognised disk label" or when both GPT primary
and backup tables are corrupted.
* tests/t0101-print-empty.sh: Adjust expected exit code to match
new behavior.
* NEWS (Bug fixes): Mention this.
diff --git a/NEWS b/NEWS
index af1d957..b043ba1 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,11 @@ GNU parted NEWS -*- outline -*-
** Bug fixes
+ parted now exits nonzero for certain failures already diagnosed as "Error".
+ For example, before this change, parted would exit successfully in spite
+ of "Error: ...unrecognised disk label" and "Error:... both GPT primary
+ and backup partition tables are corrupted".
+
libparted: gpt_disk_duplicate now copies the flags over to the new
disk object. Previously the flags would be undefined.
diff --git a/parted/parted.c b/parted/parted.c
index b6f89aa..66beba6 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -990,6 +990,7 @@ do_print (PedDevice** dev)
const char* name;
char* tmp;
wchar_t* table_rendered;
+ int ok = 1; /* default to success */
peek_word = command_line_peek_word ();
if (peek_word) {
@@ -1015,8 +1016,18 @@ do_print (PedDevice** dev)
free (peek_word);
}
- if (!has_devices_arg && !has_list_arg)
+ if (!has_devices_arg && !has_list_arg) {
disk = ped_disk_new (*dev);
+ /* Returning NULL here is an indication of failure, when in
+ script mode. Otherwise (interactive mode) it may indicate
+ a real error, but it may also indicate that the user
+ declined when asked to perform some operation. FIXME:
+ what this really needs is an API change, but a reliable
+ exit code is less important in interactive mode. */
+ if (disk == NULL && opt_script_mode)
+ ok = 0;
+ }
+
if (disk &&
ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
@@ -1229,13 +1240,13 @@ do_print (PedDevice** dev)
ped_disk_destroy (disk);
- return 1;
+ return ok;
error_destroy_disk:
ped_disk_destroy (disk);
return 0;
nopt:
- return 1;
+ return ok;
}
static int
diff --git a/tests/t0101-print-empty.sh b/tests/t0101-print-empty.sh
index 3e77850..b8ff5ed 100755
--- a/tests/t0101-print-empty.sh
+++ b/tests/t0101-print-empty.sh
@@ -34,8 +34,8 @@ EOF
# create 'empty' device
dd if=/dev/zero of=$dev bs=$(expr 8 '*' $ss) count=1 >/dev/null 2>&1 || fail=1
-# print the empty table
-parted -s $dev unit s print >out 2>&1 || fail=1
+# print the empty table; expect nonzero exit status
+parted -s $dev unit s print >out 2>&1 && fail=1
# prepare actual and expected output
mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:,; \
commit e284640cc665843d8bdb35cb452a28ceb62591e0
Author: Jim Meyering <meyering at redhat.com>
Date: Thu Nov 3 16:59:07 2011 +0100
tests: adjust a test to make its failure easier to diagnose
* tests/t0203-gpt-tiny-device-abort.sh: When failing, also
emit parted's diagnostics.
diff --git a/tests/t0203-gpt-tiny-device-abort.sh b/tests/t0203-gpt-tiny-device-abort.sh
index 690f286..694bc9a 100644
--- a/tests/t0203-gpt-tiny-device-abort.sh
+++ b/tests/t0203-gpt-tiny-device-abort.sh
@@ -35,7 +35,7 @@ for i in 33 34 35 67 68 69 101 102 103; do
# Print the partition table. Before, this would evoke a failed assertion.
printf 'i\no\n' > in
- parted ---pretend-input-tty bad u s p < in > out 2> err || fail=1
+ parted ---pretend-input-tty bad u s p < in > out 2> err || { fail=1; cat err; }
# don't bother comparing stdout
done
More information about the Parted-commits
mailing list