MCPcopy Create free account
hub / github.com/Tencent/phxsql / GetBasePath

Method GetBasePath

phxcomm/configparser/base_config.cpp:137–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135string PhxBaseConfig::s_default_path;
136
137string 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
173void PhxBaseConfig::SetDefaultPath(const char *config_path) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected