Closed masatake closed 2 months ago
Checker::Checker() {
fs::path tmp_dir = fs::temp_directory_path() / ("pegof_" + std::to_string(time(0)));
time(2) System Calls Manual time(2)
NAME
time - get time in seconds
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <time.h>
time_t time(time_t *_Nullable tloc);
DESCRIPTION
time() returns the time as the number of seconds since the Epoch,
1970-01-01 00:00:00 +0000 (UTC).
Using mkstemp may be better.
mkstemp()
POSIX.1-2001.
diff --git a/src/checker.cc b/src/checker.cc
index 28c3a0a..e29f8fa 100644
--- a/src/checker.cc
+++ b/src/checker.cc
@@ -42,7 +42,8 @@ std::string Stats::compare(const Stats& s) const {
}
Checker::Checker() {
- fs::path tmp_dir = fs::temp_directory_path() / ("pegof_" + std::to_string(time(0)));
+ fs::path tmp_dir = fs::temp_directory_path() / ("pegof_" + std::to_string(time(0))
+ + "_" + std::to_string(getpid()));
output = (tmp_dir / "output").native();
tmp = tmp_dir.native();
fs::create_directory(tmp_dir);
This works. However, the name of the directory is predictable.
I've fixed it using mkdtemp
, see #13.
I'm intergrating pegof to the build script of Universal Ctags (https://github.com/universal-ctags/ctags/pull/4026).
During integration, I found pegof processes suddenly died when I passed -j16 option to make. I inspected it. It seemed that pegof used current time with second resolution:
Using higher resolution, or mixing process id, or something technique is needed.