}
}
-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(std::string_view dir, std::string_view path)
{
// `path` has no file extension, an empty string_view is returned.
std::string_view get_extension(std::string_view path);
-// 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
}
LOG("Command line: {}", util::format_argv_for_logging(argv));
- LOG("Hostname: {}", Util::get_hostname());
+ LOG("Hostname: {}", util::get_hostname());
LOG("Working directory: {}", ctx.actual_cwd);
if (ctx.apparent_cwd != ctx.actual_cwd) {
LOG("Apparent working directory: {}", ctx.apparent_cwd);
#include <core/wincompat.hpp>
#include <util/file.hpp>
#include <util/filesystem.hpp>
+#include <util/process.hpp>
#include "third_party/fmt/core.h"
LockFile::do_acquire(const bool blocking)
{
std::stringstream ss;
- ss << Util::get_hostname() << '-' << getpid() << '-'
- << std::this_thread::get_id();
+ ss << get_hostname() << '-' << getpid() << '-' << std::this_thread::get_id();
const auto content_prefix = ss.str();
util::TimePoint last_seen_activity = [this] {
#include <core/wincompat.hpp>
+#include <cstring>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
namespace {
// Process umask, read and written by get_umask and set_umask.
namespace util {
+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;
+}
+
mode_t
get_umask()
{
namespace util {
+// Return a static string with the current hostname.
+const char* get_hostname();
+
// Get process umask.
mode_t get_umask();