当前位置: 首页>>代码示例>>C++>>正文


C++ TError::GetErrno方法代码示例

本文整理汇总了C++中TError::GetErrno方法的典型用法代码示例。如果您正苦于以下问题:C++ TError::GetErrno方法的具体用法?C++ TError::GetErrno怎么用?C++ TError::GetErrno使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TError的用法示例。


在下文中一共展示了TError::GetErrno方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Remove

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

示例2: IdentifyClient

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

示例3: AcceptConnection

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

示例4: IdentifyClient

TError TClient::IdentifyClient(TContainerHolder &holder, bool initial) {
    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");

    if (!initial && Pid == cr.pid && Cred.Uid == cr.uid && Cred.Gid == cr.gid &&
            !ClientContainer.expired())
        return TError::Success();

    Cred.Uid = cr.uid;
    Cred.Gid = cr.gid;
    Pid = cr.pid;

    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 */

    error = LoadGroups();
    if (error && error.GetErrno() != ENOENT)
        L_WRN() << "Cannot load supplementary group list" << Pid
                << " : " << error << std::endl;

    ReadOnlyAccess = !Cred.IsPortoUser();

    std::shared_ptr<TContainer> container;
    error = holder.FindTaskContainer(Pid, container);
    if (error && error.GetErrno() != ENOENT)
        L_WRN() << "Cannot identify container of pid " << Pid
                << " : " << error << std::endl;
    if (error)
        return error;

    if (!container->Prop->Get<bool>(P_ENABLE_PORTO))
        return TError(EError::Permission, "Porto disabled in container " + container->GetName());

    ClientContainer = container;
    return TError::Success();
}
开发者ID:monsterzz,项目名称:porto,代码行数:43,代码来源:client.cpp


注:本文中的TError::GetErrno方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。