| 135 | string PhxBaseConfig::s_default_path; |
| 136 | |
| 137 | string PhxBaseConfig::GetBasePath() { |
| 138 | static char szTemp[512] = { 0 }; |
| 139 | |
| 140 | char pszExeName[512] = { 0 }; |
| 141 | |
| 142 | int iFD = open("/proc/self/cmdline", O_RDONLY, 0); |
| 143 | if (iFD < 0) |
| 144 | return pszExeName; |
| 145 | |
| 146 | if (read(iFD, szTemp, sizeof(szTemp) - 1) < 0) { |
| 147 | close(iFD); |
| 148 | return ""; |
| 149 | } |
| 150 | szTemp[511] = 0; |
| 151 | close(iFD); |
| 152 | |
| 153 | string path = szTemp; |
| 154 | |
| 155 | char real_path[128]; |
| 156 | |
| 157 | realpath(path.c_str(), real_path); |
| 158 | path = real_path; |
| 159 | size_t pos = path.rfind("sbin/"); |
| 160 | if (pos == string::npos) { |
| 161 | size_t pos = path.rfind("phxsql/"); |
| 162 | if (pos == string::npos) { |
| 163 | return "../"; |
| 164 | } else { |
| 165 | return path.substr(0, pos + 7); |
| 166 | } |
| 167 | } else { |
| 168 | return path.substr(0, pos); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | //set the default path, where config files are located |
| 173 | void PhxBaseConfig::SetDefaultPath(const char *config_path) { |
nothing calls this directly
no outgoing calls
no test coverage detected