From 5190d2ac4fe8f3eb4deb3f40190d301196e3247e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 13 Jan 2008 16:38:58 +0000 Subject: [PATCH] fix crash at startup if .rc files are empty and/or if ARDOUR::init() fails for any reason; also avoid calling XML parser with empty files git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2907 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 8 +++-- libs/ardour/configuration.cc | 62 +++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 8601b3f5e4..c7051680db 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -228,7 +228,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[]) /* lets get this party started */ try { - ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization); + if (ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization)) { + throw failed_constructor (); + } + setup_gtk_ardour_enums (); Config->set_current_owner (ConfigVariableBase::Interface); setup_profile (); @@ -236,7 +239,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[]) } catch (failed_constructor& err) { error << _("could not initialize Ardour.") << endmsg; // pass it on up - throw err; + throw; } /* we like keyboards */ @@ -247,7 +250,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[]) stopping.connect (mem_fun(*this, &ARDOUR_UI::shutdown)); platform_setup (); - } int diff --git a/libs/ardour/configuration.cc b/libs/ardour/configuration.cc index c19541ddbd..6493b61fea 100644 --- a/libs/ardour/configuration.cc +++ b/libs/ardour/configuration.cc @@ -20,6 +20,9 @@ #include #include /* for snprintf, grrr */ +#include +#include /* for g_stat() */ + #include #include @@ -74,7 +77,8 @@ int Configuration::load_state () { string rcfile; - + struct stat statbuf; + /* load system configuration first */ rcfile = find_config_file ("ardour_system.rc"); @@ -83,18 +87,28 @@ Configuration::load_state () XMLTree tree; - cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl; + /* stupid XML Parser hates empty files */ - if (!tree.read (rcfile.c_str())) { - error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg; + if (g_stat (rcfile.c_str(), &statbuf)) { return -1; } - current_owner = ConfigVariableBase::System; - - if (set_state (*tree.root())) { - error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; - return -1; + if (statbuf.st_size != 0) { + cerr << string_compose (_("loading system configuration file %1"), rcfile) << endl; + + if (!tree.read (rcfile.c_str())) { + error << string_compose(_("Ardour: cannot read system configuration file \"%1\""), rcfile) << endmsg; + return -1; + } + + current_owner = ConfigVariableBase::System; + + if (set_state (*tree.root())) { + error << string_compose(_("Ardour: system configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; + return -1; + } + } else { + error << _("your system Ardour configuration file is empty. This probably means that there as an error installing Ardour") << endmsg; } } @@ -106,20 +120,30 @@ Configuration::load_state () if (rcfile.length()) { XMLTree tree; - - cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl; - if (!tree.read (rcfile)) { - error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg; + /* stupid XML parser hates empty files */ + + if (g_stat (rcfile.c_str(), &statbuf)) { return -1; } - current_owner = ConfigVariableBase::Config; - - if (set_state (*tree.root())) { - error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; - return -1; - } + if (statbuf.st_size != 0) { + cerr << string_compose (_("loading user configuration file %1"), rcfile) << endl; + + if (!tree.read (rcfile)) { + error << string_compose(_("Ardour: cannot read configuration file \"%1\""), rcfile) << endmsg; + return -1; + } + + current_owner = ConfigVariableBase::Config; + + if (set_state (*tree.root())) { + error << string_compose(_("Ardour: user configuration file \"%1\" not loaded successfully."), rcfile) << endmsg; + return -1; + } + } else { + warning << _("your Ardour configuration file is empty. This is not normal.") << endmsg; + } } return 0;