-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (54 loc) · 1.46 KB
/
main.cpp
File metadata and controls
56 lines (54 loc) · 1.46 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
#include <vector>
#include <cstdio>
#include "bob.h"
#include <csignal>
#include <cstdlib>
#include <thread>
bool bob_client_stop_flag = false;
bool is_watchdog = true;
static void onSigInt(int) {
if (!bob_client_stop_flag)
{
if (!is_watchdog) requestToExitBob(); // watchdog process doesn't run bob actually
bob_client_stop_flag = true;
}
else
{
printf("Pressed Ctrl+C twice, killing the process...\n");
exit(3);
}
}
void installCtrlCPrinter() {
std::signal(SIGINT, &onSigInt);
}
int main(int argc, char *argv[]) {
if (argc == 3)
{
if (std::string(argv[2]) == "-no-watchdog") is_watchdog = false;
}
installCtrlCPrinter();
if (is_watchdog)
{
std::string command = std::string(argv[0]) + " ";
if (argc > 1) command += std::string(argv[1]) + " -no-watchdog";
else command += "bob.json -no-watchdog";
while (true){
int r = system(command.c_str());
printf("bob exited with code %d, if you want to exit bob completely, press Ctrl+C one more time\n", r);
printf("sleep for 2 seconds and start again\n");
if (bob_client_stop_flag) break;
std::this_thread::sleep_for(std::chrono::seconds (2));
}
}
else
{
try {
return runBob(argc, argv);
}
catch (std::exception &ex) {
printf("%s", ex.what());
return -1;
}
}
return 0;
}