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
This commit is contained in:
Paul Davis 2008-01-13 16:38:58 +00:00
parent 570e002e86
commit 5190d2ac4f
2 changed files with 48 additions and 22 deletions

View file

@ -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

View file

@ -20,6 +20,9 @@
#include <unistd.h>
#include <cstdio> /* for snprintf, grrr */
#include <glib.h>
#include <glib/gstdio.h> /* for g_stat() */
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
@ -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;