From 852e10d59bb6262de04593903981dec1e7ca85dc Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 10 Nov 2011 10:07:40 +0100 Subject: Die if trust file load fails --- src/main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index d4bf6fb..e14a88a 100644 --- a/src/main.c +++ b/src/main.c @@ -328,6 +328,7 @@ int main (int argc, char **argv) { static BarApp_t app; /* terminal attributes _before_ we started messing around with ~ECHO */ struct termios termOrig; + WaitressReturn_t wRet; memset (&app, 0, sizeof (app)); @@ -344,10 +345,6 @@ int main (int argc, char **argv) { BarSettingsInit (&app.settings); BarSettingsRead (&app.settings); - WaitressInit (&app.waith, app.settings.tlsCaPath); - app.waith.url.host = strdup (PIANO_RPC_HOST); - app.waith.url.tls = true; - BarUiMsg (&app.settings, MSG_NONE, "Welcome to " PACKAGE " (" VERSION ")! "); if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) { @@ -358,6 +355,20 @@ int main (int argc, char **argv) { app.settings.keys[BAR_KS_HELP]); } + if ((wRet = WaitressInit (&app.waith, app.settings.tlsCaPath)) != WAITRESS_RET_OK) { + if (wRet == WAITRESS_RET_TLS_TRUSTFILE_ERR) { + BarUiMsg (&app.settings, MSG_ERR, "Can't load root certificates. " + "Please check the tls_ca_path setting in your config file.\n"); + } else { + BarUiMsg (&app.settings, MSG_ERR, "Can't initialize HTTP library: " + "%s\n", WaitressErrorToStr (wRet)); + } + goto die; + } + + app.waith.url.host = strdup (PIANO_RPC_HOST); + app.waith.url.tls = true; + /* init fds */ FD_ZERO(&app.input.set); app.input.fds[0] = STDIN_FILENO; @@ -377,6 +388,7 @@ int main (int argc, char **argv) { BarMainLoop (&app); +die: if (app.input.fds[1] != -1) { close (app.input.fds[1]); } -- cgit v1.2.3