From: Steve Guminski Date: Wed, 12 Jul 2017 11:35:12 +0000 (-0400) Subject: LU-5170 lfs: Standardize error messages in set_time() X-Git-Tag: 2.11.52~57 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F34%2F28234%2F3;p=fs%2Flustre-release.git 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 --- 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;