File s390-tools-sles15sp2-dasdfmt-Set-prog_name-to-last-component-of-program-n.patch of Package s390-tools.19914

From da4fdeeb82ce22b166f4d39ca0f566ee55dcf08e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B6ppner?= <hoeppner@linux.ibm.com>
Date: Sun, 25 Oct 2020 20:16:00 +0100
Subject: [PATCH] dasdfmt: Set prog_name to last component of program name
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In the process of switching to glibc defined error functions it becomes
apparent that self-defined error functions that do special things are
not in line with the output of the glibc functions.

To address this, set the prog_name variable to the last component of the
program name (stored in argv[0]) and guarantee a uniform error output.

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

diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c
index 94f5d91..a424f3c 100644
--- a/dasdfmt/dasdfmt.c
+++ b/dasdfmt/dasdfmt.c
@@ -1481,6 +1481,20 @@ static void eval_format_mode(void)
 		mode = g.ese ? QUICK : FULL;
 }
 
+/*
+ * Set prog_name to the last component of the program name to be in line with
+ * err() and warn() function (and its derivatives).
+ */
+static void set_prog_name(char *s)
+{
+	char *p = strrchr(s, '/');
+
+	if (p == NULL)
+		prog_name = s;
+	else
+		prog_name = p + 1;
+}
+
 int main(int argc, char *argv[])
 {
 	volume_label_t vlabel;
@@ -1502,7 +1516,7 @@ int main(int argc, char *argv[])
 	signal(SIGQUIT, program_interrupt_signal);
 
 	/******************* initialization ********************/
-	prog_name = argv[0];
+	set_prog_name(argv[0]);
 
 	util_prg_init(&prg);
 	util_opt_init(opt_vec, NULL);
-- 
2.26.2

openSUSE Build Service is sponsored by