本文整理汇总了C++中TError类的典型用法代码示例。如果您正苦于以下问题:C++ TError类的具体用法?C++ TError怎么用?C++ TError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TError类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:noxiouz,项目名称:porto,代码行数:26,代码来源:test.cpp
示例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();
}
开发者ID:monsterzz,项目名称:porto,代码行数:27,代码来源:client.cpp
示例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;
}
开发者ID:noxiouz,项目名称:porto,代码行数:26,代码来源:cgroup.cpp
示例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;
};
开发者ID:yandex,项目名称:porto,代码行数:59,代码来源:portotest.cpp
示例5: GroupGid
int GroupGid(const std::string &group) {
TGroup g(group);
TError error = g.Load();
if (error)
throw error.GetMsg();
return g.GetId();
}
开发者ID:direvius,项目名称:porto,代码行数:8,代码来源:test.cpp
示例6: UserUid
int UserUid(const std::string &user) {
TUser u(user);
TError error = u.Load();
if (error)
throw error.GetMsg();
return u.GetId();
}
开发者ID:direvius,项目名称:porto,代码行数:8,代码来源:test.cpp
示例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;
}
开发者ID:noxiouz,项目名称:porto,代码行数:9,代码来源:test.cpp
示例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;
}
开发者ID:direvius,项目名称:porto,代码行数:10,代码来源:test.cpp
示例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();
}
开发者ID:noxiouz,项目名称:porto,代码行数:10,代码来源:test.cpp
示例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();
}
开发者ID:noxiouz,项目名称:porto,代码行数:53,代码来源:client.cpp
示例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);
}
开发者ID:direvius,项目名称:porto,代码行数:13,代码来源:test.cpp
示例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);
}
开发者ID:direvius,项目名称:porto,代码行数:13,代码来源:test.cpp
示例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);
}
开发者ID:cdaffara,项目名称:symbiandump-os1,代码行数:18,代码来源:ciftest.cpp
示例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;
}
开发者ID:direvius,项目名称:porto,代码行数:19,代码来源:test.cpp
示例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);
}
开发者ID:noxiouz,项目名称:porto,代码行数:40,代码来源:test.cpp
示例16: 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());
}
开发者ID:noxiouz,项目名称:porto,代码行数:22,代码来源:test.cpp
示例17: GetCgroups
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;
}
开发者ID:noxiouz,项目名称:porto,代码行数:22,代码来源:test.cpp
示例18: 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;
}
开发者ID:noxiouz,项目名称:porto,代码行数:6,代码来源:cli.cpp
示例19: Abort
void TTask::Abort(const TError &error) const {
TError ret = error.Serialize(Wfd);
if (ret)
L_ERR() << ret << std::endl;
exit(EXIT_FAILURE);
}
开发者ID:presto53,项目名称:porto,代码行数:6,代码来源:task.cpp
示例20: CreateCwd
TError TTask::Start() {
int ret;
int pfd[2], syncfd[2];
Pid = 0;
if (Env->CreateCwd) {
TError error = CreateCwd();
if (error) {
if (error.GetError() != EError::NoSpace)
L_ERR() << "Can't create temporary cwd: " << error << std::endl;
return error;
}
}
ExitStatus = 0;
ret = pipe2(pfd, O_CLOEXEC);
if (ret) {
TError error(EError::Unknown, errno, "pipe2(pdf)");
L_ERR() << "Can't create communication pipe for child: " << error << std::endl;
return error;
}
Rfd = pfd[0];
Wfd = pfd[1];
// we want our child to have portod master as parent, so we
// are doing double fork here (fork + clone);
// we also need to know child pid so we are using pipe to send it back
pid_t forkPid = fork();
if (forkPid < 0) {
TError error(EError::Unknown, errno, "fork()");
L() << "Can't spawn child: " << error << std::endl;
close(Rfd);
close(Wfd);
return error;
} else if (forkPid == 0) {
TError error;
SetDieOnParentExit(SIGKILL);
SetProcessName("portod-spawn-p");
char stack[8192];
(void)setsid();
// move to target cgroups
for (auto cg : Env->LeafCgroups) {
error = cg.second->Attach(getpid());
if (error) {
L() << "Can't attach to cgroup: " << error << std::endl;
ReportPid(-1);
Abort(error);
}
}
error = Env->ClientMntNs.SetNs();
if (error) {
L() << "Can't move task to client mount namespace: " << error << std::endl;
ReportPid(-1);
Abort(error);
}
error = ReopenStdio();
if (error) {
ReportPid(-1);
Abort(error);
}
error = Env->ParentNs.Enter();
if (error) {
L() << "Cannot enter namespaces: " << error << std::endl;
ReportPid(-1);
Abort(error);
}
int cloneFlags = SIGCHLD;
if (Env->Isolate)
cloneFlags |= CLONE_NEWPID | CLONE_NEWIPC;
if (Env->NewMountNs)
cloneFlags |= CLONE_NEWNS;
if (!Env->Hostname.empty())
cloneFlags |= CLONE_NEWUTS;
if (Env->NetCfg.NewNetNs)
cloneFlags |= CLONE_NEWNET;
int ret = pipe2(syncfd, O_CLOEXEC);
if (ret) {
TError error(EError::Unknown, errno, "pipe2(pdf)");
L() << "Can't create sync pipe for child: " << error << std::endl;
ReportPid(-1);
Abort(error);
}
WaitParentRfd = syncfd[0];
//.........这里部分代码省略.........
开发者ID:presto53,项目名称:porto,代码行数:101,代码来源:task.cpp
注:本文中的TError类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论