summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/path.h12
-rw-r--r--lib/path.c18
-rw-r--r--sys-utils/chcpu.c22
-rw-r--r--sys-utils/lscpu.c35
4 files changed, 45 insertions, 42 deletions
diff --git a/include/path.h b/include/path.h
index 3dfd51794..cefaaa0a4 100644
--- a/include/path.h
+++ b/include/path.h
@@ -5,11 +5,11 @@
extern FILE *path_fopen(const char *mode, int exit_on_err, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
-extern void path_getstr(char *result, size_t len, const char *path, ...)
+extern void path_read_str(char *result, size_t len, const char *path, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
-extern int path_writestr(const char *str, const char *path, ...)
+extern int path_write_str(const char *str, const char *path, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
-extern int path_getnum(const char *path, ...)
+extern int path_read_s32(const char *path, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
extern int path_exist(const char *path, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
@@ -17,11 +17,11 @@ extern int path_exist(const char *path, ...)
#ifdef HAVE_CPU_SET_T
# include "cpuset.h"
-extern cpu_set_t *path_cpuset(int, const char *path, ...)
+extern cpu_set_t *path_read_cpuset(int, const char *path, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
-extern cpu_set_t *path_cpulist(int, const char *path, ...)
+extern cpu_set_t *path_read_cpulist(int, const char *path, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
-extern void path_setprefix(const char *);
+extern void path_set_prefix(const char *);
#endif /* HAVE_CPU_SET_T */
#endif /* UTIL_LINUX_PATH_H */
diff --git a/lib/path.c b/lib/path.c
index 404eeeb24..f4118ccd3 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -1,10 +1,12 @@
/*
- * Simple functions to access files.
+ * Simple functions to access files, paths maybe be globally prefixed by a
+ * global prefix to read data from alternative destination (e.g. /proc dump for
+ * regression tests).
*
* Taken from lscpu.c
*
* Copyright (C) 2008 Cai Qian <qcai@redhat.com>
- * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2008-2012 Karel Zak <kzak@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -84,7 +86,7 @@ path_fopen(const char *mode, int exit_on_error, const char *path, ...)
}
void
-path_getstr(char *result, size_t len, const char *path, ...)
+path_read_str(char *result, size_t len, const char *path, ...)
{
FILE *fd;
va_list ap;
@@ -103,7 +105,7 @@ path_getstr(char *result, size_t len, const char *path, ...)
}
int
-path_getnum(const char *path, ...)
+path_read_s32(const char *path, ...)
{
FILE *fd;
va_list ap;
@@ -124,7 +126,7 @@ path_getnum(const char *path, ...)
}
int
-path_writestr(const char *str, const char *path, ...)
+path_write_str(const char *str, const char *path, ...)
{
int fd, result;
va_list ap;
@@ -185,7 +187,7 @@ path_cpuparse(int maxcpus, int islist, const char *path, va_list ap)
}
cpu_set_t *
-path_cpuset(int maxcpus, const char *path, ...)
+path_read_cpuset(int maxcpus, const char *path, ...)
{
va_list ap;
cpu_set_t *set;
@@ -198,7 +200,7 @@ path_cpuset(int maxcpus, const char *path, ...)
}
cpu_set_t *
-path_cpulist(int maxcpus, const char *path, ...)
+path_read_cpulist(int maxcpus, const char *path, ...)
{
va_list ap;
cpu_set_t *set;
@@ -213,7 +215,7 @@ path_cpulist(int maxcpus, const char *path, ...)
#endif /* HAVE_CPU_SET_T */
void
-path_setprefix(const char *prefix)
+path_set_prefix(const char *prefix)
{
prefixlen = strlen(prefix);
strncpy(pathbuf, prefix, sizeof(pathbuf));
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index 0209fe9bf..da6f65887 100644
--- a/sys-utils/chcpu.c
+++ b/sys-utils/chcpu.c
@@ -83,7 +83,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
printf(_("CPU %d is not hot pluggable\n"), cpu);
continue;
}
- online = path_getnum(_PATH_SYS_CPU "/cpu%d/online", cpu);
+ online = path_read_s32(_PATH_SYS_CPU "/cpu%d/online", cpu);
if ((online == 1) && (enable == 1)) {
printf(_("CPU %d is already enabled\n"), cpu);
continue;
@@ -93,9 +93,9 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
continue;
}
if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu))
- configured = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", cpu);
+ configured = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
if (enable) {
- rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
+ rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
if ((rc == -1) && (configured == 0))
printf(_("CPU %d enable failed "
"(CPU is deconfigured)\n"), cpu);
@@ -109,7 +109,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
"(last enabled CPU)\n"), cpu);
continue;
}
- rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
+ rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
if (rc == -1)
printf(_("CPU %d disable failed (%m)\n"), cpu);
else {
@@ -126,7 +126,7 @@ static int cpu_rescan(void)
{
if (!path_exist(_PATH_SYS_CPU_RESCAN))
errx(EXIT_FAILURE, _("This system does not support rescanning of CPUs"));
- if (path_writestr("1", _PATH_SYS_CPU_RESCAN) == -1)
+ if (path_write_str("1", _PATH_SYS_CPU_RESCAN) == -1)
err(EXIT_FAILURE, _("Failed to trigger rescan of CPUs"));
printf(_("Triggered rescan of CPUs\n"));
return EXIT_SUCCESS;
@@ -138,11 +138,11 @@ static int cpu_set_dispatch(int mode)
errx(EXIT_FAILURE, _("This system does not support setting "
"the dispatching mode of CPUs"));
if (mode == 0) {
- if (path_writestr("0", _PATH_SYS_CPU_DISPATCH) == -1)
+ if (path_write_str("0", _PATH_SYS_CPU_DISPATCH) == -1)
err(EXIT_FAILURE, _("Failed to set horizontal dispatch mode"));
printf(_("Successfully set horizontal dispatching mode\n"));
} else {
- if (path_writestr("1", _PATH_SYS_CPU_DISPATCH) == -1)
+ if (path_write_str("1", _PATH_SYS_CPU_DISPATCH) == -1)
err(EXIT_FAILURE, _("Failed to set vertical dispatch mode"));
printf(_("Successfully set vertical dispatching mode\n"));
}
@@ -165,7 +165,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
printf(_("CPU %d is not configurable\n"), cpu);
continue;
}
- current = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", cpu);
+ current = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
if ((current == 1) && (configure == 1)) {
printf(_("CPU %d is already configured\n"), cpu);
continue;
@@ -181,13 +181,13 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
continue;
}
if (configure) {
- rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
+ rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
if (rc == -1)
printf(_("CPU %d configure failed (%m)\n"), cpu);
else
printf(_("CPU %d configured\n"), cpu);
} else {
- rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
+ rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
if (rc == -1)
printf(_("CPU %d deconfigure failed (%m)\n"), cpu);
else
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
if (maxcpus < 1)
errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting"));
if (path_exist(_PATH_SYS_CPU_ONLINE))
- onlinecpus = path_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
+ onlinecpus = path_read_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
setsize = CPU_ALLOC_SIZE(maxcpus);
cpu_set = CPU_ALLOC(maxcpus);
if (!cpu_set)
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index a111561dc..a840548c0 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -384,7 +384,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
if (path_exist(_PATH_SYS_SYSTEM "/cpu/kernel_max"))
/* note that kernel_max is maximum index [NR_CPUS-1] */
- maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1;
+ maxcpus = path_read_s32(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1;
else if (mod->system == SYSTEM_LIVE)
/* the root is '/' so we are working with data from the current kernel */
@@ -398,7 +398,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
setsize = CPU_ALLOC_SIZE(maxcpus);
if (path_exist(_PATH_SYS_SYSTEM "/cpu/possible")) {
- cpu_set_t *tmp = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/possible");
+ cpu_set_t *tmp = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/possible");
desc->ncpuspos = CPU_COUNT_S(setsize, tmp);
cpuset_free(tmp);
} else
@@ -408,19 +408,20 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
/* get mask for present CPUs */
if (path_exist(_PATH_SYS_SYSTEM "/cpu/present")) {
- desc->present = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/present");
+ desc->present = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/present");
desc->ncpus = CPU_COUNT_S(setsize, desc->present);
}
/* get mask for online CPUs */
if (path_exist(_PATH_SYS_SYSTEM "/cpu/online")) {
- desc->online = path_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/online");
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
+ desc->online = path_read_cpulist(maxcpus, _PATH_SYS_SYSTEM "/cpu/online");
desc->nthreads = CPU_COUNT_S(setsize, desc->online);
}
/* get dispatching mode */
if (path_exist(_PATH_SYS_SYSTEM "/cpu/dispatching"))
- desc->dispatching = path_getnum(_PATH_SYS_SYSTEM "/cpu/dispatching");
+ desc->dispatching = path_read_s32(_PATH_SYS_SYSTEM "/cpu/dispatching");
else
desc->dispatching = -1;
}
@@ -611,13 +612,13 @@ read_topology(struct lscpu_desc *desc, int num)
if (!path_exist(_PATH_SYS_CPU "/cpu%d/topology/thread_siblings", num))
return;
- thread_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+ thread_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
"/cpu%d/topology/thread_siblings", num);
- core_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+ core_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
"/cpu%d/topology/core_siblings", num);
book_siblings = NULL;
if (path_exist(_PATH_SYS_CPU "/cpu%d/topology/book_siblings", num)) {
- book_siblings = path_cpuset(maxcpus, _PATH_SYS_CPU
+ book_siblings = path_read_cpuset(maxcpus, _PATH_SYS_CPU
"/cpu%d/topology/book_siblings", num);
}
@@ -683,7 +684,7 @@ read_polarization(struct lscpu_desc *desc, int num)
return;
if (!desc->polarization)
desc->polarization = xcalloc(desc->ncpuspos, sizeof(int));
- path_getstr(mode, sizeof(mode), _PATH_SYS_CPU "/cpu%d/polarization", num);
+ path_read_str(mode, sizeof(mode), _PATH_SYS_CPU "/cpu%d/polarization", num);
if (strncmp(mode, "vertical:low", sizeof(mode)) == 0)
desc->polarization[num] = POLAR_VLOW;
else if (strncmp(mode, "vertical:medium", sizeof(mode)) == 0)
@@ -703,7 +704,7 @@ read_address(struct lscpu_desc *desc, int num)
return;
if (!desc->addresses)
desc->addresses = xcalloc(desc->ncpuspos, sizeof(int));
- desc->addresses[num] = path_getnum(_PATH_SYS_CPU "/cpu%d/address", num);
+ desc->addresses[num] = path_read_s32(_PATH_SYS_CPU "/cpu%d/address", num);
}
static void
@@ -713,7 +714,7 @@ read_configured(struct lscpu_desc *desc, int num)
return;
if (!desc->configured)
desc->configured = xcalloc(desc->ncpuspos, sizeof(int));
- desc->configured[num] = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", num);
+ desc->configured[num] = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", num);
}
static int
@@ -752,7 +753,7 @@ read_cache(struct lscpu_desc *desc, int num)
int type, level;
/* cache type */
- path_getstr(buf, sizeof(buf),
+ path_read_str(buf, sizeof(buf),
_PATH_SYS_CPU "/cpu%d/cache/index%d/type",
num, i);
if (!strcmp(buf, "Data"))
@@ -763,7 +764,7 @@ read_cache(struct lscpu_desc *desc, int num)
type = 0;
/* cache level */
- level = path_getnum(_PATH_SYS_CPU "/cpu%d/cache/index%d/level",
+ level = path_read_s32(_PATH_SYS_CPU "/cpu%d/cache/index%d/level",
num, i);
if (type)
snprintf(buf, sizeof(buf), "L%d%c", level, type);
@@ -773,14 +774,14 @@ read_cache(struct lscpu_desc *desc, int num)
ca->name = xstrdup(buf);
/* cache size */
- path_getstr(buf, sizeof(buf),
+ path_read_str(buf, sizeof(buf),
_PATH_SYS_CPU "/cpu%d/cache/index%d/size",
num, i);
ca->size = xstrdup(buf);
}
/* information about how CPUs share different caches */
- map = path_cpuset(maxcpus,
+ map = path_read_cpuset(maxcpus,
_PATH_SYS_CPU "/cpu%d/cache/index%d/shared_cpu_map",
num, i);
@@ -806,7 +807,7 @@ read_nodes(struct lscpu_desc *desc)
/* information about how nodes share different CPUs */
for (i = 0; i < desc->nnodes; i++)
- desc->nodemaps[i] = path_cpuset(maxcpus,
+ desc->nodemaps[i] = path_read_cpuset(maxcpus,
_PATH_SYS_SYSTEM "/node/node%d/cpumap",
i);
}
@@ -1338,7 +1339,7 @@ int main(int argc, char *argv[])
mod->mode = c == 'p' ? OUTPUT_PARSABLE : OUTPUT_READABLE;
break;
case 's':
- path_setprefix(optarg);
+ path_set_prefix(optarg);
mod->system = SYSTEM_SNAPSHOT;
break;
case 'x':