From 2b53faf94245900d84afbdaeecc47f827179f874 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 28 May 2019 08:41:04 +0200 Subject: [PATCH] Use exit_vncviewer() for early errors Makes things more consistent and avoids surprises. --- vncviewer/vncviewer.cxx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 39a267c0..f6ae1675 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -86,6 +86,7 @@ char vncServerName[VNCSERVERNAMELEN] = { '\0' }; static const char *argv0 = NULL; +static bool inMainloop = false; static bool exitMainloop = false; static const char *exitError = NULL; @@ -114,7 +115,14 @@ void exit_vncviewer(const char *error) if ((error != NULL) && (exitError == NULL)) exitError = strdup(error); - exitMainloop = true; + if (inMainloop) + exitMainloop = true; + else { + // We're early in the startup. Assume we can just exit(). + if (alertOnFatalError) + fl_alert("%s", exitError); + exit(EXIT_FAILURE); + } } bool should_exit() @@ -415,9 +423,7 @@ potentiallyLoadConfigurationFile(char *vncServerName) vncServerName[VNCSERVERNAMELEN-1] = '\0'; } catch (rfb::Exception& e) { vlog.error("%s", e.str()); - if (alertOnFatalError) - fl_alert("%s", e.str()); - exit(EXIT_FAILURE); + exit_vncviewer(e.str()); } } } @@ -600,10 +606,8 @@ int main(int argc, char** argv) // TRANSLATORS: "Parameters" are command line arguments, or settings // from a file or the Windows registry. vlog.error(_("Parameters -listen and -via are incompatible")); - if (alertOnFatalError) - fl_alert(_("Parameters -listen and -via are incompatible")); - exit_vncviewer(); - return 1; + exit_vncviewer(_("Parameters -listen and -via are incompatible")); + return 1; /* Not reached */ } #endif @@ -649,10 +653,8 @@ int main(int argc, char** argv) } } catch (rdr::Exception& e) { vlog.error("%s", e.str()); - if (alertOnFatalError) - fl_alert("%s", e.str()); - exit_vncviewer(); - return 1; + exit_vncviewer(e.str()); + return 1; /* Not reached */ } while (!listeners.empty()) { @@ -674,8 +676,10 @@ int main(int argc, char** argv) CConn *cc = new CConn(vncServerName, sock); + inMainloop = true; while (!exitMainloop) run_mainloop(); + inMainloop = false; delete cc; -- 2.39.5