From b1870a11d2050d192921af34ac3b0eeac66bd215 Mon Sep 17 00:00:00 2001 From: Steve Guminski Date: Wed, 12 Jul 2017 07:35:12 -0400 Subject: [PATCH] LU-5170 lfs: Standardize error messages in set_time() Error and warning messages in set_time() are updated to a standard format. Messages are prefixed with the name of the utility and the command that caused the error. User-provided values are delimited with single quotes. Test-Parameters: trivial Signed-off-by: Steve Guminski Change-Id: I4b5efa394b49f4a0af0c073ad707c2b8c6faf6b0 Reviewed-on: https://review.whamcloud.com/28234 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Nunez --- lustre/utils/lfs.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4dcb8f3..e05b3fb 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -3233,28 +3233,38 @@ static int lfs_poollist(int argc, char **argv) static int set_time(time_t *time, time_t *set, char *str) { - time_t t; - int res = 0; - - if (str[0] == '+') - res = 1; - else if (str[0] == '-') - res = -1; - - if (res) - str++; - - t = strtol(str, NULL, 0); - if (*time < t * 24 * 60 * 60) { - if (res) - str--; - fprintf(stderr, "Wrong time '%s' is specified.\n", str); - return INT_MAX; - } + time_t t; + int res = 0; + char *endptr; - *set = *time - t * 24 * 60 * 60; - return res; + if (str[0] == '+') + res = 1; + else if (str[0] == '-') + res = -1; + + if (res) + str++; + + t = strtol(str, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr, + "%s find: bad time '%s': %s\n", + progname, str, strerror(EINVAL)); + return INT_MAX; + } + if (*time < t * 24 * 60 * 60) { + if (res != 0) + str--; + fprintf(stderr, + "%s find: bad time '%s': too large\n", + progname, str); + return INT_MAX; + } + + *set = *time - t * 24 * 60 * 60; + return res; } + static int name2uid(unsigned int *id, const char *name) { struct passwd *passwd; -- 1.8.3.1