aboutsummaryrefslogtreecommitdiffstats
path: root/coreupdown.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-02-24 20:53:42 +0100
committerMattias Andrée <maandree@kth.se>2024-02-24 20:53:42 +0100
commit18694f67a119a1a2c0f44fc4014c3df9c3fa2b8b (patch)
tree0b9d9866d3d6b07e31b497dbf6057c08f6256ef8 /coreupdown.c
parentAdd support for SIGHUP (diff)
downloadcoreupdown-18694f67a119a1a2c0f44fc4014c3df9c3fa2b8b.tar.gz
coreupdown-18694f67a119a1a2c0f44fc4014c3df9c3fa2b8b.tar.bz2
coreupdown-18694f67a119a1a2c0f44fc4014c3df9c3fa2b8b.tar.xz
Prepare for configurability
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--coreupdown.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/coreupdown.c b/coreupdown.c
index 70015ec..ab3d4e9 100644
--- a/coreupdown.c
+++ b/coreupdown.c
@@ -242,8 +242,22 @@ daemon_main(int argc, char **argv, int orig_argc, char **orig_argv, int reexeced
size_t cpus;
int up_time = 0, down_time = 0, cooldown = 0, err;
struct timespec interval, rem;
+ uintmax_t coreup_threshold_cpu, coredown_threshold_cpu;
+ int coreup_threshold_time, coredown_threshold_time;
+ int coreup_cooldown, coredown_cooldown;
+ time_t daemon_interval_sec;
+ long int daemon_interval_nsec;
restart:
+ coreup_threshold_cpu = COREUP_THRESHOLD_CPU;
+ coreup_threshold_time = COREUP_THRESHOLD_TIME;
+ coreup_cooldown = COREUP_COOLDOWN;
+ coredown_threshold_cpu = COREDOWN_THRESHOLD_CPU;
+ coredown_threshold_time = COREDOWN_THRESHOLD_TIME;
+ coredown_cooldown = COREDOWN_COOLDOWN;
+ daemon_interval_sec = DAEMON_INTERVAL_SEC;
+ daemon_interval_nsec = DAEMON_INTERVAL_NSEC;
+
if (reexeced)
argv[0] = "coreupdownd";
@@ -266,8 +280,8 @@ restart:
if (signal(SIGHUP, sighup_handler) == SIG_ERR)
fprintf(stderr, "%s: signal SIGHUP <function>: %s\n", argv0, strerror(errno));
- interval.tv_sec = DAEMON_INTERVAL_SEC;
- interval.tv_nsec = DAEMON_INTERVAL_NSEC;
+ interval.tv_sec = daemon_interval_sec;
+ interval.tv_nsec = daemon_interval_nsec;
if (getusage(&total, &idle, &cpus))
return 1;
@@ -303,17 +317,17 @@ restart:
continue;
}
- if (cpus == 1 && 100 * (total - idle) > COREUP_THRESHOLD_CPU * total) {
+ if (cpus == 1 && 100 * (total - idle) > coreup_threshold_cpu * total) {
down_time = 0;
- if (up_time++ >= COREUP_THRESHOLD_TIME) {
- cooldown = COREUP_COOLDOWN;
+ if (up_time++ >= coreup_threshold_time) {
+ cooldown = coreup_cooldown;
coreup();
up_time = 0;
}
- } else if (cpus > 1 && 100 * (total - idle) < COREDOWN_THRESHOLD_CPU * total * cpus) {
+ } else if (cpus > 1 && 100 * (total - idle) < coredown_threshold_cpu * total * cpus) {
up_time = 0;
- if (down_time++ >= COREDOWN_THRESHOLD_TIME) {
- cooldown = COREDOWN_COOLDOWN;
+ if (down_time++ >= coredown_threshold_time) {
+ cooldown = coredown_cooldown;
coredown();
down_time = 0;
}