module/mem: cleanup poll-interval

* man page: spell out ‘milliseconds’
* use a ‘static const’ variable for min_poll_interval, instead of a
  macro
This commit is contained in:
Daniel Eklöf 2022-12-22 11:47:15 +01:00
parent a18296a179
commit ac8e45c331
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 10 additions and 8 deletions

View file

@ -33,7 +33,7 @@ mem - This module provides the memory usage
| poll-interval
: string
: no
: Refresh interval of the memory usage stats in ms
: Refresh interval of the memory usage stats in milliseconds
(default=500). Cannot be less then 500ms.
# EXAMPLES

View file

@ -12,13 +12,14 @@
#define LOG_MODULE "mem"
#define LOG_ENABLE_DBG 0
#define SMALLEST_INTERVAL 500
#include "../bar/bar.h"
#include "../config-verify.h"
#include "../config.h"
#include "../log.h"
#include "../plugin.h"
static const long min_poll_interval = 500;
struct private
{
struct particle *label;
@ -155,18 +156,19 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
const struct yml_node *c = yml_get_value(node, "content");
return mem_new(
interval == NULL ? SMALLEST_INTERVAL : yml_value_as_int(interval),
interval == NULL ? min_poll_interval : yml_value_as_int(interval),
conf_to_particle(c, inherited));
}
static bool
conf_verify_interval(keychain_t *chain, const struct yml_node *node)
conf_verify_poll_interval(keychain_t *chain, const struct yml_node *node)
{
if (!conf_verify_unsigned(chain, node))
return false;
if (yml_value_as_int(node) < SMALLEST_INTERVAL) {
LOG_ERR("%s: interval value cannot be less than %d ms", conf_err_prefix(chain, node), SMALLEST_INTERVAL);
if (yml_value_as_int(node) < min_poll_interval) {
LOG_ERR("%s: interval value cannot be less than %ldms",
conf_err_prefix(chain, node), min_poll_interval);
return false;
}
@ -177,7 +179,7 @@ static bool
verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"poll-interval", false, &conf_verify_interval},
{"poll-interval", false, &conf_verify_poll_interval},
MODULE_COMMON_ATTRS,
};