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)));
#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 */
/*
- * 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
}
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;
}
int
-path_getnum(const char *path, ...)
+path_read_s32(const char *path, ...)
{
FILE *fd;
va_list ap;
}
int
-path_writestr(const char *str, const char *path, ...)
+path_write_str(const char *str, const char *path, ...)
{
int fd, result;
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;
}
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;
#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));
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;
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);
"(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 {
{
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;
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"));
}
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;
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
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)
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 */
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
/* 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;
}
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);
}
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)
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
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
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"))
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);
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);
/* 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);
}
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':