Skip to content

Commit

Permalink
Refactor: Detect proxy environment variable on daemon start (#358)
Browse files Browse the repository at this point in the history
Signed-off-by: xiafeng <xiafeng.li@foxmail.com>
  • Loading branch information
L-Xiafeng authored Nov 12, 2024
1 parent b4b364c commit 1273f69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CraneCtld/CraneCtld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ int StartServer() {
CRANE_ERROR("Unable to set file descriptor limits to {}", file_max);
std::exit(1);
}
util::os::CheckProxyEnvironmentVariable();

CreateFolders();

Expand Down
1 change: 1 addition & 0 deletions src/Craned/Craned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ void StartServer() {

// Set FD_CLOEXEC on stdin, stdout, stderr
util::os::SetCloseOnExecOnFdRange(STDIN_FILENO, STDERR_FILENO + 1);
util::os::CheckProxyEnvironmentVariable();
g_server = std::make_unique<Craned::CranedServer>(g_config.ListenConf);
std::this_thread::sleep_for(std::chrono::milliseconds(500));

Expand Down
25 changes: 25 additions & 0 deletions src/Utilities/PublicHeader/OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ bool SetMaxFileDescriptorNumber(unsigned long num) {
return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
}

bool CheckProxyEnvironmentVariable() {
bool has_proxy = false;
const char* HTTP_PROXY = std::getenv("HTTP_PROXY");
if (HTTP_PROXY) {
has_proxy = true;
CRANE_WARN("HTTP_PROXY is set to {}", HTTP_PROXY);
}
const char* http_proxy = std::getenv("http_proxy");
if (http_proxy) {
has_proxy = true;
CRANE_WARN("http_proxy is set to {}", http_proxy);
}
const char* HTTPS_PROXY = std::getenv("HTTPS_PROXY");
if (HTTPS_PROXY) {
has_proxy = true;
CRANE_WARN("HTTPS_PROXY is set to {}", HTTPS_PROXY);
}
const char* https_proxy = std::getenv("https_proxy");
if (https_proxy) {
has_proxy = true;
CRANE_WARN("https_proxy is set to {}", https_proxy);
}
return has_proxy;
}

bool GetSystemReleaseInfo(SystemRelInfo* info) {
#if defined(__linux__) || defined(__unix__)
utsname utsname_info{};
Expand Down
2 changes: 2 additions & 0 deletions src/Utilities/PublicHeader/include/crane/OS.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ bool SetMaxFileDescriptorNumber(unsigned long num);

bool GetSystemReleaseInfo(SystemRelInfo* info);

bool CheckProxyEnvironmentVariable();

absl::Time GetSystemBootTime();

} // namespace os
Expand Down

0 comments on commit 1273f69

Please sign in to comment.