本文整理汇总了C++中TError类的典型用法代码示例。如果您正苦于以下问题:C++ TError类的具体用法?C++ TError怎么用?C++ TError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sizeof
TError TClient::AcceptConnection(TContext &context, int listenFd) {
struct sockaddr_un peer_addr;
socklen_t peer_addr_size;
TError error;
peer_addr_size = sizeof(struct sockaddr_un);
Fd = accept4(listenFd, (struct sockaddr *) &peer_addr,
&peer_addr_size, SOCK_NONBLOCK | SOCK_CLOEXEC);
if (Fd < 0) {
error = TError(EError::Unknown, errno, "accept4()");
if (error.GetErrno() != EAGAIN)
L_WRN() << "Cannot accept client: " << error << std::endl;
return error;
}
error = IdentifyClient(*context.Cholder, true);
if (error) {
close(Fd);
Fd = -1;
return error;
}
if (Verbose)
L() << "Client connected: " << *this << std::endl;
return TError::Success();
}
示例3: TError
TError TCgroup::Remove() const {
struct stat st;
TError error;
if (Secondary())
return TError(EError::Unknown, "Cannot create secondary cgroup " + Type());
L_ACT() << "Remove cgroup " << *this << std::endl;
error = Path().Rmdir();
/* workaround for bad synchronization */
if (error && error.GetErrno() == EBUSY &&
!Path().StatStrict(st) && st.st_nlink == 2) {
for (int i = 0; i < 100; i++) {
usleep(config().daemon().cgroup_remove_timeout_s() * 10000);
error = Path().Rmdir();
if (!error || error.GetErrno() != EBUSY)
break;
}
}
if (error && (error.GetErrno() != ENOENT || Exists()))
L_ERR() << "Cannot remove cgroup " << *this << " : " << error << std::endl;
return error;
}
示例4: 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;
};
示例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: 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;
}
示例9: 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();
}
示例10: sizeof
TError TClient::IdentifyClient(TContainerHolder &holder, bool initial) {
std::shared_ptr<TContainer> ct;
struct ucred cr;
socklen_t len = sizeof(cr);
TError error;
if (getsockopt(Fd, SOL_SOCKET, SO_PEERCRED, &cr, &len))
return TError(EError::Unknown, errno, "Cannot identify client: getsockopt() failed");
/* check that request from the same pid and container is still here */
if (!initial && Pid == cr.pid && TaskCred.Uid == cr.uid &&
TaskCred.Gid == cr.gid && !ClientContainer.expired())
return TError::Success();
TaskCred.Uid = cr.uid;
TaskCred.Gid = cr.gid;
Pid = cr.pid;
error = holder.FindTaskContainer(Pid, ct);
if (error && error.GetErrno() != ENOENT)
L_WRN() << "Cannot identify container of pid " << Pid
<< " : " << error << std::endl;
if (error)
return error;
if (!ct->IsPortoEnabled())
return TError(EError::Permission,
"Porto disabled in container " + ct->GetName());
ClientContainer = ct;
error = TPath("/proc/" + std::to_string(Pid) + "/comm").ReadAll(Comm, 64);
if (error)
Comm = "<unknown process>";
else
Comm.resize(Comm.length() - 1); /* cut \n at the end */
if (ct->IsRoot()) {
Cred.Uid = cr.uid;
Cred.Gid = cr.gid;
error = LoadGroups();
if (error && error.GetErrno() != ENOENT)
L_WRN() << "Cannot load supplementary group list" << Pid
<< " : " << error << std::endl;
} else {
/* requests from containers are executed in behalf of their owners */
Cred = ct->OwnerCred;
}
ReadOnlyAccess = !Cred.IsPortoUser();
return TError::Success();
}
示例11: 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);
}
示例12: 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);
}
示例13: HandleParserComplete
void CCmdCifTest::HandleParserComplete(CParser& /*aParser*/, const TError& aError)
{
TInt err = aError.Error();
if (err)
{
iFailures++;
PrintError(err, _L("%S failed at line %d"), &aError.ScriptFileName(), aError.ScriptLineNumber());
}
else
{
if (iVerbose)
{
Printf(_L("Smoketest for %S completed ok.\r\n"), &iCurrentCif->Name());
}
iPasses++;
}
TestCompleted(err);
}
示例14: GetCgroups
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;
}
示例15: 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);
}