예제 #1
0
파일: test.cpp 프로젝트: noxiouz/porto
void AsRoot(Porto::Connection &api) {
    api.Close();

    ExpectEq(seteuid(0), 0);
    ExpectEq(setegid(0), 0);
    ExpectEq(setgroups(0, nullptr), 0);
}
예제 #2
0
파일: test.cpp 프로젝트: noxiouz/porto
void TestDaemon(Porto::Connection &api) {
    struct dirent **lst;
    int pid;

    AsRoot(api);

    api.Close();
    sleep(1);

    Say() << "Make sure portod-slave doesn't have zombies" << std::endl;
    pid = ReadPid(config().slave_pid().path());
    ExpectEq(ChildrenNum(pid), 0);

    Say() << "Make sure portod-slave doesn't have invalid FDs" << std::endl;

    std::string path = ("/proc/" + std::to_string(pid) + "/fd");

    // when sssd is running getgrnam opens unix socket to read database
    int sssFd = 0;
    if (WordCount("/etc/nsswitch.conf", "sss"))
        sssFd = 3;

    /**
     * .
     * ..
     * 0 (stdin)
     * 1 (stdout)
     * 128 (event pipe)
     * 129 (ack pipe)
     * 130 (rpc socket)
     * 2 (stderr)
     * 3 (portod.log)
     * 4 (epoll)
     * 5 (host netlink)
     * 6 (signalfd)
     */
    int nr = scandir(path.c_str(), &lst, NULL, alphasort);
    PrintFds(path, lst, nr);
    ExpectLessEq(nr, 12 + sssFd);
    ExpectLessEq(12, nr);

    Say() << "Make sure portod-master doesn't have zombies" << std::endl;
    pid = ReadPid(config().master_pid().path());
    ExpectEq(ChildrenNum(pid), 1);

    Say() << "Make sure portod-master doesn't have invalid FDs" << std::endl;
    Say() << "Number of portod-master fds=" << nr << std::endl;
    path = ("/proc/" + std::to_string(pid) + "/fd");
    /**
     * .
     * ..
     * 0 (stdin)
     * 1 (stdout)
     * 130 (rpc socket)
     * 2 (stderr)
     * 3 (portoloop.log)
     * 4 (epoll)
     * 6 (event pipe)
     * 7 (ack pipe)
     * 9 (signalfd)
     */
    nr = scandir(path.c_str(), &lst, NULL, alphasort);
    PrintFds(path, lst, nr);
    ExpectLessEq(nr, 11 + sssFd);
    ExpectLessEq(11, nr);

    Say() << "Check portod-master queue size" << std::endl;
    std::string v;
    ExpectApiSuccess(api.GetData("/", "porto_stat[queued_statuses]", v));
    Expect(v == std::to_string(0));

    Say() << "Check portod-slave queue size" << std::endl;
    ExpectApiSuccess(api.GetData("/", "porto_stat[queued_events]", v));
    Expect(v != std::to_string(0)); // RotateLogs

    // TODO: check rtnl classes
}