From 7b1f1d73e6ef01adf82f0bc7810a8862e7deecb9 Mon Sep 17 00:00:00 2001
From: ehofman <ehofman>
Date: Tue, 27 Dec 2005 14:02:38 +0000
Subject: [PATCH] Detect the hostname as early as possible to prevent a
 segmentation fault (and an unknown exception in the main loop situation.

---
 src/Main/fg_init.cxx | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx
index 5ad947602..0c57030a1 100644
--- a/src/Main/fg_init.cxx
+++ b/src/Main/fg_init.cxx
@@ -145,6 +145,15 @@ float init_volume;
 static string fgScanForOption( const string& option, int argc, char **argv ) {
     int i = 1;
 
+    cout << "The quest for hostname part 1" << endl;
+    if (hostname == NULL)
+    {
+        char _hostname[256];
+        gethostname(_hostname, 256);
+        hostname = strdup(_hostname);
+        free_hostname = true;
+    }
+
     SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
 
     int len = option.length();
@@ -212,14 +221,6 @@ static string fgScanForOption( const string& option, const string& path ) {
 static string fgScanForOption( const string& option ) {
     string arg("");
 
-    if (hostname == NULL)
-    {
-        char _hostname[256];
-        gethostname(_hostname, 256);
-        hostname = strdup(_hostname);
-        free_hostname = true;
-    }
-
 #if defined( unix ) || defined( __CYGWIN__ )
     // Next check home directory for .fgfsrc.hostname file
     if ( arg.empty() ) {