libdwfl: Use actual file names in parse_opt failure cases.
authorMark Wielaard <mjw@redhat.com>
Sun, 10 Feb 2013 14:07:33 +0000 (15:07 +0100)
committerMark Wielaard <mjw@redhat.com>
Sun, 10 Feb 2013 14:07:33 +0000 (15:07 +0100)
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
libdwfl/argp-std.c

index 11d599b..1311dea 100644 (file)
@@ -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.
index 7584054..e54f720 100644 (file)
@@ -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