Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 7040801

Browse files
Nov11pervazea
authored andcommitted
when 'bind' fails, log error message and exit with none-zero value (#1321)
1 parent 73b4f73 commit 7040801

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/main/peloton/peloton.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
// For GFlag's built-in help message flag
2323
DECLARE_bool(help);
2424

25-
void RunPelotonServer() {
25+
int RunPelotonServer() {
26+
int return_code = 0;
2627
try {
2728
// Setup
2829
peloton::PelotonInit::Initialize();
@@ -34,15 +35,18 @@ void RunPelotonServer() {
3435

3536
peloton_server.SetupServer().ServerLoop();
3637
} catch (peloton::ConnectionException &exception) {
37-
// Nothing to do here!
38+
//log error message and mark failure
39+
peloton::LOG_ERROR("Cannot start server. Failure detail : %s\n", exception.GetMessage().c_str());
40+
return_code = EXIT_FAILURE;
3841
}
3942

4043
// Teardown
4144
peloton::PelotonInit::Shutdown();
45+
return return_code;
4246
}
4347

4448

45-
void RunPelotonBrain() {
49+
int RunPelotonBrain() {
4650
// TODO(tianyu): boot up other peloton resources as needed here
4751
peloton::brain::Brain brain;
4852
evthread_use_pthreads();
@@ -62,6 +66,7 @@ void RunPelotonBrain() {
6266

6367
brain.RegisterJob<peloton::brain::SimpleBrainJob>(&one_second, "test", example_task);
6468
brain.Run();
69+
return 0;
6570
}
6671

6772
int main(int argc, char *argv[]) {
@@ -84,13 +89,14 @@ int main(int argc, char *argv[]) {
8489
}
8590
} catch (peloton::SettingsException &exception) {
8691
peloton::LOG_ERROR("Cannot load settings. Failed with %s\n", exception.GetMessage().c_str());
87-
return 0; // TODO: Use an enum with exit error codes
92+
return EXIT_FAILURE; // TODO: Use an enum with exit error codes
8893
}
8994

95+
int exit_code = 0;
9096
if (peloton::settings::SettingsManager::GetBool(
9197
peloton::settings::SettingId::brain))
92-
RunPelotonBrain();
98+
exit_code = RunPelotonBrain();
9399
else
94-
RunPelotonServer();
95-
return 0;
100+
exit_code = RunPelotonServer();
101+
return exit_code;
96102
}

src/network/peloton_server.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ int PelotonServer::VerifyCallback(int ok, X509_STORE_CTX *store) {
226226
template<typename... Ts>
227227
void PelotonServer::TrySslOperation(int (*func)(Ts...), Ts... arg) {
228228
if (func(arg...) < 0) {
229+
auto error_message = peloton_error_message();
229230
if (GetSSLLevel() != SSLLevel::SSL_DISABLE) {
230231
SSL_CTX_free(ssl_context);
231232
}
232-
throw ConnectionException("Error listening onsocket.");
233+
throw ConnectionException(error_message);
233234
}
234235
}
235236

0 commit comments

Comments
 (0)