forked from BulldogDrummond/aldl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.c
45 lines (38 loc) · 1.09 KB
/
remote.c
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
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
/* local objects */
#include "error.h"
#include "aldl-io.h"
#include "loadconfig.h"
#include "useful.h"
void *remote_init(void *aldl_in) {
aldl_conf_t *aldl = aldl_in;
int ran_connected_script = 0;
while(1) {
/* loop throttling */
sleep(1);
/* exit entire program if this file is present ... */
if(access("/etc/aldl/aldl-stop",F_OK) != -1) {
exit(1);
}
/* if /etc/aldl/aldl-connected.sh exists, run it when buffered... */
if(aldl->ready == 1 && ran_connected_script == 0) {
if(access("/etc/aldl/aldl-connected.sh",X_OK) != -1) {
system("/etc/aldl/aldl-connected.sh");
}
ran_connected_script = 1;
}
/* if connection drops after being connected, run aldl-disconnected.sh */
if(ran_connected_script == 1 && get_connstate(aldl) > 10) {
if(access("/etc/aldl/aldl-disconnected.sh",X_OK) != -1) {
system("/etc/aldl/aldl-disconnected.sh");
}
ran_connected_script = 0;
}
}
return NULL;
}