File s390-tools-sles15sp2-dasdfmt-Replace-ERRMSG_EXIT-macro-with-an-error-hand.patch of Package s390-tools.19914

From 732b3dddab8402bed1e10c41d3b839a7be7edc7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B6ppner?= <hoeppner@linux.ibm.com>
Date: Wed, 21 Oct 2020 20:26:00 +0200
Subject: [PATCH] dasdfmt: Replace ERRMSG_EXIT macro with an error handling
 function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The ERRMSG_EXIT macro is a bit clunky in its usage and a change is
necessary in order to free memory in error cases.

Create a new function error() that takes only a format string and adds
all other relevant information by itself. This function frees memory
before terminating the program with the EXIT_FAILURE exit code.

This simplifies the error handling for pretty much all calls and makes
the code a bit cleaner.

While at it, the defines EXIT_MISUSE and EXIT_BUSY don't provide any
value. Neither are they documented nor are these standardized. Also, a
parent process is mostly interessted in success or failure only anyway.
Replace these by using only EXIT_FAILURE in the error() function.

Also, change multiline output to a combination of warnx and error to
have a uniformed output. So this:

WARNING: Device is formatted with a different blocksize (4096).
Use --mode=full to perform a clean format.

becomes this:

dasdfmt: WARNING: Device is formatted with a different blocksize (4096).
dasdfmt: Use --mode=full to perform a clean format.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
---
 dasdfmt/dasdfmt.c | 255 ++++++++++++++++++----------------------------
 1 file changed, 97 insertions(+), 158 deletions(-)

diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c
index ef48c7a..86e9330 100644
--- a/dasdfmt/dasdfmt.c
+++ b/dasdfmt/dasdfmt.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/version.h>
+#include <stdarg.h>
 #include <sys/sysmacros.h>
 #include <sys/time.h>
 #include <sys/utsname.h>
@@ -186,6 +187,23 @@ static struct util_opt opt_vec[] = {
 	UTIL_OPT_END
 };
 
+/* Report error, free memory, and exit */
+static void error(const char *format, ...)
+{
+	va_list args;
+
+	fprintf(stderr, "%s: ", prog_name);
+	va_start(args, format);
+	vfprintf(stderr, format, args);
+	va_end(args);
+	fprintf(stderr, "\n");
+
+	free(g.dev_node);
+	free(g.dev_path);
+
+	exit(EXIT_FAILURE);
+}
+
 /*
  * Helper function to calculate the days, hours, minutes, and seconds
  * for a given timestamp in seconds
@@ -439,9 +457,7 @@ static void disk_enable(void)
 
 	err = dasd_disk_enable(filedes);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL "
-			    "BIODASDENABLE failed (%s)\n", prog_name,
-			    strerror(err));
+		error("(prepare device) IOCTL BIODASDENABLE failed: %s", strerror(err));
 	disk_disabled = 0;
 }
 
@@ -451,9 +467,7 @@ static void disk_disable(const char *device)
 
 	err = dasd_disk_disable(device, &filedes);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: (prepare device) IOCTL "
-			    "BIODASDDISABLE failed. (%s)\n", prog_name,
-			    strerror(err));
+		error("(prepare device) IOCTL BIODASDDISABLE failed: %s", strerror(err));
 	disk_disabled = 1;
 }
 
@@ -499,36 +513,27 @@ static void get_device_name(int optind, int argc, char *argv[])
 	struct stat dev_stat;
 
 	if (optind + 1 < argc)
-		ERRMSG_EXIT(EXIT_MISUSE,
-			    "%s: More than one device specified!\n", prog_name);
+		error("More than one device specified!");
 
 	if (optind >= argc)
-		ERRMSG_EXIT(EXIT_MISUSE, "%s: No device specified!\n",
-			    prog_name);
+		error("No device specified!");
 
 	if (strlen(argv[optind]) >= PATH_MAX)
-		ERRMSG_EXIT(EXIT_MISUSE, "%s: device name too long!\n",
-			    prog_name);
+		error("device name too long!");
 	util_asprintf(&g.dev_path, argv[optind]);
 
 	if (stat(g.dev_path, &dev_stat) != 0)
-		ERRMSG_EXIT(EXIT_MISUSE, "%s: Could not get information for "
-			    "device node %s: %s\n", prog_name, g.dev_path,
-			    strerror(errno));
+		error("Could not get information for device node %s: %s",
+		      g.dev_path, strerror(errno));
 
 	maj = major(dev_stat.st_rdev);
 	min = minor(dev_stat.st_rdev);
-	if (min & PARTN_MASK) {
-		ERRMSG_EXIT(EXIT_MISUSE, "%s: Unable to format partition %s. "
-			    "Please specify a device.\n", prog_name,
-			    g.dev_path);
-	}
+	if (min & PARTN_MASK)
+		error("Unable to format partition %s. Please specify a device.", g.dev_path);
 
 	if (util_proc_dev_get_entry(dev_stat.st_rdev, 1, &dev_entry) == 0) {
 		if (strncmp(dev_entry.name, "dasd", 4) != 0)
-			ERRMSG_EXIT(EXIT_MISUSE,
-				    "%s: Unsupported device type '%s'.\n",
-				    prog_name, dev_entry.name);
+			error("Unsupported device type '%s'.", dev_entry.name);
 	} else {
 		printf("%s WARNING: Unable to get driver name for device node %s",
 		       prog_name, g.dev_path);
@@ -543,9 +548,7 @@ static void get_blocksize(unsigned int *blksize)
 
 	err = dasd_get_blocksize(g.dev_node, blksize);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl to get the blocksize "
-			    "of the device failed (%s).\n", prog_name,
-			    strerror(err));
+		error("the ioctl to get the blocksize of the device failed: %s", strerror(err));
 }
 
 /*
@@ -561,9 +564,8 @@ static void check_blocksize(unsigned int blksize)
 
 	get_blocksize(&dev_blksize);
 	if (dev_blksize != blksize) {
-		ERRMSG_EXIT(EXIT_FAILURE, "WARNING: Device is formatted with a "
-			    "different blocksize (%d).\nUse --mode=full to "
-			    "perform a clean format.\n", dev_blksize);
+		warnx("WARNING: Device is formatted with a different blocksize (%d).", dev_blksize);
+		error("Use --mode=full to perform a clean format.");
 	}
 }
 
@@ -592,8 +594,7 @@ static void check_layout(unsigned int intensity)
 	if (g.dasd_info.format == DASD_FORMAT_LDL)
 		sprintf(layout, "LDL");
 
-	ERRMSG_EXIT(EXIT_FAILURE, "WARNING: Device is formatted with a "
-		    "different layout (%s).\n", layout);
+	error("WARNING: Device is formatted with a different layout (%s).", layout);
 }
 
 /*
@@ -606,29 +607,20 @@ static void check_disk(void)
 
 	err = dasd_is_ro(g.dev_node, &ro);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE,
-			    "%s: the ioctl call to retrieve read/write "
-			    "status information failed (%s)\n",
-			    prog_name, strerror(err));
-
+		error("the ioctl call to retrieve read/write status information failed: %s",
+		      strerror(err));
 	if (ro)
-		ERRMSG_EXIT(EXIT_FAILURE, "Disk is read only!\n");
-
-	if (!g.force)
+		error("Disk is read only!");
+	if (!g.force) {
 		if (g.dasd_info.open_count > 1)
-			ERRMSG_EXIT(EXIT_BUSY, "Disk in use!\n");
-
-	if (strncmp(g.dasd_info.type, "ECKD", 4) != 0) {
-		ERRMSG_EXIT(EXIT_FAILURE,
-			    "%s: Unsupported disk type\n%s is not an "
-			    "ECKD disk!\n", prog_name, g.dev_path);
+			error("Disk in use!");
 	}
-
-	if (dasd_sys_raw_track_access(g.dev_node)) {
-		ERRMSG_EXIT(EXIT_FAILURE,
-			    "%s: Device '%s' is in raw-track access mode\n",
-			    prog_name, g.dev_path);
+	if (strncmp(g.dasd_info.type, "ECKD", 4) != 0) {
+		warnx("Unsupported disk type");
+		error("%s is not an ECKD disk!", g.dev_path);
 	}
+	if (dasd_sys_raw_track_access(g.dev_node))
+		error("Device '%s' is in raw-track access mode", g.dev_path);
 }
 
 /*
@@ -811,10 +803,9 @@ static format_check_t check_track_format(format_data_t *p)
 			} else if (!g.check) {
 				ERRMSG(" (--force to override)");
 			}
-			ERRMSG_EXIT(EXIT_FAILURE, ".\n");
+			error(".");
 		}
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Could no check format: %s\n",
-			    prog_name, strerror(err));
+		error("Could not check format: %s", strerror(err));
 	}
 
 	return cdata;
@@ -855,9 +846,7 @@ static int process_tracks(unsigned int cylinders, unsigned int heads,
 		} else {
 			err = dasd_format_disk(filedes, &step);
 			if (err != 0)
-				ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl call "
-					    "to format tracks failed. (%s)\n",
-					    prog_name, strerror(err));
+				error("the ioctl call to format tracks failed: %s", strerror(err));
 		}
 
 		cyl = cur_trk / heads + 1;
@@ -905,10 +894,8 @@ static void check_disk_format(unsigned int cylinders, unsigned int heads,
 			check_params->intensity &= ~DASD_FMT_INT_COMPAT;
 	}
 
-	if (process_tracks(cylinders, heads, check_params)) {
-		ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform a "
-			    "clean format.\n");
-	}
+	if (process_tracks(cylinders, heads, check_params))
+		error("Use --mode=full to perform a clean format.");
 
 	printf("Done. Disk is fine.\n");
 }
@@ -1037,9 +1024,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 	 */
 	rc = dasd_get_geo(g.dev_node, &geo);
 	if (rc != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: (write labels) IOCTL "
-			    "HDIO_GETGEO failed (%s).\n",
-			    prog_name, strerror(rc));
+		error("(write labels) IOCTL HDIO_GETGEO failed: %s", strerror(rc));
 
 	if (g.verbosity > 0)
 		printf("ok\n");
@@ -1067,37 +1052,30 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 
 	fd = open(g.dev_node, O_RDWR);
 	if (fd < 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Unable to open device "
-			    "'%s' (%s)\n", prog_name, g.dev_path,
-			    strerror(errno));
+		error("Unable to open device '%s': %s", g.dev_path, strerror(errno));
 
 	if (lseek(fd, 0, SEEK_SET) != 0) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command 0 failed "
-			    "(%s)\n", prog_name, strerror(errno));
+		error("lseek command 0 failed: %s", strerror(errno));
 	}
 
 	rc = write(fd, ipl1_record, ipl1_record_len);
 	if (rc != ipl1_record_len) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Writing the bootstrap IPL1 "
-			    "failed, only wrote %d bytes.\n", prog_name, rc);
+		error("Writing the bootstrap IPL1 failed, only wrote %d bytes.", rc);
 	}
 
 	label_position = blksize;
 	rc = lseek(fd, label_position, SEEK_SET);
 	if (rc != label_position) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
-			    "(%s).\n", prog_name, label_position,
-			    strerror(errno));
+		error("lseek command to %i failed: %s", label_position, strerror(errno));
 	}
 
 	rc = write(fd, ipl2_record, ipl2_record_len);
 	if (rc != ipl2_record_len) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Writing the bootstrap IPL2 "
-			    "failed, only wrote %d bytes.\n", prog_name, rc);
+		error("Writing the bootstrap IPL2 failed, only wrote %d bytes.", rc);
 	}
 
 	/* write VTOC */
@@ -1117,9 +1095,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 	rc = lseek(fd, label_position, SEEK_SET);
 	if (rc != label_position) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
-			    "(%s).\n", prog_name, label_position,
-			    strerror(errno));
+		error("lseek command to %i failed: %s", label_position, strerror(errno));
 	}
 
 	/*
@@ -1141,8 +1117,7 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 	    ((rc != (sizeof(*vlabel) - sizeof(vlabel->volkey))) &&
 	     !g.cdl_format)) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing volume label "
-			    "(%d).\n", prog_name, rc);
+		error("Error writing volume label (%d).", rc);
 	}
 
 	if (g.verbosity > 0)
@@ -1154,17 +1129,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 	rc = lseek(fd, label_position, SEEK_SET);
 	if (rc != label_position) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek command to %i failed "
-			    "(%s).\n", prog_name, label_position,
-			    strerror(errno));
+		error("lseek command to %i failed: %s", label_position, strerror(errno));
 	}
 
 	/* write VTOC FMT4 DSCB */
 	rc = write(fd, &f4, sizeof(format4_label_t));
 	if (rc != sizeof(format4_label_t)) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT4 label "
-			    "(%d).\n", prog_name, rc);
+		error("Error writing FMT4 label (%d).", rc);
 	}
 
 	label_position += blksize;
@@ -1172,16 +1144,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 	rc = lseek(fd, label_position, SEEK_SET);
 	if (rc != label_position) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek to %i failed (%s).\n",
-			    prog_name, label_position, strerror(errno));
+		error("lseek to %i failed: %s", label_position, strerror(errno));
 	}
 
 	/* write VTOC FMT5 DSCB */
 	rc = write(fd, &f5, sizeof(format5_label_t));
 	if (rc != sizeof(format5_label_t)) {
 		close(fd);
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT5 label "
-			    "(%d).\n", prog_name, rc);
+		error("Error writing FMT5 label (%d).", rc);
 	}
 
 	if ((cylinders * heads) > BIG_DISK_SIZE) {
@@ -1190,17 +1160,14 @@ static void dasdfmt_write_labels(volume_label_t *vlabel,
 		rc = lseek(fd, label_position, SEEK_SET);
 		if (rc != label_position) {
 			close(fd);
-			ERRMSG_EXIT(EXIT_FAILURE, "%s: lseek to %i failed "
-				    "(%s).\n", prog_name, label_position,
-				    strerror(errno));
+			error("lseek to %i failed: %s", label_position, strerror(errno));
 		}
 
 		/* write VTOC FMT 7 DSCB (only on big disks) */
 		rc = write(fd, &f7, sizeof(format7_label_t));
 		if (rc != sizeof(format7_label_t)) {
 			close(fd);
-			ERRMSG_EXIT(EXIT_FAILURE, "%s: Error writing FMT7 "
-				    "label (rc=%d).\n", prog_name, rc);
+			error("Error writing FMT7 label (rc=%d).", rc);
 		}
 	}
 
@@ -1235,8 +1202,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
 
 	if (cdata.result) {
 		evaluate_format_error(&cdata, heads);
-		ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform a "
-			    "clean format.\n");
+		error("Use --mode=full to perform a clean format.");
 	}
 
 	printf("Expansion mode active. Searching for starting position...\n");
@@ -1257,8 +1223,7 @@ static void dasdfmt_find_start(unsigned int cylinders, unsigned int heads,
 	}
 
 	if (first == 2 && cdata.blksize == format_params->blksize)
-		ERRMSG_EXIT(EXIT_FAILURE,
-			    "No unformatted part found, aborting.\n");
+		error("No unformatted part found, aborting.");
 
 	printf("Done. Unformatted part starts at track %d.\n", first);
 
@@ -1280,10 +1245,8 @@ static void dasdfmt_release_space(void)
 
 	printf("Releasing space for the entire device...\n");
 	err = dasd_release_space(g.dev_node, &r);
-	if (err) {
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: Could not release space (%s)\n",
-			    prog_name, strerror(err));
-	}
+	if (err)
+		error("Could not release space: %s", strerror(err));
 }
 
 static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int heads,
@@ -1312,9 +1275,7 @@ static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int head
 
 	err = dasd_format_disk(filedes, &temp);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: (invalidate first track) IOCTL "
-			    "BIODASDFMT failed. (%s)\n", prog_name,
-			    strerror(err));
+		error("(invalidate first track) IOCTL BIODASDFMT failed: %s", strerror(err));
 
 	/* except track 0 from standard formatting procss */
 	p->start_unit = 1;
@@ -1331,9 +1292,7 @@ static void dasdfmt_prepare_and_format(unsigned int cylinders, unsigned int head
 
 	err = dasd_format_disk(filedes, &temp);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: (re-validate first track) IOCTL"
-			    " BIODASDFMT failed (%s)\n", prog_name,
-			    strerror(err));
+		error("(re-validate first track) IOCTL BIODASDFMT failed: %s", strerror(err));
 
 	if (g.verbosity > 0)
 		printf("Re-accessing the device...\n");
@@ -1398,8 +1357,7 @@ static void dasdfmt_quick_format(unsigned int cylinders, unsigned int heads,
 		}
 		if (cdata.result) {
 			evaluate_format_error(&cdata, heads);
-			ERRMSG_EXIT(EXIT_FAILURE, "Use --mode=full to perform "
-				    "a clean format.\n");
+			error("Use --mode=full to perform a clean format.");
 		} else {
 			printf("Done. Disk seems fine.\n");
 		}
@@ -1414,8 +1372,7 @@ static void dasdfmt_quick_format(unsigned int cylinders, unsigned int heads,
 	/* Now do the actual formatting of our first two tracks */
 	err = dasd_format_disk(filedes, p);
 	if (err != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl to format the device "
-			    "failed. (%s)\n", prog_name, strerror(err));
+		error("the ioctl to format the device failed: %s", strerror(err));
 
 	/* Re-Enable the device so that we can continue working with it */
 	disk_enable();
@@ -1448,11 +1405,11 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
 	count = dasd_get_host_access_count(g.dev_node);
 	if (g.force_host) {
 		if (count > 1) {
-			ERRMSG_EXIT(EXIT_FAILURE,
-				    "\n%s: Disk %s is online on OS instances in %d different LPARs.\n"
-				    "Note: Your installation might include z/VM systems that are configured to\n"
-				    "automatically vary on disks, regardless of whether they are subsequently used.\n\n",
-				    prog_name, g.dev_path, count);
+			printf("\n");
+			warnx("Disk %s is online on OS instances in %d different LPARs.",
+			      g.dev_path, count);
+			warnx("Note: Your installation might include z/VM systems that are configured to");
+			error("automatically vary on disks, regardless of whether they are subsequently used.\n");
 		} else if (count < 0) {
 			ERRMSG("\nHosts access information not available for disk %s.\n\n",
 			       g.dev_path);
@@ -1516,10 +1473,9 @@ static void do_format_dasd(volume_label_t *vlabel, format_data_t *p,
 static void eval_format_mode(void)
 {
 	if (!g.force && g.mode_specified && g.ese && mode == EXPAND) {
-		ERRMSG_EXIT(EXIT_FAILURE,
-			    "WARNING: The specified device is thin-provisioned\n"
-			    "Format mode 'expand' is not feasible.\n"
-			    "Use --mode=full or --mode=quick to perform a clean format\n");
+		warnx("WARNING: The specified device is thin-provisioned");
+		warnx("Format mode 'expand' is not feasible.");
+		error("Use --mode=full or --mode=quick to perform a clean format");
 	}
 
 	if (!g.mode_specified)
@@ -1571,17 +1527,15 @@ int main(int argc, char *argv[])
 			if (strcasecmp(optarg, "cdl") == 0) {
 				format_params.intensity |= DASD_FMT_INT_COMPAT;
 				if (g.writenolabel) {
-					printf("WARNING: using the cdl "
-					       "format without writing a "
-					       "label doesn't make much "
-					       "sense!\n");
-					exit(1);
+					error("WARNING: using the cdl "
+					      "format without writing a "
+					      "label doesn't make much "
+					      "sense!");
 				}
 			} else if (strcasecmp(optarg, "ldl") == 0) {
 				format_params.intensity &= ~DASD_FMT_INT_COMPAT;
 			} else {
-				printf("%s is not a valid option!\n", optarg);
-				exit(1);
+				error("%s is not a valid option!", optarg);
 			}
 			g.layout_specified = 1;
 			break;
@@ -1627,10 +1581,9 @@ int main(int argc, char *argv[])
 			break;
 		case 'L':
 			if (format_params.intensity & DASD_FMT_INT_COMPAT) {
-				printf("WARNING: using the cdl format "
-				       "without writing a label doesn't "
-				       "make much sense!\n");
-				exit(1);
+				error("WARNING: using the cdl format "
+				      "without writing a label doesn't "
+				      "make much sense!");
 			}
 			g.writenolabel = 1;
 			break;
@@ -1656,11 +1609,9 @@ int main(int argc, char *argv[])
 			else if (strcasecmp(optarg, "expand") == 0)
 				mode = EXPAND;
 			else
-				ERRMSG_EXIT(EXIT_FAILURE,
-					    "%s: The specified mode '%s' is "
-					    "invalid. Consult the man page for "
-					    "more information.\n",
-					    prog_name, optarg);
+				error("The specified mode '%s' is invalid. "
+				      "Consult the man page for more information.",
+				      optarg);
 			g.mode_specified = 1;
 			break;
 		case OPT_NODISCARD:
@@ -1673,8 +1624,7 @@ int main(int argc, char *argv[])
 			/* End of options string - start of devices list */
 			break;
 		default:
-			ERRMSG_EXIT(EXIT_MISUSE, "Try '%s --help' for more"
-				    " information.\n", prog_name);
+			error("Try '%s --help' for more information.");
 		}
 
 		if (rc == -1)
@@ -1691,9 +1641,7 @@ int main(int argc, char *argv[])
 	if (g.reqsize_specified) {
 		PARSE_PARAM_INTO(reqsize, reqsize_param_str, 10, "requestsize");
 		if (reqsize < 1 || reqsize > 255)
-			ERRMSG_EXIT(EXIT_FAILURE,
-				    "invalid requestsize %d specified\n",
-				    reqsize);
+			error("invalid requestsize %d specified", reqsize);
 	} else {
 		reqsize = DEFAULT_REQUESTSIZE;
 	}
@@ -1705,9 +1653,7 @@ int main(int argc, char *argv[])
 
 	rc = dasd_get_info(g.dev_node, &g.dasd_info);
 	if (rc != 0)
-		ERRMSG_EXIT(EXIT_FAILURE, "%s: the ioctl call to retrieve "
-			    "device information failed (%s).\n",
-			    prog_name, strerror(rc));
+		error("the ioctl call to retrieve device information failed: %s", strerror(rc));
 
 	g.ese = dasd_sys_ese(g.dev_node);
 	eval_format_mode();
@@ -1722,28 +1668,21 @@ int main(int argc, char *argv[])
 	}
 
 	if (g.keep_volser) {
-		if (g.labelspec) {
-			ERRMSG_EXIT(EXIT_MISUSE, "%s: The -k and -l options "
-				    "are mutually exclusive\n", prog_name);
-		}
-		if (!(format_params.intensity & DASD_FMT_INT_COMPAT)) {
-			printf("WARNING: VOLSER cannot be kept "
-			       "when using the ldl format!\n");
-			exit(1);
-		}
+		if (g.labelspec)
+			error("The -k and -l options are mutually exclusive");
+		if (!(format_params.intensity & DASD_FMT_INT_COMPAT))
+			error("WARNING: VOLSER cannot be kept when using the ldl format!");
 
 		if (dasdfmt_get_volser(old_volser) == 0)
 			vtoc_volume_label_set_volser(&vlabel, old_volser);
 		else
-			ERRMSG_EXIT(EXIT_FAILURE,
-				    "%s: VOLSER not found on device %s\n",
-				    prog_name, g.dev_path);
+			error("VOLSER not found on device %s", g.dev_path);
 	}
 
 	check_disk();
 
 	if (check_param(str, ERR_LENGTH, &format_params) < 0)
-		ERRMSG_EXIT(EXIT_MISUSE, "%s: %s\n", prog_name, str);
+		error("%s", str);
 
 	set_geo(&cylinders, &heads);
 	set_label(&vlabel, &format_params, cylinders);
-- 
2.26.2

openSUSE Build Service is sponsored by