blob: a88c4bc48d075f9d0a94a2735a6b8df22fc44e02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
|