This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwfl: Use actual file names in parse_opt failure cases.


When handling ARGP_KEY_SUCCESS the failure handling code would use 'arg'
as failure string. But 'arg' would be NULL in such cases leading to failure
messages like: "cannot open '(null)': No such file or directory".
Use opt->e and opt->core explicitly to show file names that caused failure.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog  |    6 ++++++
 libdwfl/argp-std.c |   10 +++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 11d599b..1311dea 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-10  Mark Wielaard  <mjw@redhat.com>
+
+	* argp-std.c (parse_opt): Use opt->core and opt->e explicitly in
+	failure messages When handling ARGP_KEY_SUCCESS because arg will
+	not have been set.
+
 2013-01-30  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* linux-proc-maps.c: Include system.h.
diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 7584054..e54f720 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -210,7 +210,6 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	  {
 	    FILE *f = fopen (arg, "r");
 	    if (f == NULL)
-	    nofile:
 	      {
 		int code = errno;
 		argp_failure (state, EXIT_FAILURE, code,
@@ -298,7 +297,12 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	  {
 	    int fd = open64 (opt->core, O_RDONLY);
 	    if (fd < 0)
-	      goto nofile;
+	      {
+		int code = errno;
+		argp_failure (state, EXIT_FAILURE, code,
+			      "cannot open '%s'", opt->core);
+		return code;
+	      }
 
 	    Elf *core;
 	    Dwfl_Error error = __libdw_open_file (&fd, &core, true, false);
@@ -333,7 +337,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	else if (opt->e)
 	  {
 	    if (INTUSE(dwfl_report_offline) (dwfl, "", opt->e, -1) == NULL)
-	      return fail (dwfl, -1, arg);
+	      return fail (dwfl, -1, opt->e);
 	  }
 
 	/* One of the three flavors has done dwfl_begin and some reporting
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]