confile: cleanup set_config_console_buffer_size()

parent 14605013
......@@ -2222,29 +2222,26 @@ static int set_config_console_buffer_size(const char *key, const char *value,
}
ret = parse_byte_size_string(value, &size);
if (ret < 0)
return -1;
if (ret)
return ret;
if (size < 0)
return -EINVAL;
return ret_errno(EINVAL);
/* must be at least a page size */
pgsz = lxc_getpagesize();
if ((uint64_t)size < pgsz) {
NOTICE("Requested ringbuffer size for the console is %" PRId64
" but must be at least %" PRId64
" bytes. Setting ringbuffer size to %" PRId64 " bytes",
NOTICE("Requested ringbuffer size for the console is %" PRId64 " but must be at least %" PRId64 " bytes. Setting ringbuffer size to %" PRId64 " bytes",
size, pgsz, pgsz);
size = pgsz;
}
buffer_size = lxc_find_next_power2((uint64_t)size);
if (buffer_size == 0)
return -EINVAL;
return ret_errno(EINVAL);
if (buffer_size != size)
NOTICE("Passed size was not a power of 2. Rounding log size to "
"next power of two: %" PRIu64 " bytes", buffer_size);
NOTICE("Passed size was not a power of 2. Rounding log size to next power of two: %" PRIu64 " bytes", buffer_size);
lxc_conf->console.buffer_size = buffer_size;
......
......@@ -862,21 +862,21 @@ int parse_byte_size_string(const char *s, int64_t *converted)
char suffix[3] = {0};
if (!s || !strcmp(s, ""))
return -EINVAL;
return ret_errno(EINVAL);
end = stpncpy(dup, s, sizeof(dup) - 1);
if (*end != '\0')
return -EINVAL;
return ret_errno(EINVAL);
if (isdigit(*(end - 1)))
suffix_len = 0;
else if (isalpha(*(end - 1)))
suffix_len = 1;
else
return -EINVAL;
return ret_errno(EINVAL);
if (suffix_len > 0 && (end - 2) == dup && !isdigit(*(end - 2)))
return -EINVAL;
return ret_errno(EINVAL);
if (suffix_len > 0 && isalpha(*(end - 2)))
suffix_len++;
......@@ -889,8 +889,8 @@ int parse_byte_size_string(const char *s, int64_t *converted)
dup[lxc_char_right_gc(dup, strlen(dup))] = '\0';
ret = lxc_safe_long_long(dup, &conv);
if (ret < 0)
return -ret;
if (ret)
return ret;
if (suffix_len != 2) {
*converted = conv;
......@@ -904,11 +904,11 @@ int parse_byte_size_string(const char *s, int64_t *converted)
else if (strcasecmp(suffix, "GB") == 0)
mltpl = 1024 * 1024 * 1024;
else
return -EINVAL;
return ret_errno(EINVAL);
overflow = conv * mltpl;
if (conv != 0 && (overflow / conv) != mltpl)
return -ERANGE;
return ret_errno(ERANGE);
*converted = overflow;
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment