cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
64664a
From e4f26d51bd06910634c2aaeccfecc7e6cd61ef0a Mon Sep 17 00:00:00 2001
64664a
From: Karel Zak <kzak@redhat.com>
64664a
Date: Fri, 17 Mar 2017 11:47:00 +0100
64664a
Subject: [PATCH 093/116] fdisk: improve -l error handling
64664a
64664a
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1362662
64664a
Signed-off-by: Karel Zak <kzak@redhat.com>
64664a
---
64664a
 fdisks/fdisk.c | 23 ++++++++++++++++-------
64664a
 1 file changed, 16 insertions(+), 7 deletions(-)
64664a
64664a
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
64664a
index 974d735..177921a 100644
64664a
--- a/fdisks/fdisk.c
64664a
+++ b/fdisks/fdisk.c
64664a
@@ -924,11 +924,15 @@ static int is_ide_cdrom_or_tape(char *device)
64664a
 }
64664a
 
64664a
 /* Print disk geometry and partition table of a specified device (-l option) */
64664a
-static void print_partition_table_from_option(struct fdisk_context *cxt,
64664a
-				char *device, unsigned long sector_size)
64664a
+static int print_partition_table_from_option(struct fdisk_context *cxt,
64664a
+				char *device, unsigned long sector_size,
64664a
+				int warnme)
64664a
 {
64664a
-	if (fdisk_context_assign_device(cxt, device, 1) != 0)	/* read-only */
64664a
-		err(EXIT_FAILURE, _("cannot open %s"), device);
64664a
+	if (fdisk_context_assign_device(cxt, device, 1) != 0) {	/* read-only */
64664a
+		if (warnme || errno == EACCES)
64664a
+			warn(_("cannot open %s"), device);
64664a
+		return -1;
64664a
+	}
64664a
 
64664a
 	if (sector_size) /* passed -b option, override autodiscovery */
64664a
 		fdisk_override_sector_size(cxt, sector_size);
64664a
@@ -941,6 +945,8 @@ static void print_partition_table_from_option(struct fdisk_context *cxt,
64664a
 		list_table(cxt, 0);
64664a
 	else
64664a
 		list_disk_geometry(cxt);
64664a
+
64664a
+	return 0;
64664a
 }
64664a
 
64664a
 /*
64664a
@@ -971,7 +977,7 @@ print_all_partition_table_from_option(struct fdisk_context *cxt,
64664a
 			char *cn = canonicalize_path(devname);
64664a
 			if (cn) {
64664a
 				if (!is_ide_cdrom_or_tape(cn))
64664a
-					print_partition_table_from_option(cxt, cn, sector_size);
64664a
+					print_partition_table_from_option(cxt, cn, sector_size, 0);
64664a
 				free(cn);
64664a
 			}
64664a
 		}
64664a
@@ -1223,14 +1229,17 @@ int main(int argc, char **argv)
64664a
 			 " be used with one specified device\n"));
64664a
 
64664a
 	if (optl) {
64664a
+		int rc = 0;
64664a
+
64664a
 		nowarn = 1;
64664a
 		if (argc > optind) {
64664a
 			int k;
64664a
 			for (k = optind; k < argc; k++)
64664a
-				print_partition_table_from_option(cxt, argv[k], sector_size);
64664a
+				rc += print_partition_table_from_option(cxt, argv[k], sector_size, 1);
64664a
 		} else
64664a
 			print_all_partition_table_from_option(cxt, sector_size);
64664a
-		exit(EXIT_SUCCESS);
64664a
+
64664a
+		exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);
64664a
 	}
64664a
 
64664a
 	if (opts) {
64664a
-- 
64664a
2.9.3
64664a