-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerMain.cpp
49 lines (45 loc) · 1.18 KB
/
ServerMain.cpp
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
/*
* Copyright (C) 2021 Ilya Entin
*/
#include <cassert>
#include <csignal>
#include "Metrics.h"
#include "ServerOptions.h"
#include "Server.h"
#include "TransactionPolicy.h"
#include "Utility.h"
void signalHandler([[maybe_unused]] int signal) {}
int main() {
std::string terminal(getenv("GNOME_TERMINAL_SCREEN"));
utility::setServerTerminal(terminal);
atexit(Server::removeNamedMutex);
try {
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
sigset_t set;
sigemptyset(&set);
if (sigaddset(&set, SIGINT) == -1)
LogError << strerror(errno) << '\n';
if (sigaddset(&set, SIGTERM) == -1)
LogError << strerror(errno) << '\n';
ServerOptions::parse("ServerOptions.json");
TransactionPolicy policy;
ServerPtr server = std::make_shared<Server>(policy);
if (!server->start())
return 3;
int sig = 0;
if (sigwait(&set, &sig))
LogError << strerror(errno) << '\n';
Metrics::save();
server->stop();
Metrics::print();
int closed = fcloseall();
assert(closed == 0);
return 0;
}
catch (const std::exception& e) {
LogError << e.what() << '\n';
return 5;
}
}