]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsmem: make lsmem to check for the nodes more robust
authorzhangyao <zhangyao108@huawei.com>
Thu, 4 Jul 2024 08:28:51 +0000 (16:28 +0800)
committerzhangyao <zhangyao108@huawei.com>
Thu, 4 Jul 2024 08:39:10 +0000 (16:39 +0800)
See #3110.

sys-utils/lsmem.c

index 3b5ca19a01c21032f69eeaf480f4df27a9ffbe37..7c1be8e83041bc78e614e7b0f4223a347ff1675f 100644 (file)
@@ -485,6 +485,7 @@ static int memory_block_filter(const struct dirent *de)
 static void read_basic_info(struct lsmem *lsmem)
 {
        char dir[PATH_MAX];
+       int i = 0;
 
        if (ul_path_access(lsmem->sysmem, F_OK, "block_size_bytes") != 0)
                errx(EXIT_FAILURE, _("This system does not support memory blocks"));
@@ -495,8 +496,14 @@ static void read_basic_info(struct lsmem *lsmem)
        if (lsmem->ndirs <= 0)
                err(EXIT_FAILURE, _("Failed to read %s"), dir);
 
-       if (memory_block_get_node(lsmem, lsmem->dirs[0]->d_name) != -1)
-               lsmem->have_nodes = 1;
+       for (i = 0; i < lsmem->ndirs; i++)
+       {
+               if (memory_block_get_node(lsmem, lsmem->dirs[i]->d_name) != -1)
+               {
+                       lsmem->have_nodes = 1;
+                       break;
+               }
+       }
 
        /* The valid_zones sysmem attribute was introduced with kernel 3.18 */
        if (ul_path_access(lsmem->sysmem, F_OK, "memory0/valid_zones") == 0)