-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlive_inspector.c
More file actions
58 lines (47 loc) · 1.11 KB
/
live_inspector.c
File metadata and controls
58 lines (47 loc) · 1.11 KB
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
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include "live_inspector.h"
static int stop = 0, canceled = 0;
static li_data *data = NULL;
static pthread_t li_thread;
static void *live_inspector(void *arg) {
li_data *data = (li_data *)arg;
register_thread("Live Inspector");
unsigned long endtime = (unsigned long)time(NULL) + data->time_to_live;
while(!stop) {
unsigned long curtime = (unsigned long)time(NULL);
int status = api_jobs_status(data->build_id);
if(status || curtime > endtime) {
kill(data->pid, SIGKILL);
canceled = 1;
break;
}
for (int i = 0; !stop && i < 3; i++) {
sleep(1);
}
}
free(data);
unregister_thread(li_thread);
return NULL;
}
int start_live_inspector(int ttl, pid_t pid, const char *bid) {
int res;
data = xmalloc(sizeof(li_data));
data->time_to_live = ttl;
data->pid = pid;
data->build_id = bid;
stop = canceled = 0;
res = pthread_create(&li_thread, NULL, &live_inspector, data);
if(res != 0) {
return -1;
}
return 0;
}
int stop_live_inspector() {
stop = 1;
pthread_join(li_thread, NULL);
stop = 0;
return canceled;
}