-
Notifications
You must be signed in to change notification settings - Fork 77
/
adbiserver.c
100 lines (72 loc) · 1.99 KB
/
adbiserver.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
99
100
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "communication/communication.h"
#include "communication/protocol.h"
#include "process/process.h"
#include "process/thread.h"
#include "procutil/wait.h"
#include "injectable/injectable.h"
#include "util/signal.h"
#include "util/capabilities.h"
#include "logger.h"
static void cleanup() {
debug("Cleaning up...");
process_cleanup();
comm_cleanup();
protocol_cleanup();
injectable_cleanup();
debug("Cleanup complete.");
}
static void init() {
int initialized = protocol_init() && caps_init() && signal_init() && comm_init() && injectable_init();
if (!initialized) {
fatal("Initialization failed.");
cleanup();
exit(EXIT_FAILURE);
}
}
static void loop() {
alarm(10);
while (likely(!signal_quit)) {
#if 0
{
/* sanity check */
void tc(thread_t * thread) {
assert(thread->references == 2);
}
void pc(process_t * process) {
assert(!tree_empty(&process->threads));
assert(process->references == 2 + tree_size(&process->threads));
thread_iter(process, tc);
}
process_iter(pc);
}
#endif
signal_wait();
if (likely(signal_child)) {
wait_main();
}
if (unlikely(signal_io)) {
comm_handle_io();
signal_io = 0;
}
if (unlikely(signal_disconnected)) {
comm_handle_io();
}
if (unlikely(signal_alarm)) {
alarm(10);
signal_alarm = 0;
}
}
warning("Exiting.");
}
int main(/* int argc, char * argv[] */) {
info("Welcome to ADBI server.");
debug("Built on %s at %s.", __DATE__, __TIME__);
logger_level = LOGGER_DEBUG;
init();
loop();
cleanup();
return EXIT_SUCCESS;
}