while (true) {
std::string my_content =
- fmt::format("{}:{}:{}", get_hostname(), getpid(), time(nullptr));
+ fmt::format("{}:{}:{}", Util::get_hostname(), getpid(), time(nullptr));
if (symlink(my_content.c_str(), lockfile.c_str()) == 0) {
// We got the lock.
progress_receiver(1.0);
}
+const char*
+get_hostname()
+{
+ static char hostname[260] = "";
+
+ if (hostname[0]) {
+ return hostname;
+ }
+
+ if (gethostname(hostname, sizeof(hostname)) != 0) {
+ strcpy(hostname, "unknown");
+ }
+ hostname[sizeof(hostname) - 1] = 0;
+ return hostname;
+}
+
std::string
get_relative_path(string_view dir, string_view path)
{
const ProgressReceiver& progress_receiver,
std::vector<std::shared_ptr<CacheFile>>& files);
+// Return a static string with the current hostname.
+const char* get_hostname();
+
// Compute a relative path from `dir` (an absolute path to a directory) to
// `path` (an absolute path). Assumes that both `dir` and `path` are normalized.
// The algorithm does *not* follow symlinks, so the result may not actually
MTR_END("main", "set_up_uncached_err");
cc_log_argv("Command line: ", argv);
- cc_log("Hostname: %s", get_hostname());
+ cc_log("Hostname: %s", Util::get_hostname());
cc_log("Working directory: %s", ctx.actual_cwd.c_str());
if (ctx.apparent_cwd != ctx.actual_cwd) {
cc_log("Apparent working directory: %s", ctx.apparent_cwd.c_str());
# include <sys/time.h>
#endif
-// Return a static string with the current hostname.
-const char*
-get_hostname()
-{
- static char hostname[260] = "";
-
- if (hostname[0]) {
- return hostname;
- }
-
- if (gethostname(hostname, sizeof(hostname)) != 0) {
- strcpy(hostname, "unknown");
- }
- hostname[sizeof(hostname) - 1] = 0;
- return hostname;
-}
-
// This is like setenv.
void
x_setenv(const char* name, const char* value)
#include <string>
-const char* get_hostname();
void x_setenv(const char* name, const char* value);
void x_unsetenv(const char* name);
#ifndef HAVE_LOCALTIME_R