]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: stats: remove non portable getline() usage
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 17 May 2024 12:50:12 +0000 (14:50 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 17 May 2024 12:53:19 +0000 (14:53 +0200)
getline() was used to read stats-file. However, this function is not
portable and may cause build issue on some systems. Replace it by
standard fgets().

No need to backport.

src/stats-file.c

index 76168919dbb82cde73225403a4e37ff31bdf1ee3..1a77e3182b84e171b87b3443d2617bcfeef8c72c 100644 (file)
@@ -351,8 +351,6 @@ void apply_stats_file(void)
        FILE *file;
        struct ist istline;
        char *line = NULL;
-       ssize_t len;
-       size_t alloc_len;
        int linenum;
 
        if (!global.stats_file)
@@ -370,15 +368,20 @@ void apply_stats_file(void)
                goto out;
        }
 
+       line = malloc(sizeof(char) * LINESIZE);
+       if (!line) {
+               ha_warning("config: Can't load stats file: line alloc error.\n");
+               goto out;
+       }
+
        linenum = 0;
        domain = STFILE_DOMAIN_UNSET;
        while (1) {
-               len = getline(&line, &alloc_len, file);
-               if (len < 0)
+               if (!fgets(line, LINESIZE, file))
                        break;
 
                ++linenum;
-               istline = iststrip(ist2(line, len));
+               istline = iststrip(ist(line));
                if (!istlen(istline))
                        continue;