summaryrefslogtreecommitdiffstats
path: root/app-misc/sshsleeper/files/sshsleeper.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2019-09-01 00:00:32 +0200
committerSuren A. Chilingaryan <csa@suren.me>2019-09-01 00:00:32 +0200
commitca9627e70852f6b2e835660df870fe3ab405882d (patch)
tree0a008b1d5b16fa0679a195ed7b5662c7891f591c /app-misc/sshsleeper/files/sshsleeper.c
downloaddarklin4-ca9627e70852f6b2e835660df870fe3ab405882d.tar.gz
darklin4-ca9627e70852f6b2e835660df870fe3ab405882d.tar.bz2
darklin4-ca9627e70852f6b2e835660df870fe3ab405882d.tar.xz
darklin4-ca9627e70852f6b2e835660df870fe3ab405882d.zip
Initial import
Diffstat (limited to 'app-misc/sshsleeper/files/sshsleeper.c')
-rw-r--r--app-misc/sshsleeper/files/sshsleeper.c38
1 files changed, 38 insertions, 0 deletions
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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#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);
+}