fiss

Friedel's Initialization and Service Supervision
Log | Files | Refs | LICENSE

commit 3844e39022e96f526c2c69167a9e0f781ea3cb37
parent 690ec0ef91b5ed2ae5be5c5119e29b18464168e9
Author: Friedel Schön <[email protected]>
Date:   Wed, 17 May 2023 13:03:07 +0200

fixing status-updates

Diffstat:
Msrc/register.c | 6+++---
Msrc/runit.c | 1+
Msrc/serialize.c | 20++++++++++----------
Msrc/supervise.c | 4++++
4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/register.c b/src/register.c @@ -36,6 +36,9 @@ service_t* service_register(int dir, const char* name, bool is_log_service) { strncpy(s->name, name, sizeof(s->name)); service_init_status(s); + + s->status_change = time(NULL); + service_update_status(s); } struct stat st; @@ -72,8 +75,5 @@ service_t* service_register(int dir, const char* name, bool is_log_service) { s->restart_file = S_ONCE; } - s->status_change = time(NULL); - service_update_status(s); - return s; } diff --git a/src/runit.c b/src/runit.c @@ -52,6 +52,7 @@ void service_init_status(service_t* s) { } void service_update_status(service_t* s) { + printf("update: %s\n", s->name); #if SV_RUNIT_COMPAT != 0 int fd; if ((fd = openat(s->dir, "supervise/status", O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) { diff --git a/src/serialize.c b/src/serialize.c @@ -77,7 +77,7 @@ void service_store_runit(service_t* s, uint8_t* buffer) { // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ // | TAI SECONDS | TAIA NANO | PID |PS|WU|TR|ST| // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - // TAI SECONDS = unix seconds + 4611686018427387914ULL + // TAI SECONDS = unix seconds + 4611686018427387914ULL (lower endian!) // TAIA NANO = unix nanoseconds (nulled-out as fiss don't store them) // PID = current pid // PS = is paused (int boolean) @@ -85,7 +85,7 @@ void service_store_runit(service_t* s, uint8_t* buffer) { // TR = was terminated (int boolean) // ST = state (0 is down, 1 is running, 2 is finishing) - uint64_t tai = s->status_change + 4611686018427387914ULL; + uint64_t tai = (uint64_t) s->status_change + 4611686018427387914ULL; int runit_state; switch (s->state) { case STATE_INACTIVE: @@ -106,14 +106,14 @@ void service_store_runit(service_t* s, uint8_t* buffer) { break; } - buffer[0] = (tai >> 0) & 0xff; - buffer[1] = (tai >> 8) & 0xff; - buffer[2] = (tai >> 16) & 0xff; - buffer[3] = (tai >> 24) & 0xff; - buffer[4] = (tai >> 32) & 0xff; - buffer[5] = (tai >> 40) & 0xff; - buffer[6] = (tai >> 48) & 0xff; - buffer[7] = (tai >> 56) & 0xff; + buffer[0] = (tai >> 56) & 0xff; + buffer[1] = (tai >> 48) & 0xff; + buffer[2] = (tai >> 40) & 0xff; + buffer[3] = (tai >> 32) & 0xff; + buffer[4] = (tai >> 24) & 0xff; + buffer[5] = (tai >> 16) & 0xff; + buffer[6] = (tai >> 8) & 0xff; + buffer[7] = (tai >> 0) & 0xff; buffer[8] = 0; // not implemented buffer[9] = 0; // not implemented buffer[10] = 0; // not implemented diff --git a/src/supervise.c b/src/supervise.c @@ -65,10 +65,14 @@ static void check_services(void) { if (service_need_restart(s)) { if (s->state == STATE_INACTIVE) { service_start(s, NULL); + s->status_change = time(NULL); + service_update_status(s); } } else { if (s->state != STATE_INACTIVE) { service_stop(s, NULL); + s->status_change = time(NULL); + service_update_status(s); } } }