From bc500536b6dd5f2f5fba61286bd81ecccb7d959d Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 8 Aug 2019 16:07:26 -0600 Subject: [PATCH] LU-930 utils: fix 'lfs find' error message 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 Change-Id: I56eef89ab3c04b193f1c7dec3852c4038b3ebbe5 Reviewed-on: https://review.whamcloud.com/35740 Tested-by: jenkins Reviewed-by: Arshad Hussain Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/utils/lfs.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index d261f4d..40be0b3 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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], ¶m); - 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); -- 1.8.3.1