fiss

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

commit 95c323e1f0d74de15a32bc5970d3f9ed0641665a
parent 5d22e2cfe2fe7027b32614e7d68f084e468d2199
Author: Friedel Schon <[email protected]>
Date:   Mon, 10 Apr 2023 11:55:21 +0200

fixing commands behavior

Diffstat:
Msrc/command_handler.c | 36++++++++++++++++++++++++++----------
Msrc/restart.c | 4++--
2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/command_handler.c b/src/command_handler.c @@ -20,13 +20,17 @@ int service_handle_command(service_t* s, sv_command_t command, unsigned char ext case S_START: if (s == NULL) return -ENOSV; - if (extra > 2) { + if (extra > 1) { return -EBEXT; } - if (extra == 1 || extra == 2) { // pin - changed = !s->restart_manual; + if (s->state != STATE_INACTIVE) + return 0; + + if (extra == 1) { // pin + changed = s->restart_manual != S_RESTART; s->restart_manual = S_RESTART; } else { + changed = s->restart_manual != S_ONCE; s->restart_manual = S_ONCE; } if (extra == 0 || extra == 1) @@ -40,12 +44,18 @@ int service_handle_command(service_t* s, sv_command_t command, unsigned char ext case S_STOP: if (s == NULL) return -ENOSV; - if (extra > 2) { + if (extra > 1) { return -EBEXT; } - if (extra == 1 || extra == 2) { // pin - changed = s->restart_manual; + if (s->state == STATE_INACTIVE) + return 0; + + if (extra == 1) { // pin + changed = s->restart_manual != S_NONE; s->restart_manual = S_NONE; + } else { + changed = s->restart_manual != S_ONCE; + s->restart_manual = S_ONCE; } if (extra == 0 || extra == 1) service_stop(s, &changed); @@ -60,23 +70,30 @@ int service_handle_command(service_t* s, sv_command_t command, unsigned char ext return -ENOSV; service_send(s, extra); + response[0] = s; return 1; case S_PAUSE: if (s == NULL) return -ENOSV; + if (s->state == STATE_INACTIVE || s->paused) + return 0; s->paused = true; service_send(s, SIGSTOP); + response[0] = s; return 1; case S_RESUME: if (s == NULL) return -ENOSV; + if (s->state == STATE_INACTIVE || !s->paused) + return 0; s->paused = false; service_send(s, SIGCONT); + response[0] = s; return 1; @@ -84,12 +101,11 @@ int service_handle_command(service_t* s, sv_command_t command, unsigned char ext if (s == NULL) return -ENOSV; - s->state = STATE_INACTIVE; - service_start(s, &changed); - - if (!changed) + if (s->state != STATE_DEAD) return 0; + s->state = STATE_INACTIVE; + response[0] = s; return 1; diff --git a/src/restart.c b/src/restart.c @@ -30,7 +30,7 @@ static void do_finish(service_t* s) { print_error("cannot execute finish process"); _exit(1); } - } else if (s->fail_count > SV_FAIL_MAX) { + } else if (s->fail_count == SV_FAIL_MAX) { s->state = STATE_DEAD; printf(":: %s died\n", s->name); } else { @@ -80,7 +80,7 @@ void service_check_state(service_t* s, bool signaled, int return_code) { break; case STATE_FINISHING: - if (s->fail_count > SV_FAIL_MAX) { + if (s->fail_count == SV_FAIL_MAX) { s->state = STATE_DEAD; printf(":: %s died\n", s->name); } else {