diff options
Diffstat (limited to 'libglusterfs/src/common-utils.c')
| -rw-r--r-- | libglusterfs/src/common-utils.c | 110 | 
1 files changed, 107 insertions, 3 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 2b700af4e..4af1b4454 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -787,12 +787,44 @@ gf_string2time (const char *str, uint32_t *n)          if (errno == 0)                  errno = old_errno; -        if (!((tail[0] == '\0') || +        if (((tail[0] == '\0') ||                ((tail[0] == 's') && (tail[1] == '\0')) ||                ((tail[0] == 's') && (tail[1] == 'e') &&  	       (tail[2] == 'c') && (tail[3] == '\0')))) +               goto out; + +        else if (((tail[0] == 'm') && (tail[1] == '\0')) || +                 ((tail[0] == 'm') && (tail[1] == 'i') && +                  (tail[2] == 'n') && (tail[3] == '\0'))) { +                value = value * GF_MINUTE_IN_SECONDS; +                goto out; +        } + +        else if (((tail[0] == 'h') && (tail[1] == '\0')) || +                 ((tail[0] == 'h') && (tail[1] == 'r') && +	         (tail[2] == '\0'))) { +                value = value * GF_HOUR_IN_SECONDS; +                goto out; +        } + +        else if (((tail[0] == 'd') && (tail[1] == '\0')) || +                 ((tail[0] == 'd') && (tail[1] == 'a') && +	         (tail[2] == 'y') && (tail[3] == 's') && +                 (tail[4] == '\0'))) { +                value = value * GF_DAY_IN_SECONDS; +                goto out; +        } + +        else if (((tail[0] == 'w') && (tail[1] == '\0')) || +                 ((tail[0] == 'w') && (tail[1] == 'k') && +	         (tail[2] == '\0'))) { +                value = value * GF_WEEK_IN_SECONDS; +                goto out; +        } else {                  return -1; +        } +out:          *n = value;          return 0; @@ -2294,6 +2326,9 @@ gf_canonicalize_path (char *path)          if (!path || *path != '/')                  goto out; +        if (!strcmp (path, "/")) +                return 0; +          tmppath = gf_strdup (path);          if (!tmppath)                  goto out; @@ -2818,7 +2853,6 @@ out:  } -  /* Sets log file path from user provided arguments */  int  gf_set_log_file_path (cmd_args_t *cmd_args) @@ -2956,6 +2990,76 @@ backtrace_symbols(void *const *trace, size_t len)  	}  	return ptr; -}  +}  #undef BELOW  #endif /* __NetBSD__ */ + +/* TODO: extract common code from gf_get_soft_limit and gf_get_hard_limit into a + * function + */ +int +gf_get_soft_limit (char *limit, char **soft_limit) +{ +        int   colon_count   = 0; +        int   i             = 0; +        int   len           = 0; +        char *sl            = NULL; + +        len = strlen (limit); +        for (i = 0; i < len; i++) { +                if (limit[i] == ':') +                        colon_count++; +                if (colon_count == 2) +                        break; +        } + +        if (colon_count != 2) { +                gf_log ("common-utils", GF_LOG_DEBUG, "Soft-limit absent"); +                return 0; +        } + +        sl = GF_CALLOC (len - i, sizeof (char), gf_common_mt_char); +        if (!sl) +                return -1; +        strncpy (sl, &limit[i+1], len - i - 1); +        *soft_limit = sl; + +        return 1; +} + +int +gf_get_hard_limit (char *limit, char **hard_limit) +{ +        int    i                 = 0; +        int    hlbegin           = 0; +        int    len               = 0; +        char  *hl                = NULL; + +        len = strlen (limit); + +        for (i = 0; i < len; i++) { +                if (limit[i] == ':') +                        break; +        } + +        if (i == len) { +                gf_log ("common-utils", GF_LOG_ERROR, "Hard limit not found"); +                return -1; +        } + +        hlbegin = i + 1; +        i++; + +        while ((limit[i] != '\0') && (limit[i] != ':')) { +                i++; +        } + +        hl = GF_CALLOC (i - hlbegin + 1, sizeof (char), gf_common_mt_char); +        if (!hl) +                return -1; + +        strncpy (hl, &limit[hlbegin], i - hlbegin); +        *hard_limit = hl; + +        return 0; +}  | 
