projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
exec: fix a race condition when setting environment variables
[collectd.git]
/
src
/
intel_rdt.c
diff --git
a/src/intel_rdt.c
b/src/intel_rdt.c
index
422d05d
..
99c3ed0
100644
(file)
--- a/
src/intel_rdt.c
+++ b/
src/intel_rdt.c
@@
-105,7
+105,7
@@
static void rdt_submit_derive(const char *cgroup, const char *type,
vl.values_len = 1;
sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin));
vl.values_len = 1;
sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin));
- snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup);
+ s
s
nprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup);
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
@@
-121,7
+121,7
@@
static void rdt_submit_gauge(const char *cgroup, const char *type,
vl.values_len = 1;
sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin));
vl.values_len = 1;
sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin));
- snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup);
+ s
s
nprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup);
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
sstrncpy(vl.type, type, sizeof(vl.type));
if (type_instance)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
@@
-144,8
+144,8
@@
static void rdt_dump_cgroups(void) {
memset(cores, 0, sizeof(cores));
for (size_t j = 0; j < cgroup->num_cores; j++) {
memset(cores, 0, sizeof(cores));
for (size_t j = 0; j < cgroup->num_cores; j++) {
- snprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d",
- cgroup->cores[j]);
+ s
s
nprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d",
+
cgroup->cores[j]);
}
DEBUG(RDT_PLUGIN ": group[%zu]:", i);
}
DEBUG(RDT_PLUGIN ": group[%zu]:", i);
@@
-171,8
+171,8
@@
static void rdt_dump_ngroups(void) {
for (size_t i = 0; i < g_rdt->num_ngroups; i++) {
memset(names, 0, sizeof(names));
for (size_t j = 0; j < g_rdt->ngroups[i].num_names; j++)
for (size_t i = 0; i < g_rdt->num_ngroups; i++) {
memset(names, 0, sizeof(names));
for (size_t j = 0; j < g_rdt->ngroups[i].num_names; j++)
- snprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s",
- g_rdt->ngroups[i].names[j]);
+ s
s
nprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s",
+
g_rdt->ngroups[i].names[j]);
DEBUG(RDT_PLUGIN ": group[%d]:", (int)i);
DEBUG(RDT_PLUGIN ": description: %s", g_rdt->ngroups[i].desc);
DEBUG(RDT_PLUGIN ": group[%d]:", (int)i);
DEBUG(RDT_PLUGIN ": description: %s", g_rdt->ngroups[i].desc);
@@
-249,8
+249,8
@@
static void rdt_dump_pids_data(void) {
for (size_t j = 0; j < g_rdt->ngroups[i].num_names; ++j) {
pids_list_t *list = g_rdt->ngroups[i].proc_pids[j]->curr;
for (size_t k = 0; k < list->size; k++)
for (size_t j = 0; j < g_rdt->ngroups[i].num_names; ++j) {
pids_list_t *list = g_rdt->ngroups[i].proc_pids[j]->curr;
for (size_t k = 0; k < list->size; k++)
- snprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u",
- list->pids[k]);
+ s
s
nprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u",
+
list->pids[k]);
}
DEBUG(RDT_PLUGIN ": [%s] %s", g_rdt->ngroups[i].desc, pids);
}
}
DEBUG(RDT_PLUGIN ": [%s] %s", g_rdt->ngroups[i].desc, pids);
}
@@
-325,8
+325,8
@@
static int strlisttoarray(char *str_list, char ***names, size_t *names_num) {
continue;
if ((isdupstr((const char **)*names, *names_num, token))) {
continue;
if ((isdupstr((const char **)*names, *names_num, token))) {
- ERROR(RDT_PLUGIN ": Duplicated process name \'%s\'
in group \'%s\'",
- token, str_list);
+ ERROR(RDT_PLUGIN ": Duplicated process name \'%s\'
", token);
+
return -EINVAL;
} else {
if (0 != strarray_add(names, names_num, token)) {
return -EINVAL;
} else {
if (0 != strarray_add(names, names_num, token)) {
@@
-475,6
+475,8
@@
static void rdt_free_ngroups(rdt_ctx_t *rdt) {
}
if (rdt->proc_pids)
sfree(rdt->proc_pids);
}
if (rdt->proc_pids)
sfree(rdt->proc_pids);
+
+ rdt->num_ngroups = 0;
}
/*
}
/*
@@
-849,9
+851,9
@@
static void rdt_init_pids_monitoring() {
}
/* update global proc_pids table */
}
/* update global proc_pids table */
- proc_pids_t **proc_pids =
realloc(g_rdt->proc_pids,
-
(g_rdt->num_proc_pids + ng->num_names) *
-
sizeof(*g_rdt->proc_pids));
+ proc_pids_t **proc_pids =
+
realloc(g_rdt->proc_pids,
(g_rdt->num_proc_pids + ng->num_names) *
+ sizeof(*g_rdt->proc_pids));
if (NULL == proc_pids) {
ERROR(RDT_PLUGIN ": Alloc error\n");
continue;
if (NULL == proc_pids) {
ERROR(RDT_PLUGIN ": Alloc error\n");
continue;
@@
-882,7
+884,7
@@
static void rdt_init_pids_monitoring() {
#endif /* LIBPQOS2 */
/*
* NAME
#endif /* LIBPQOS2 */
/*
* NAME
- * rdt_free_
n
groups
+ * rdt_free_
c
groups
*
* DESCRIPTION
* Function to deallocate memory allocated for core groups.
*
* DESCRIPTION
* Function to deallocate memory allocated for core groups.
@@
-892,6
+894,7
@@
static void rdt_free_cgroups(void) {
for (int i = 0; i < RDT_MAX_CORES; i++) {
sfree(g_rdt->pcgroups[i]);
}
for (int i = 0; i < RDT_MAX_CORES; i++) {
sfree(g_rdt->pcgroups[i]);
}
+ g_rdt->cores.num_cgroups = 0;
}
static int rdt_default_cgroups(void) {
}
static int rdt_default_cgroups(void) {
@@
-919,7
+922,7
@@
static int rdt_default_cgroups(void) {
cgroup->num_cores = 1;
cgroup->cores[0] = i;
cgroup->num_cores = 1;
cgroup->cores[0] = i;
- snprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore);
+ s
s
nprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore);
cgroup->desc = strdup(desc);
if (cgroup->desc == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group description");
cgroup->desc = strdup(desc);
if (cgroup->desc == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group description");
@@
-1101,21
+1104,27
@@
static int rdt_config(oconfig_item_t *ci) {
reports a failure in configuration and
aborts
*/
reports a failure in configuration and
aborts
*/
- return
(0)
;
+ return
0
;
}
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
if (strncasecmp("Cores", child->key, (size_t)strlen("Cores")) == 0) {
}
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
if (strncasecmp("Cores", child->key, (size_t)strlen("Cores")) == 0) {
- if (rdt_config_cgroups(child) != 0) {
+ if (g_rdt->cores.num_cgroups > 0) {
+ ERROR(RDT_PLUGIN
+ ": Configuration parameter \"%s\" can be used only once.",
+ child->key);
+ g_state = CONFIGURATION_ERROR;
+ } else if (rdt_config_cgroups(child) != 0)
g_state = CONFIGURATION_ERROR;
g_state = CONFIGURATION_ERROR;
+
+ if (g_state == CONFIGURATION_ERROR)
/* if we return -1 at this point collectd
reports a failure in configuration and
aborts
*/
/* if we return -1 at this point collectd
reports a failure in configuration and
aborts
*/
- return (0);
- }
+ return 0;
#if COLLECT_DEBUG
rdt_dump_cgroups();
#if COLLECT_DEBUG
rdt_dump_cgroups();
@@
-1128,21
+1137,24
@@
static int rdt_config(oconfig_item_t *ci) {
"Resctrl monitoring is needed for PIDs monitoring.",
child->key);
g_state = CONFIGURATION_ERROR;
"Resctrl monitoring is needed for PIDs monitoring.",
child->key);
g_state = CONFIGURATION_ERROR;
- /* if we return -1 at this point collectd
- reports a failure in configuration and
- aborts
- */
- return 0;
}
}
- if (rdt_config_ngroups(g_rdt, child) != 0) {
+ else if (g_rdt->num_ngroups > 0) {
+ ERROR(RDT_PLUGIN
+ ": Configuration parameter \"%s\" can be used only once.",
+ child->key);
g_state = CONFIGURATION_ERROR;
g_state = CONFIGURATION_ERROR;
+ }
+
+ else if (rdt_config_ngroups(g_rdt, child) != 0)
+ g_state = CONFIGURATION_ERROR;
+
+ if (g_state == CONFIGURATION_ERROR)
/* if we return -1 at this point collectd
reports a failure in configuration and
aborts
*/
return 0;
/* if we return -1 at this point collectd
reports a failure in configuration and
aborts
*/
return 0;
- }
#if COLLECT_DEBUG
rdt_dump_ngroups();
#if COLLECT_DEBUG
rdt_dump_ngroups();
@@
-1249,8
+1261,17
@@
static void rdt_init_cores_monitoring() {
static int rdt_init(void) {
static int rdt_init(void) {
- if (g_state == CONFIGURATION_ERROR)
+ if (g_state == CONFIGURATION_ERROR) {
+ if (g_rdt != NULL) {
+ if (g_rdt->cores.num_cgroups > 0)
+ rdt_free_cgroups();
+#ifdef LIBPQOS2
+ if (g_rdt->num_ngroups > 0)
+ rdt_free_ngroups(g_rdt);
+#endif
+ }
return -1;
return -1;
+ }
int rdt_preinint_result = rdt_preinit();
if (rdt_preinint_result != 0)
int rdt_preinint_result = rdt_preinit();
if (rdt_preinint_result != 0)