From 93672d5557d1d273ef9bc9c8bf8a3789a848f954 Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Fri, 13 Oct 2023 08:46:59 -0700 Subject: [PATCH] Use new aws_byte_buf_init_from_file_with_size_hint() function, so don't waste 4KB on these short strings. --- source/linux/system_info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/linux/system_info.c b/source/linux/system_info.c index bdfd2a99b..2d9c5a120 100644 --- a/source/linux/system_info.c +++ b/source/linux/system_info.c @@ -6,10 +6,14 @@ #include int aws_system_environment_load_platform_impl(struct aws_system_environment *env) { - aws_byte_buf_init_from_file(&env->virtualization_vendor, env->allocator, "/sys/devices/virtual/dmi/id/sys_vendor"); + /* provide size_hint when reading "special files", since some platforms mis-report these files' size as 4KB */ + aws_byte_buf_init_from_file_with_size_hint( + &env->virtualization_vendor, env->allocator, "/sys/devices/virtual/dmi/id/sys_vendor", 32 /*size_hint*/); + /* whether this one works depends on if this is a sysfs filesystem. If it fails, it will just be empty * and these APIs are a best effort at the moment. We can add fallbacks as the loaders get more complicated. */ - aws_byte_buf_init_from_file(&env->product_name, env->allocator, "/sys/devices/virtual/dmi/id/product_name"); + aws_byte_buf_init_from_file_with_size_hint( + &env->product_name, env->allocator, "/sys/devices/virtual/dmi/id/product_name", 32 /*size_hint*/); return AWS_OP_SUCCESS; }