]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: cleanup set_config_console_buffer_size()
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 14:52:16 +0000 (15:52 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 8 Dec 2020 15:49:40 +0000 (16:49 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/string_utils.c

index f65ac70836d4b53e8c9f711091e568e17da7fbd0..05464a24910c4bd686eef04eb8a1a516fc631828 100644 (file)
@@ -2350,29 +2350,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;
 
index 3d0d31a6c6e9f75ee1a9346c95454f041954ccca..9918299fb8e65c153090f8119867fc12aea0a376 100644 (file)
@@ -907,21 +907,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++;
@@ -934,8 +934,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;
@@ -949,11 +949,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;