2020-05-01 16:57:10 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
add support for enabling/desabling service
diff --git a/README b/README index 0107aab..3b11e02 100644 --- a/README +++ b/README @@ -32,7 +32,8 @@ Interaction --- ------ q Quit isv j/k Move selection cursor down/up - 1/2 Send USR1/USR2 signal to service + SPACE Enable/disable selected service (del/add "down" file) + 1/2 Send USR1/USR2 signal to selected service <UPPER> Send command to selected service (e.g. 'U' -> 'up') That is, to control a service, we first move the cursor (<>) using j/k to diff --git a/isv.c b/isv.c index 3ef62b1..b48f165 100644 --- a/isv.c +++ b/isv.c @@ -184,6 +184,23 @@ send_command(const char *base_dir, int nservices, int selection, char cmd) close(fd); } +void +toggle_service(const char *base_dir, int nservices, int selection) +{ + struct service *service; + + (void) nservices; + if (selection == -1) + return; + service = &services[selection]; + chdir(base_dir); + chdir(service->name); + if (service->active) + creat("down", 0644); + else + unlink("down"); +} + int main(int argc, char *argv[]) { @@ -269,6 +286,9 @@ main(int argc, char *argv[]) case '1': case '2': /* non-alphabetic cmds can't be uppercase */ send_command(base_dir, nservices, selection, byte); break; + case ' ': + toggle_service(base_dir, nservices, selection); + break; default: got_cmd = false; }