mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-04 09:42:59 +00:00
Added some exception hadling. Dont want to live *too* dangerously here
This commit is contained in:
parent
92abc92463
commit
d701f4e331
@ -153,6 +153,7 @@ void PostgreSQL::nodeIsOnline(const uint64_t networkId, const uint64_t memberId,
|
||||
|
||||
void PostgreSQL::initializeNetworks(PGconn *conn)
|
||||
{
|
||||
try {
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
fprintf(stderr, "Bad Database Connection: %s", PQerrorMessage(conn));
|
||||
exit(1);
|
||||
@ -276,10 +277,15 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
|
||||
}
|
||||
_readyLock.unlock();
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error initializing networks: %s", e.what());
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void PostgreSQL::initializeMembers(PGconn *conn)
|
||||
{
|
||||
try {
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
fprintf(stderr, "Bad Database Connection: %s", PQerrorMessage(conn));
|
||||
exit(1);
|
||||
@ -376,6 +382,10 @@ void PostgreSQL::initializeMembers(PGconn *conn)
|
||||
}
|
||||
_readyLock.unlock();
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error initializing members: %s\n", e.what());
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void PostgreSQL::heartbeat()
|
||||
@ -565,7 +575,7 @@ void PostgreSQL::commitThread()
|
||||
{
|
||||
PGconn *conn = PQconnectdb(_path.c_str());
|
||||
if (PQstatus(conn) == CONNECTION_BAD) {
|
||||
fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
fprintf(stderr, "ERROR: Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
@ -575,8 +585,15 @@ void PostgreSQL::commitThread()
|
||||
if (!config) {
|
||||
continue;
|
||||
}
|
||||
if (PQstatus(conn) == CONNECTION_BAD) {
|
||||
fprintf(stderr, "ERROR: Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
try {
|
||||
const std::string objtype = (*config)["objtype"];
|
||||
if (objtype == "member") {
|
||||
try {
|
||||
std::string memberId = (*config)["id"];
|
||||
std::string networkId = (*config)["nwid"];
|
||||
std::string name = (*config)["name"];
|
||||
@ -700,7 +717,11 @@ void PostgreSQL::commitThread()
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error updating member: %s\n", e.what());
|
||||
}
|
||||
} else if (objtype == "network") {
|
||||
try {
|
||||
std::string id = (*config)["id"];
|
||||
std::string controllerId = _myAddressStr.c_str();
|
||||
std::string name = (*config)["name"];
|
||||
@ -882,10 +903,13 @@ void PostgreSQL::commitThread()
|
||||
fprintf(stderr, "ERROR: Error committing network update: %s\n", PQresultErrorMessage(res));
|
||||
}
|
||||
PQclear(res);
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error updating member: %s\n", e.what());
|
||||
}
|
||||
} else if (objtype == "trace") {
|
||||
fprintf(stderr, "ERROR: Trace not yet implemented");
|
||||
} else if (objtype == "_delete_network") {
|
||||
|
||||
try {
|
||||
std::string networkId = (*config)["nwid"];
|
||||
const char *values[1] = {
|
||||
networkId.c_str()
|
||||
@ -904,7 +928,11 @@ void PostgreSQL::commitThread()
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error deleting network: %s\n", e.what());
|
||||
}
|
||||
} else if (objtype == "_delete_member") {
|
||||
try {
|
||||
std::string memberId = (*config)["id"];
|
||||
std::string networkId = (*config)["nwid"];
|
||||
|
||||
@ -927,10 +955,15 @@ void PostgreSQL::commitThread()
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error deleting member: %s\n", e.what());
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "ERROR: unknown objtype");
|
||||
}
|
||||
|
||||
} catch (std::exception &e) {
|
||||
fprintf(stderr, "ERROR: Error getting objtype: %s\n", e.what());
|
||||
}
|
||||
delete config;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
Loading…
x
Reference in New Issue
Block a user