From ca9627e70852f6b2e835660df870fe3ab405882d Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sun, 1 Sep 2019 00:00:32 +0200 Subject: Initial import --- app-misc/sshsleeper/files/sshsleeper.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app-misc/sshsleeper/files/sshsleeper.c (limited to 'app-misc/sshsleeper/files') diff --git a/app-misc/sshsleeper/files/sshsleeper.c b/app-misc/sshsleeper/files/sshsleeper.c new file mode 100644 index 0000000..a88c4bc --- /dev/null +++ b/app-misc/sshsleeper/files/sshsleeper.c @@ -0,0 +1,38 @@ +#include +#include +#include + +#define BUFSIZE 128 + +int main() { + int i; + unsigned int val; + int slpsec = 3600; + + char buf[BUFSIZE+1]; + + FILE *f = fopen("/etc/sshsleeper.conf", "r"); + if (f) { + while (fgets(buf, BUFSIZE, f)) { + // check if we are facing a long string + if (strlen(buf) >= BUFSIZE) { + while ((fgets(buf, BUFSIZE, f))&&(strlen(buf) >= BUFSIZE)); + } + + for (i = 0; buf[i] == ' '; i++); + if (strncmp(buf, "duration", 8)) continue; + for (i += 8; buf[i] == ' '; i++); + if (sscanf(buf + i, "%u", &val) != 1) continue; + + if (val > 0) { + slpsec = val; + break; + } + + } + fclose(f); + } + + printf("Sleeping for %u seconds\n", slpsec); + sleep(slpsec); +} -- cgit v1.2.3