confile: cleanup set_config_console_buffer_size()

parent 9a26e4af
...@@ -2350,29 +2350,26 @@ static int set_config_console_buffer_size(const char *key, const char *value, ...@@ -2350,29 +2350,26 @@ static int set_config_console_buffer_size(const char *key, const char *value,
} }
ret = parse_byte_size_string(value, &size); ret = parse_byte_size_string(value, &size);
if (ret < 0) if (ret)
return -1; return ret;
if (size < 0) if (size < 0)
return -EINVAL; return ret_errno(EINVAL);
/* must be at least a page size */ /* must be at least a page size */
pgsz = lxc_getpagesize(); pgsz = lxc_getpagesize();
if ((uint64_t)size < pgsz) { if ((uint64_t)size < pgsz) {
NOTICE("Requested ringbuffer size for the console is %" PRId64 NOTICE("Requested ringbuffer size for the console is %" PRId64 " but must be at least %" PRId64 " bytes. Setting ringbuffer size to %" PRId64 " bytes",
" but must be at least %" PRId64
" bytes. Setting ringbuffer size to %" PRId64 " bytes",
size, pgsz, pgsz); size, pgsz, pgsz);
size = pgsz; size = pgsz;
} }
buffer_size = lxc_find_next_power2((uint64_t)size); buffer_size = lxc_find_next_power2((uint64_t)size);
if (buffer_size == 0) if (buffer_size == 0)
return -EINVAL; return ret_errno(EINVAL);
if (buffer_size != size) if (buffer_size != size)
NOTICE("Passed size was not a power of 2. Rounding log size to " NOTICE("Passed size was not a power of 2. Rounding log size to next power of two: %" PRIu64 " bytes", buffer_size);
"next power of two: %" PRIu64 " bytes", buffer_size);
lxc_conf->console.buffer_size = buffer_size; lxc_conf->console.buffer_size = buffer_size;
......
...@@ -907,21 +907,21 @@ int parse_byte_size_string(const char *s, int64_t *converted) ...@@ -907,21 +907,21 @@ int parse_byte_size_string(const char *s, int64_t *converted)
char suffix[3] = {0}; char suffix[3] = {0};
if (!s || !strcmp(s, "")) if (!s || !strcmp(s, ""))
return -EINVAL; return ret_errno(EINVAL);
end = stpncpy(dup, s, sizeof(dup) - 1); end = stpncpy(dup, s, sizeof(dup) - 1);
if (*end != '\0') if (*end != '\0')
return -EINVAL; return ret_errno(EINVAL);
if (isdigit(*(end - 1))) if (isdigit(*(end - 1)))
suffix_len = 0; suffix_len = 0;
else if (isalpha(*(end - 1))) else if (isalpha(*(end - 1)))
suffix_len = 1; suffix_len = 1;
else else
return -EINVAL; return ret_errno(EINVAL);
if (suffix_len > 0 && (end - 2) == dup && !isdigit(*(end - 2))) if (suffix_len > 0 && (end - 2) == dup && !isdigit(*(end - 2)))
return -EINVAL; return ret_errno(EINVAL);
if (suffix_len > 0 && isalpha(*(end - 2))) if (suffix_len > 0 && isalpha(*(end - 2)))
suffix_len++; suffix_len++;
...@@ -934,8 +934,8 @@ int parse_byte_size_string(const char *s, int64_t *converted) ...@@ -934,8 +934,8 @@ int parse_byte_size_string(const char *s, int64_t *converted)
dup[lxc_char_right_gc(dup, strlen(dup))] = '\0'; dup[lxc_char_right_gc(dup, strlen(dup))] = '\0';
ret = lxc_safe_long_long(dup, &conv); ret = lxc_safe_long_long(dup, &conv);
if (ret < 0) if (ret)
return -ret; return ret;
if (suffix_len != 2) { if (suffix_len != 2) {
*converted = conv; *converted = conv;
...@@ -949,11 +949,11 @@ int parse_byte_size_string(const char *s, int64_t *converted) ...@@ -949,11 +949,11 @@ int parse_byte_size_string(const char *s, int64_t *converted)
else if (strcasecmp(suffix, "GB") == 0) else if (strcasecmp(suffix, "GB") == 0)
mltpl = 1024 * 1024 * 1024; mltpl = 1024 * 1024 * 1024;
else else
return -EINVAL; return ret_errno(EINVAL);
overflow = conv * mltpl; overflow = conv * mltpl;
if (conv != 0 && (overflow / conv) != mltpl) if (conv != 0 && (overflow / conv) != mltpl)
return -ERANGE; return ret_errno(ERANGE);
*converted = overflow; *converted = overflow;
return 0; 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