本文整理汇总了C++中TError::GetMsg方法的典型用法代码示例。如果您正苦于以下问题:C++ TError::GetMsg方法的具体用法?C++ TError::GetMsg怎么用?C++ TError::GetMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TError
的用法示例。
在下文中一共展示了TError::GetMsg方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsCfqActive
static bool IsCfqActive() {
std::vector<std::string> items;
(void)TPath("/sys/block").ReadDirectory(items);
for (auto d : items) {
if ( (d.find(std::string("loop")) != std::string::npos) || (d.find(std::string("ram")) != std::string::npos) )
continue;
std::string data;
std::vector<std::string> tokens;
TError error = TPath("/sys/block/" + d + "/queue/scheduler").ReadAll(data);
if (error)
throw error.GetMsg();
error = SplitString(data, ' ', tokens);
if (error)
throw error.GetMsg();
bool cfqEnabled = false;
for (auto t : tokens) {
if (t == std::string("[cfq]"))
cfqEnabled = true;
}
if (!cfqEnabled) {
return false;
}
}
return true;
}
示例2: main
int main(int argc, char *argv[])
{
if (argc == 2 && !strcmp(argv[1], "connectivity"))
return TestConnectivity();
// in case client closes pipe we are writing to in the protobuf code
Signal(SIGPIPE, SIG_IGN);
TLogger::DisableLog();
umask(0);
if (argc >= 2) {
string name(argv[1]);
if (name == "-h" || name == "--help") {
Usage();
return EXIT_FAILURE;
}
if (name == "-v" || name == "--version") {
std::cout << PORTO_VERSION << " " << PORTO_REVISION << std::endl;
return EXIT_FAILURE;
}
}
try {
config.Load();
test::InitUsersAndGroups();
auto nl = std::make_shared<TNl>();
TError error = nl->Connect();
if (error)
throw error.GetMsg();
error = nl->OpenLinks(test::links, false);
if (error)
throw error.GetMsg();
test::InitKernelFeatures();
string what = "";
if (argc >= 2)
what = argv[1];
if (what == "stress")
return Stresstest(argc - 2, argv + 2);
else
return Selftest(argc - 1, argv + 1);
} catch (string err) {
std::cerr << "Exception: " << err << std::endl;
} catch (const std::exception &exc) {
std::cerr << "Exception: " << exc.what() << std::endl;
} catch (...) {
std::cerr << "Unknown exception" << std::endl;
}
return EXIT_FAILURE;
};
示例3: AsDaemon
void AsDaemon(TPortoAPI &api) {
TUser daemonUser("daemon");
TError error = daemonUser.Load();
if (error)
throw error.GetMsg();
TGroup daemonGroup("daemon");
error = daemonGroup.Load();
if (error)
throw error.GetMsg();
AsUser(api, daemonUser, daemonGroup);
}
示例4: AsNobody
void AsNobody(TPortoAPI &api) {
TUser nobody(GetDefaultUser());
TError error = nobody.Load();
if (error)
throw error.GetMsg();
TGroup nogroup(GetDefaultGroup());
error = nogroup.Load();
if (error)
throw error.GetMsg();
AsUser(api, nobody, nogroup);
}
示例5: GroupGid
int GroupGid(const std::string &group) {
TGroup g(group);
TError error = g.Load();
if (error)
throw error.GetMsg();
return g.GetId();
}
示例6: UserUid
int UserUid(const std::string &user) {
TUser u(user);
TError error = u.Load();
if (error)
throw error.GetMsg();
return u.GetId();
}
示例7: ReadPid
int ReadPid(const std::string &path) {
int pid = 0;
TError error = TPath(path).ReadInt(pid);
if (error)
throw std::string(error.GetMsg());
return pid;
}
示例8: ReadLink
std::string ReadLink(const std::string &path) {
TPath lnk;
TPath f(path);
TError error = f.ReadLink(lnk);
if (error)
throw error.GetMsg();
return lnk.ToString();
}
示例9: ReadPid
int ReadPid(const std::string &path) {
TFile f(path);
int pid = 0;
TError error = f.AsInt(pid);
if (error)
throw std::string(error.GetMsg());
return pid;
}
示例10: f
std::map<std::string, std::string> GetCgroups(const std::string &pid) {
std::map<std::string, std::string> cgmap;
TFile f("/proc/" + pid + "/cgroup");
std::vector<std::string> lines;
TError error = f.AsLines(lines);
if (error)
throw std::string("Can't get cgroups: " + error.GetMsg());
std::vector<std::string> tokens;
for (auto l : lines) {
tokens.clear();
error = SplitString(l, ':', tokens, 3);
if (error)
throw std::string("Can't get cgroups: " + error.GetMsg());
cgmap[tokens[1]] = tokens[2];
}
return cgmap;
}
示例11: BootstrapCommand
void BootstrapCommand(const std::string &cmd, const TPath &path, bool remove) {
if (remove)
(void)path.RemoveAll();
vector<string> lines;
ExpectSuccess(Popen("ldd " + cmd, lines));
for (auto &line : lines) {
vector<string> tokens;
TError error = SplitString(line, ' ', tokens);
if (error)
throw error.GetMsg();
TPath from;
string name;
if (tokens.size() == 2) {
from = StringTrim(tokens[0]);
TPath p(tokens[0]);
name = p.BaseName();
} else if (tokens.size() == 4) {
if (tokens[2] == "")
continue;
from = StringTrim(tokens[2]);
name = StringTrim(tokens[0]);
} else {
continue;
}
TPath dest = path / from.DirName();
if (!dest.Exists()) {
error = dest.MkdirAll(0755);
if (error)
throw error.GetMsg();
}
Expect(system(("cp " + from.ToString() + " " + dest.ToString() + "/" + name).c_str()) == 0);
}
Expect(system(("cp " + cmd + " " + path.ToString()).c_str()) == 0);
}
示例12: InitUsersAndGroups
void InitUsersAndGroups() {
TError error;
error = Nobody.Load("nobody");
if (error)
throw error.GetMsg();
error = Alice.Load("porto-alice");
if (error)
throw error.GetMsg();
error = Bob.Load("porto-bob");
if (error)
throw error.GetMsg();
ExpectNeq(Alice.Uid, Bob.Uid);
ExpectNeq(Alice.Gid, Bob.Gid);
Expect(!Nobody.IsPortoUser());
Expect(Alice.IsPortoUser());
Expect(Bob.IsPortoUser());
}
示例13: string
std::map<std::string, std::string> GetCgroups(const std::string &pid) {
std::map<std::string, std::string> cgmap;
std::vector<std::string> lines;
TError error = TPath("/proc/" + pid + "/cgroup").ReadLines(lines);
if (error)
throw std::string("Can't get cgroups: " + error.GetMsg());
std::vector<std::string> tokens;
std::vector<std::string> subsys;
for (auto l : lines) {
tokens.clear();
error = SplitString(l, ':', tokens, 3);
if (error)
throw std::string("Can't get cgroups: " + error.GetMsg());
subsys.clear();
SplitString(tokens[1], ',', subsys);
for (auto s : subsys)
cgmap[s] = tokens[2];
}
return cgmap;
}
示例14: PrintError
void ICmd::PrintError(const TError &error, const string &str) {
if (error.GetMsg().length())
std::cerr << str << ": " << ErrorName(error.GetError()) << " (" << error.GetMsg() << ")" << std::endl;
else
std::cerr << str << ": " << ErrorName(error.GetError()) << std::endl;
}