// This symlink will cause infinite recursion. It should not be followed.
std::filesystem::create_directory_symlink(scratch_path_ + "/abc/aaa/bbb/pqr",
scratch_path_ + "/abc/aaa/bbb/pqr/lnk");
// This is a directory. It should not be included in the results.
std::filesystem::create_directory(scratch_path_ + "/abc/def/ghi/000.txt");
// Paths that shouldn't be matched if the paths above are escaped.
CreateFile(scratch_path_ + "/abc/b.txt");
CreateFile(scratch_path_ + "/b.txt");
CreateFile(scratch_path_ + "/*b.txt");
CreateFile(scratch_path_ + "/?b.txt");
CreateFile(scratch_path_ + "/[a-zb]b.txt");
// Verifies that the escaped path only matches the given path. auto verify_escape = [this](const std::string& file) {
EXPECT_THAT(Glob({EscapeGlob(file)}, scratch_path_), UnorderedElementsAre(file));
};
// Check the current status of the process with `WNOHANG`. The related process should have exited, // so `si_signo` should be `SIGCHLD`.
siginfo_t info;
ASSERT_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid_1, &info, WEXITED | WNOWAIT | WNOHANG)), 0);
EXPECT_EQ(info.si_signo, SIGCHLD);
EXPECT_EQ(info.si_code, CLD_EXITED);
EXPECT_EQ(info.si_status, 0);
// The method should not wait on unrelated processes. The unrelated process should not have // exited, so `si_signo` should be 0.
ASSERT_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid_2, &info, WEXITED | WNOWAIT | WNOHANG)), 0);
EXPECT_EQ(info.si_signo, 0);
}
TEST_F(ArtToolsEnsureNoProcessInDirTest, TimesOut) {
std::vector<std::string> args{related_dir_ + "/sleep", "5"}; auto [pid, scope_guard] = ScopedExec(args, /*wait=*/false);
NanoSleep(100'000'000); // Wait for child processes to exec.
Result<void> result = EnsureNoProcessInDir(related_dir_, /*timeout_ms=*/200, /*try_kill=*/false);
EXPECT_FALSE(result.ok());
EXPECT_EQ(result.error().message(), "Some process(es) are still running after 200ms");
// The process should not have exited.
siginfo_t info;
ASSERT_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid, &info, WEXITED | WNOWAIT | WNOHANG)), 0);
EXPECT_EQ(info.si_signo, 0);
}
TEST_F(ArtToolsEnsureNoProcessInDirTest, KillsProcesses) {
std::vector<std::string> args_1{related_dir_ + "/sleep", "5"}; auto [pid_1, scope_guard_1] = ScopedExec(args_1, /*wait=*/false);
std::vector<std::string> args_2{unrelated_dir_ + "/sleep", "5"}; auto [pid_2, scope_guard_2] = ScopedExec(args_2, /*wait=*/false);
NanoSleep(100'000'000); // Wait for child processes to exec.
// The related process should have been killed.
siginfo_t info;
ASSERT_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid_1, &info, WEXITED | WNOWAIT | WNOHANG)), 0);
EXPECT_EQ(info.si_signo, SIGCHLD);
EXPECT_EQ(info.si_code, CLD_KILLED);
EXPECT_EQ(info.si_status, SIGKILL);
// The unrelated process should still be running.
ASSERT_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid_2, &info, WEXITED | WNOWAIT | WNOHANG)), 0);
EXPECT_EQ(info.si_signo, 0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.