Changeset 17348
- Timestamp:
- 11/23/13 13:01:26 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Main.h
r16759 r17348 21 21 { 22 22 using namespace std; 23 namespace fs = boost::filesystem; 23 24 24 25 void SetupConfiguration(Configuration &conf) … … 31 32 ("host", var<string>(), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)") 32 33 ("log,l", var<string>(n), "Name of local log-file") 34 ("logpath", var<string>(), "Absolute path to log-files (default: excutable's directory)") 33 35 ("no-log", po_switch(), "Supress log-file") 34 36 ("append-log", po_bool(), "Append log information to local log-file") … … 38 40 ("exec,e", vars<string>(), "Execute one or more scrips at startup ('file:N' - start at label N)") 39 41 ("arg:*", var<string>(), "Arguments for script execution with --exc, e.g. --arg:ra='12.5436'") 42 ("home", var<string>(), "Path to home directory (used as default for logpath if standard log files not writable)") 40 43 ("quit", po_switch(), "Quit after startup"); 41 44 ; … … 43 46 conf.AddEnv("dns", "DIM_DNS_NODE"); 44 47 conf.AddEnv("host", "DIM_HOST_NODE"); 48 conf.AddEnv("home", "HOME"); 45 49 46 50 conf.AddOptions(config); … … 87 91 88 92 // ----------------------------------------------------------------- 89 90 static T shell(conf.GetName().c_str(), 93 const fs::path program(conf.GetName()); 94 95 // Split path to program into path and filename 96 const string prgpath = program.parent_path().string(); 97 98 #if BOOST_VERSION < 104600 99 const string prgname = program.filename(); 100 #else 101 const string prgname = program.filename().string(); 102 #endif 103 104 fs::path path = conf.Has("logpath") ? conf.Get<string>("logpath") : ""; 105 106 // No explicit path given 107 if (path.empty()) 108 { 109 path = prgpath; 110 111 // default path not accessible 112 if (access(prgpath.empty() ? "." : prgpath.c_str(), W_OK)) 113 { 114 path = conf.Get<string>("home"); 115 path /= ".fact++"; 116 } 117 } 118 119 // Create directories if necessary 120 fs::create_directories(path); 121 122 // ----------------------------------------------------------------- 123 124 static T shell((path/prgname).string().c_str(), 91 125 conf.Has("console") ? conf.Get<int>("console")!=1 : conf.Get<bool>("null")); 92 126 … … 108 142 109 143 if (conf.Has("log") && !conf.Get<bool>("no-log")) 110 if (!wout.OpenLogFile(conf.Get<string>("log"), conf.Get<bool>("append-log"))) 111 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl; 144 { 145 #if BOOST_VERSION < 104600 146 const fs::path file = fs::path(conf.Get<string>("log")).filename(); 147 #else 148 const fs::path file = fs::path(conf.Get<string>("log")).filename(); 149 #endif 150 if (!wout.OpenLogFile((path/file).string(), conf.Get<bool>("append-log"))) 151 win << kYellow << "WARNING - Couldn't open log-file " << path.string() << ": " << strerror(errno) << endl; 152 } 112 153 113 154 S io_service(wout); 114 155 115 const boost::filesystem::path path(conf.GetName());116 117 const string pname = path.parent_path().string();118 #if BOOST_VERSION < 104600119 const string fname = path.filename();120 #else121 const string fname = path.filename().string();122 #endif123 156 const Time now; 124 157 io_service.Write(now, "/----------------------- Program ------------------------"); 125 io_service.Write(now, "| Program: "PACKAGE_STRING" ("+ fname+":"+to_string(getpid())+")");126 io_service.Write(now, "| CallPath: "+p name);158 io_service.Write(now, "| Program: "PACKAGE_STRING" ("+prgname+":"+to_string(getpid())+")"); 159 io_service.Write(now, "| CallPath: "+prgpath); 127 160 io_service.Write(now, "| Compiled: "__DATE__" "__TIME__); 128 161 io_service.Write(now, "| Revision: "REVISION);
Note:
See TracChangeset
for help on using the changeset viewer.