Whamcloud - gitweb
LU-5170 lfs: Standardize error messages in set_time() 34/28234/3
authorSteve Guminski <stephenx.guminski@intel.com>
Wed, 12 Jul 2017 11:35:12 +0000 (07:35 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 2 May 2018 02:22:15 +0000 (02:22 +0000)
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 <stephenx.guminski@intel.com>
Change-Id: I4b5efa394b49f4a0af0c073ad707c2b8c6faf6b0
Reviewed-on: https://review.whamcloud.com/28234
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Nunez <james.a.nunez@intel.com>
lustre/utils/lfs.c

index 4dcb8f3..e05b3fb 100644 (file)
@@ -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;