]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move get_hostname to Util
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 30 Jul 2020 05:16:00 +0000 (07:16 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 30 Jul 2020 19:04:01 +0000 (21:04 +0200)
src/Lockfile.cpp
src/Util.cpp
src/Util.hpp
src/ccache.cpp
src/legacy_util.cpp
src/legacy_util.hpp

index e07d0c2c71af9543b4b6372cab88f090025907b1..97e31b1e4876727298e4a56b3af906ce84dc67c3 100644 (file)
@@ -42,7 +42,7 @@ do_acquire_posix(const std::string& lockfile, uint32_t staleness_limit)
 
   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.
index a6db3ccb10e8fd722346ad3008c44634402389cd..fd19e1a4cabf5d9332150a6479192d396d03759a 100644 (file)
@@ -590,6 +590,22 @@ get_level_1_files(const std::string& dir,
   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)
 {
index 7028caf8a1a4a9df182738ad84e8f1d157293054..ef9a3a247cda7485a62ac13365e95d25f06f146f 100644 (file)
@@ -190,6 +190,9 @@ void get_level_1_files(const std::string& dir,
                        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
index b2c4d9b4831da3343e8c727cc1d0e1174dcfb6a4..a5d36099e190f6994136bb43eab60af03f5d5f92 100644 (file)
@@ -1971,7 +1971,7 @@ do_cache_compilation(Context& ctx, const char* const* argv)
   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());
index fe7cbd94b0d9332ee026c0ad6feeee17e34087a3..aa962abcfd6d4acb6ebc79130982041f0daea265 100644 (file)
 #  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)
index e91fba8df29be0047647f39b9924cb8325c284bb..8b39c63f2ce537d15dd52feb7e3d70f3f2b57ffc 100644 (file)
@@ -22,7 +22,6 @@
 
 #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