From c11d09ac816776b8d459bd3f5e3b0aebc96c3d1d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 11 Jul 2023 15:12:18 +0200 Subject: [PATCH] MINOR: cfgparse: use read_line_from_trash() to read from /sys It's easier to use this function now to natively support variable fields in the file's path. This also removes read_file_from_trash() that was only used here and was static. --- src/cfgparse.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index b25812b3f..4ace5afdb 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2587,25 +2587,6 @@ static void parse_cpumap(char *cpumap_str, struct hap_cpuset *cpu_set) } while (comma); } -/* Read the first line of a file from into the trash buffer. - * Returns 0 on success, otherwise non-zero. - */ -static int read_file_to_trash(const char *path) -{ - FILE *file; - int ret = 1; - - file = fopen(path, "r"); - if (file) { - if (fgets(trash.area, trash.size, file)) - ret = 0; - - fclose(file); - } - - return ret; -} - /* Inspect the cpu topology of the machine on startup. If a multi-socket * machine is detected, try to bind on the first node with active cpu. This is * done to prevent an impact on the overall performance when the topology of @@ -2625,7 +2606,6 @@ static int numa_detect_topology() struct hap_cpuset active_cpus, node_cpu_set; const char *parse_cpu_set_args[2]; - char cpumap_path[PATH_MAX]; char *err = NULL; int grp, thr; @@ -2639,7 +2619,7 @@ static int numa_detect_topology() goto free_scandir_entries; /* 2. read and parse the list of currently online cpu */ - if (read_file_to_trash(NUMA_DETECT_SYSTEM_SYSFS_PATH"/cpu/online")) { + if (read_line_to_trash("%s/cpu/online", NUMA_DETECT_SYSTEM_SYSFS_PATH)) { ha_notice("Cannot read online CPUs list, will not try to refine binding\n"); goto free_scandir_entries; } @@ -2657,10 +2637,7 @@ static int numa_detect_topology() const char *node = node_dirlist[node_dirlist_size]->d_name; ha_cpuset_zero(&node_cpu_set); - snprintf(cpumap_path, PATH_MAX, "%s/node/%s/cpumap", - NUMA_DETECT_SYSTEM_SYSFS_PATH, node); - - if (read_file_to_trash(cpumap_path)) { + if (read_line_to_trash("%s/node/%s/cpumap", NUMA_DETECT_SYSTEM_SYSFS_PATH, node)) { ha_notice("Cannot read CPUs list of '%s', will not select them to refine binding\n", node); free(node_dirlist[node_dirlist_size]); continue;