summaryrefslogtreecommitdiffstats
path: root/app-misc/sshsleeper/files/sshsleeper.c
diff options
context:
space:
mode:
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);
+}