29 #if !defined(_MSC_VER) 43 #if !defined(_MSC_VER) 44 if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
45 throw ErrnoException(
"Error setting FD_CLOEXEC on file descriptor");
54 if (pipe2(out_pipefds, O_CLOEXEC) != 0)
56 #elif defined(_MSC_VER) 57 if (_pipe(out_pipefds, 256,
O_BINARY) != 0)
60 if (pipe(out_pipefds) != 0)
71 pid_t mypid = getpid();
74 if (!proc.good())
return;
76 std::vector<std::string> args;
78 while (std::getline(proc, arg,
'\0'))
79 args.emplace_back(arg);
84 std::string::size_type slashpos = prog.rfind(
'/');
85 if (slashpos != std::string::npos)
86 prog = prog.substr(slashpos + 1);
89 std::ostringstream cmdline;
90 for (
size_t i = 0; i < args.size(); ++i) {
96 if (arg.find(
'"') != std::string::npos)
101 logger <<
"class" <<
"Cmdline" 102 <<
"event" <<
"start" 105 <<
"cmdline" << cmdline.str();
112 #if __linux__ && !THRILL_ON_TRAVIS 115 CPU_SET(cpu_id % std::thread::hardware_concurrency(), &cpuset);
116 int rc = pthread_setaffinity_np(
117 thread.native_handle(),
sizeof(cpu_set_t), &cpuset);
119 LOG1 <<
"Error calling pthread_setaffinity_np(): " 120 << rc <<
": " << strerror(errno);
129 #if __linux__ && !THRILL_ON_TRAVIS 132 CPU_SET(cpu_id % std::thread::hardware_concurrency(), &cpuset);
133 int rc = pthread_setaffinity_np(pthread_self(),
sizeof(cpu_set_t), &cpuset);
135 LOG1 <<
"Error calling pthread_setaffinity_np(): " 136 << rc <<
": " << strerror(errno);
146 gethostname(buffer, 64);
149 return "<unknown host>";
154 static std::mutex s_mutex;
155 std::unique_lock<std::mutex> lock(s_mutex);
156 return ::readdir(dirp);
void LogCmdlineParams(JsonLogger &logger)
An Exception which is thrown on system errors and contains errno information.
void PortSetCloseOnExec(int fd)
set FD_CLOEXEC on file descriptor (if possible)
void MakePipe(int out_pipefds[2])
create a pair of pipe file descriptors
static by_string to_string(int val)
convert to string
std::string & replace_all(std::string *str, const std::string &needle, const std::string &instead)
Replace all occurrences of needle in str.
std::string GetHostname()
get hostname
struct dirent * ts_readdir(DIR *dirp)
mutex-locked readdir() call
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
JsonLogger is a receiver of JSON output objects for logging.
void SetCpuAffinity(std::thread &thread, size_t cpu_id)
set cpu/core affinity of a thread