From 4bf7b3d38f24110f162bd911e99a339176d4c488 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 2 Feb 2022 18:10:35 +0100 Subject: [PATCH] Manager: Put machine information fetching in separate functions --- src/machine.cpp | 23 +++++++++++++++++++---- src/machine.h | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index b7daeea..2068580 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -12,6 +12,19 @@ #include "util/file.h" Machine::Machine(s) +{ + fetchDistro(); + fetchHostname(); + fetchUsername(); +} + +Machine::~Machine() +{ +} + +// ----------------------------------------- + +void Machine::fetchDistro() { Util::File osRelease("/etc/os-release"); std::istringstream stream(osRelease.data()); @@ -23,13 +36,19 @@ Machine::Machine(s) m_distroIdLike = line.substr(8); } } +} +void Machine::fetchHostname() +{ char hostname[64] { 0 }; if (gethostname(hostname, 64) < 0) { perror("\033[31;1mError:\033[0m gethostname"); } m_hostname = hostname; +} +void Machine::fetchUsername() +{ // Get the username logged in on the controlling terminal of the process char username[32] { 0 }; if (getlogin_r(username, 32) != 0) { @@ -42,7 +61,3 @@ Machine::Machine(s) perror("\033[31;1mError:\033[0m getpwnam"); } } - -Machine::~Machine() -{ -} diff --git a/src/machine.h b/src/machine.h index 547ed1e..b5b92c7 100644 --- a/src/machine.h +++ b/src/machine.h @@ -27,6 +27,10 @@ public: uint32_t gid() { return m_passwd->pw_gid; } private: + void fetchDistro(); + void fetchHostname(); + void fetchUsername(); + std::string m_distroId; std::string m_distroIdLike; std::string m_hostname;