Skip to content

Commit

Permalink
Direcly call uname for linux detection
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Jun 26, 2023
1 parent c9770b1 commit 6c7c47e
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions libmamba/src/core/util_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <clocale>

#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <unistd.h>
#if defined(__APPLE__)
#include <libproc.h>
Expand All @@ -21,14 +22,15 @@
// Incomplete header included last
#include <tlhelp32.h>
#include <WinReg.hpp>

#include "mamba/core/context.hpp"
#endif

#include <fmt/color.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <reproc++/run.hpp>

#include "mamba/core/context.hpp"
#include "mamba/core/environment.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/util.hpp"
Expand Down Expand Up @@ -322,25 +324,19 @@ namespace mamba
return "";
}

std::string out, err;
std::vector<std::string> args = { "uname", "-r" };
auto [status, ec] = reproc::run(
args,
reproc::options{},
reproc::sink::string(out),
reproc::sink::string(err)
);

if (ec)
#ifndef _WIN32
struct utsname uname_result = {};
const auto ret = ::uname(&uname_result);
if (ret != 0)
{
LOG_DEBUG << "Could not find linux version by calling 'uname -r' (skipped)";
return "";
LOG_DEBUG << "Error calling uname (skipping): "
<< std::system_error(errno, std::generic_category()).what();
}

std::regex re("([0-9]+\\.[0-9]+\\.[0-9]+)(?:-.*)?");
static const std::regex re("([0-9]+\\.[0-9]+\\.[0-9]+)(?:-.*)?");
std::smatch m;

if (std::regex_search(out, m, re))
std::string const version = uname_result.release;
if (std::regex_search(version, m, re))
{
if (m.size() == 2)
{
Expand All @@ -351,6 +347,7 @@ namespace mamba
}

LOG_DEBUG << "Could not parse linux version";
#endif

return "";
}
Expand Down

0 comments on commit 6c7c47e

Please sign in to comment.