Whamcloud - gitweb
LU-930 utils: fix 'lfs find' error message 40/35740/2
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 8 Aug 2019 22:07:26 +0000 (16:07 -0600)
committerOleg Drokin <green@whamcloud.com>
Thu, 15 Aug 2019 07:55:53 +0000 (07:55 +0000)
Print out the actual filename supplied to "lfs find" rather than the
last argument in the list.  Otherwise we get error messages like:

    $ lfs find /myth/tmp -name fasdfasf -size 12
    error: find failed for 12.

Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I56eef89ab3c04b193f1c7dec3852c4038b3ebbe5
Reviewed-on: https://review.whamcloud.com/35740
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.super@gmail.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/lfs.c

index d261f4d..40be0b3 100644 (file)
@@ -3979,15 +3979,16 @@ static int lfs_find(int argc, char **argv)
 /* getstripe { .val = 'v', .name = "verbose",  .has_arg = no_argument }, */
 /* getstripe { .val = 'y', .name = "yaml",     .has_arg = no_argument }, */
        { .name = NULL } };
-        int pathstart = -1;
-        int pathend = -1;
-        int neg_opt = 0;
-        time_t *xtime;
-        int *xsign;
-        int isoption;
-        char *endptr;
+       int pathstart = -1;
+       int pathend = -1;
+       int pathbad = -1;
+       int neg_opt = 0;
+       time_t *xtime;
+       int *xsign;
+       int isoption;
+       char *endptr;
 
-        time(&t);
+       time(&t);
 
        /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
        while ((c = getopt_long_only(argc, argv,
@@ -4535,13 +4536,16 @@ err_free:
 
        do {
                rc = llapi_find(argv[pathstart], &param);
-               if (rc != 0 && ret == 0)
+               if (rc && !ret) {
                        ret = rc;
+                       pathbad = pathstart;
+               }
        } while (++pathstart < pathend);
 
-        if (ret)
-                fprintf(stderr, "error: %s failed for %s.\n",
-                        argv[0], argv[optind - 1]);
+       if (ret)
+               fprintf(stderr, "%s: failed for '%s': %s\n",
+                       progname, argv[pathbad], strerror(-rc));
+
 err:
        if (param.fp_obd_uuid && param.fp_num_alloc_obds)
                free(param.fp_obd_uuid);