-
Notifications
You must be signed in to change notification settings - Fork 0
/
nobarrier.c
98 lines (90 loc) · 2.21 KB
/
nobarrier.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*!gcc {0} -I. -I../include/ -o out; ./out */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifndef snprintf
#define snprintf(buffer, size, ...) sprintf(buffer, __VA_ARGS__)
#endif
const char *possible_addresses[] = {
// 8
"192.168.8.100:24800",
"192.168.8.101:24800",
"192.168.8.102:24800",
"192.168.8.103:24800",
"192.168.8.104:24800",
"192.168.8.105:24800",
"192.168.8.106:24800",
"192.168.8.107:24800",
"192.168.8.108:24800",
"192.168.8.109:24800",
// 9
"192.168.9.100:24800",
"192.168.9.101:24800",
"192.168.9.102:24800",
"192.168.9.103:24800",
"192.168.9.104:24800",
"192.168.9.105:24800",
"192.168.9.106:24800",
"192.168.9.107:24800",
"192.168.9.108:24800",
"192.168.9.109:24800",
// 10
"192.168.10.100:24800",
"192.168.10.101:24800",
"192.168.10.102:24800",
"192.168.10.103:24800",
"192.168.10.104:24800",
"192.168.10.105:24800",
"192.168.10.106:24800",
"192.168.10.107:24800",
"192.168.10.108:24800",
"192.168.10.109:24800"
};
unsigned barrier_server_is_running(const char *address)
{
FILE *fp;
char path[1035];
char *concatenated = (char *) malloc(200);
snprintf(concatenated, 200, "curl -I --silent --max-time 4 %s\0", address);
printf("Checking '%s'... ", concatenated);
clock_t begin = clock();
fp = popen(concatenated, "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit(1);
}
while (fgets(path, sizeof(path), fp) != NULL) {
printf("%s", path);
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
pclose(fp);
printf("(%f) \n", time_spent);
if (time_spent <= 2) {
free(concatenated);
return 1;
}
free(concatenated);
return 0;
}
void check_possible_open_barrier_server(char *name)
{
unsigned index;
for(index = 0; index < 30; index++) {
const char *address = possible_addresses[index];
if (barrier_server_is_running(address) == 1) {
char *concatenated = (char *) malloc(200);
snprintf(concatenated, 200, "barrierc -f --name %s %s\0", name, address);
printf("Barrier running at %s\n", address);
system(concatenated);
free(concatenated);
return;
}
}
check_possible_open_barrier_server(name);
}
int main(int argc, char **argv)
{
check_possible_open_barrier_server(argv[1]);
return EXIT_SUCCESS;
}