[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] parted: exit nonzero for certain failures already diagnosed as "
From: |
Jim Meyering |
Subject: |
[PATCH] parted: exit nonzero for certain failures already diagnosed as "Error" |
Date: |
Thu, 03 Nov 2011 22:08:36 +0100 |
While working on a different GPT-related problem,
I was surprised to see an "Error: ...", yet to see that
parted exited successfully. This fixes that:
>From f0e91a88107642b17f1c7801d9326460924a1948 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 3 Nov 2011 17:57:19 +0100
Subject: [PATCH] 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.
---
NEWS | 5 +++++
parted/parted.c | 17 ++++++++++++++---
tests/t0101-print-empty.sh | 4 ++--
3 files changed, 21 insertions(+), 5 deletions(-)
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:,; \
--
1.7.8.rc0.32.g87bf9
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] parted: exit nonzero for certain failures already diagnosed as "Error",
Jim Meyering <=