zwoop commented on code in PR #12230: URL: https://github.com/apache/trafficserver/pull/12230#discussion_r2131232038
########## plugins/header_rewrite/parser.cc: ########## @@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line) _tokens.push_back(line.substr(cur_token_start)); } } + +// This is the universal configuration reader, which can read both +// a raw file, as well as executing an external compiler (hrw4u) to parse +// the configuration file. +namespace +{ +void +_log_stderr(int fd) +{ + char buffer[512]; + std::string partial; + + while (ssize_t n = read(fd, buffer, sizeof(buffer))) { + if (n <= 0) + break; Review Comment: Fixed, clang-format did not seem to catch this. ########## plugins/header_rewrite/parser.cc: ########## @@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line) _tokens.push_back(line.substr(cur_token_start)); } } + +// This is the universal configuration reader, which can read both +// a raw file, as well as executing an external compiler (hrw4u) to parse +// the configuration file. +namespace +{ +void +_log_stderr(int fd) +{ + char buffer[512]; + std::string partial; + + while (ssize_t n = read(fd, buffer, sizeof(buffer))) { + if (n <= 0) + break; + partial.append(buffer, n); + size_t pos = 0; + while ((pos = partial.find('\n')) != std::string::npos) { + std::string line = partial.substr(0, pos); + TSError("[header_rewrite: hrw4u] %s", line.c_str()); + partial.erase(0, pos + 1); + } + } + + if (!partial.empty()) { + TSError("[hrw4u] stderr: %s", partial.c_str()); + } + + close(fd); +} +} // namespace + +std::optional<ConfReader> +openConfig(const std::string &filename) +{ + namespace fs = std::filesystem; + const std::string suffix = ".hrw4u"; + std::string hrw4u = Layout::get()->bindir + "/traffic_hrw4u"; + + static const bool has_compiler = [hrw4u]() { + fs::path path(hrw4u); + std::error_code ec; + auto status = fs::status(path, ec); + auto perms = status.permissions(); + return fs::exists(path, ec) && fs::is_regular_file(path, ec) && (perms & fs::perms::owner_exec) != fs::perms::none; + }(); + + if (filename.ends_with(suffix) && has_compiler) { + int pipe_fds[2]; + int stderr_pipe[2]; + + if (pipe(pipe_fds) != 0 || pipe(stderr_pipe) != 0) { + return std::nullopt; + } + + pid_t pid = fork(); + if (pid < 0) { + return std::nullopt; Review Comment: Added. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@trafficserver.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org