Refactor FG_HOME init, so we can log sooner.
Logging to file now happens earlier, so some useful early output is captured.
This commit is contained in:
parent
7cc3ffb30f
commit
9ccf159f81
6 changed files with 42 additions and 32 deletions
|
@ -163,26 +163,21 @@ static void fg_terminate() {
|
||||||
int _bootstrap_OSInit;
|
int _bootstrap_OSInit;
|
||||||
|
|
||||||
// Main entry point; catch any exceptions that have made it this far.
|
// Main entry point; catch any exceptions that have made it this far.
|
||||||
int main ( int argc, char **argv ) {
|
int main ( int argc, char **argv )
|
||||||
|
{
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
// Don't show blocking "no disk in drive" error messages on Windows 7,
|
// Don't show blocking "no disk in drive" error messages on Windows 7,
|
||||||
// silently return errors to application instead.
|
// silently return errors to application instead.
|
||||||
// See Microsoft MSDN #ms680621: "GUI apps should specify SEM_NOOPENFILEERRORBOX"
|
// See Microsoft MSDN #ms680621: "GUI apps should specify SEM_NOOPENFILEERRORBOX"
|
||||||
SetErrorMode(SEM_NOOPENFILEERRORBOX);
|
SetErrorMode(SEM_NOOPENFILEERRORBOX);
|
||||||
|
|
||||||
// Windows has no $HOME aka %HOME%, so we have to construct the full path.
|
|
||||||
homedir = ::getenv("APPDATA");
|
|
||||||
homedir.append("\\flightgear.org");
|
|
||||||
|
|
||||||
hostname = ::getenv( "COMPUTERNAME" );
|
hostname = ::getenv( "COMPUTERNAME" );
|
||||||
#else
|
#else
|
||||||
// Unix(alike) systems
|
// Unix(alike) systems
|
||||||
char _hostname[256];
|
char _hostname[256];
|
||||||
gethostname(_hostname, 256);
|
gethostname(_hostname, 256);
|
||||||
hostname = _hostname;
|
hostname = _hostname;
|
||||||
|
|
||||||
homedir = ::getenv( "HOME" );
|
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -390,23 +390,26 @@ static SGPath platformDefaultDataPath()
|
||||||
#else
|
#else
|
||||||
static SGPath platformDefaultDataPath()
|
static SGPath platformDefaultDataPath()
|
||||||
{
|
{
|
||||||
SGPath config( homedir );
|
SGPath config( getenv("HOME") );
|
||||||
config.append( ".fgfs" );
|
config.append( ".fgfs" );
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void fgInitHome()
|
||||||
|
{
|
||||||
|
SGPath dataPath = platformDefaultDataPath();
|
||||||
|
const char *fg_home = getenv("FG_HOME");
|
||||||
|
if (fg_home)
|
||||||
|
dataPath = fg_home;
|
||||||
|
|
||||||
|
globals->set_fg_home(dataPath.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// Read in configuration (file and command line)
|
// Read in configuration (file and command line)
|
||||||
bool fgInitConfig ( int argc, char **argv )
|
bool fgInitConfig ( int argc, char **argv )
|
||||||
{
|
{
|
||||||
SGPath dataPath = platformDefaultDataPath();
|
SGPath dataPath = globals->get_fg_home();
|
||||||
|
|
||||||
const char *fg_home = getenv("FG_HOME");
|
|
||||||
if (fg_home)
|
|
||||||
dataPath = fg_home;
|
|
||||||
|
|
||||||
globals->set_fg_home(dataPath.c_str());
|
|
||||||
|
|
||||||
simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
|
simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
|
||||||
if (!exportDir.exists()) {
|
if (!exportDir.exists()) {
|
||||||
exportDir.create(0777);
|
exportDir.create(0777);
|
||||||
|
|
|
@ -34,6 +34,7 @@ class SGPath;
|
||||||
// Return the current base package version
|
// Return the current base package version
|
||||||
std::string fgBasePackageVersion();
|
std::string fgBasePackageVersion();
|
||||||
|
|
||||||
|
void fgInitHome();
|
||||||
|
|
||||||
// Read in configuration (file and command line)
|
// Read in configuration (file and command line)
|
||||||
bool fgInitConfig ( int argc, char **argv );
|
bool fgInitConfig ( int argc, char **argv );
|
||||||
|
|
|
@ -273,12 +273,34 @@ static void ATIScreenSizeHack()
|
||||||
globals->get_renderer()->addCamera(hackCam, false);
|
globals->get_renderer()->addCamera(hackCam, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void logToFile()
|
||||||
|
{
|
||||||
|
SGPath logPath = globals->get_fg_home();
|
||||||
|
logPath.append("fgfs.log");
|
||||||
|
if (logPath.exists()) {
|
||||||
|
SGPath prevLogPath = globals->get_fg_home();
|
||||||
|
prevLogPath.append("fgfs_0.log");
|
||||||
|
logPath.rename(prevLogPath);
|
||||||
|
// bit strange, we need to restore the correct value of logPath now
|
||||||
|
logPath = globals->get_fg_home();
|
||||||
|
logPath.append("fgfs.log");
|
||||||
|
}
|
||||||
|
sglog().logToFile(logPath, SG_ALL, SG_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
// Main top level initialization
|
// Main top level initialization
|
||||||
int fgMainInit( int argc, char **argv ) {
|
int fgMainInit( int argc, char **argv ) {
|
||||||
|
|
||||||
// set default log levels
|
// set default log levels
|
||||||
sglog().setLogLevels( SG_ALL, SG_ALERT );
|
sglog().setLogLevels( SG_ALL, SG_ALERT );
|
||||||
|
|
||||||
|
globals = new FGGlobals;
|
||||||
|
fgInitHome();
|
||||||
|
|
||||||
|
// now home is initialised, we can log to a file inside it
|
||||||
|
logToFile();
|
||||||
|
|
||||||
string version;
|
string version;
|
||||||
#ifdef FLIGHTGEAR_VERSION
|
#ifdef FLIGHTGEAR_VERSION
|
||||||
version = FLIGHTGEAR_VERSION;
|
version = FLIGHTGEAR_VERSION;
|
||||||
|
@ -292,8 +314,8 @@ int fgMainInit( int argc, char **argv ) {
|
||||||
// Allocate global data structures. This needs to happen before
|
// Allocate global data structures. This needs to happen before
|
||||||
// we parse command line options
|
// we parse command line options
|
||||||
|
|
||||||
globals = new FGGlobals;
|
|
||||||
|
|
||||||
// seed the random number generator
|
// seed the random number generator
|
||||||
sg_srandom_time();
|
sg_srandom_time();
|
||||||
|
|
||||||
|
@ -313,18 +335,6 @@ int fgMainInit( int argc, char **argv ) {
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
|
SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPath logPath = globals->get_fg_home();
|
|
||||||
logPath.append("fgfs.log");
|
|
||||||
if (logPath.exists()) {
|
|
||||||
SGPath prevLogPath = globals->get_fg_home();
|
|
||||||
prevLogPath.append("fgfs_0.log");
|
|
||||||
logPath.rename(prevLogPath);
|
|
||||||
// bit strange, we need to restore the correct value of logPath now
|
|
||||||
logPath = globals->get_fg_home();
|
|
||||||
logPath.append("fgfs.log");
|
|
||||||
}
|
|
||||||
sglog().logToFile(logPath, SG_ALL, SG_INFO);
|
|
||||||
|
|
||||||
// Initialize the Window/Graphics environment.
|
// Initialize the Window/Graphics environment.
|
||||||
fgOSInit(&argc, argv);
|
fgOSInit(&argc, argv);
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
int fgMainInit( int argc, char **argv );
|
int fgMainInit( int argc, char **argv );
|
||||||
|
|
||||||
extern std::string homedir;
|
|
||||||
extern std::string hostname;
|
extern std::string hostname;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1745,6 +1745,8 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
|
||||||
// then config files
|
// then config files
|
||||||
SGPath config;
|
SGPath config;
|
||||||
|
|
||||||
|
std::string homedir(getenv("HOME"));
|
||||||
|
|
||||||
if( homedir.size() && hostname.size() ) {
|
if( homedir.size() && hostname.size() ) {
|
||||||
// Check for ~/.fgfsrc.hostname
|
// Check for ~/.fgfsrc.hostname
|
||||||
config.set(homedir);
|
config.set(homedir);
|
||||||
|
|
Loading…
Add table
Reference in a new issue