提交 4b394592 编写于 作者: S Simon Fels

cmds: add command to check for mandatory CPU features

上级 5909a067
#!/bin/bash
if [ "$SNAP_ARCH" == "amd64" ]; then
if [ "$SNAP_ARCH" = "amd64" ]; then
ARCH="x86_64-linux-gnu"
elif [ "$SNAP_ARCH" == "armhf" ]; then
elif [ "$SNAP_ARCH" = "armhf" ]; then
ARCH="arm-linux-gnueabihf"
else
ARCH="$SNAP_ARCH-linux-gnu"
......@@ -11,10 +11,12 @@ fi
# With recent builds on Ubuntu 16.04 the snap does not find the path to
# libpulsecommon-8.0.so anymore so we have to teach the linker manually
# where it can be found
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH/pulseaudio
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH/pulseaudio"
# liblxc.so.1 is in $SNAP/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/lib
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/lib"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH"
# We set XDG_DATA_HOME to SNAP_USER_COMMON here as this will be the location we will
# create all our application launchers in. The system application launcher will
......
#!/bin/sh
# If not all feature checks pass we fail the Anbox installation
exec $SNAP/bin/desktop-launch $SNAP/bin/anbox-wrapper.sh check-features
......@@ -100,6 +100,8 @@ set(SOURCES
anbox/cmds/version.h
anbox/cmds/wait_ready.cpp
anbox/cmds/wait_ready.h
anbox/cmds/check_features.cpp
anbox/cmds/check_features.h
anbox/common/binary_writer.cpp
anbox/common/binary_writer.h
......
/*
* Copyright (C) 2018 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "anbox/cmds/check_features.h"
#include "cpu_features_macros.h"
#include "cpuinfo_x86.h"
anbox::cmds::CheckFeatures::CheckFeatures()
: CommandWithFlagsAndAction{
cli::Name{"check-features"}, cli::Usage{"check-features"},
cli::Description{"Check that the host system supports all necessary features"}} {
action([this](const cli::Command::Context&) {
#if defined(CPU_FEATURES_ARCH_X86)
const auto info = cpu_features::GetX86Info();
std::vector<std::string> missing_features;
#define CHECK_BOOL(x, name) \
if (!x) \
missing_features.push_back(name)
CHECK_BOOL(info.features.sse4_1, "SSE 4.1");
CHECK_BOOL(info.features.sse4_2, "SSE 4.2");
CHECK_BOOL(info.features.ssse3, "SSSE 3");
if (missing_features.size() > 0) {
std::cerr << "Your computer does not meet the requirements to run Anbox. You're missing" << std::endl
<< "support for the following features: ";
for (size_t n = 0; n < missing_features.size(); n++) {
const auto feature = missing_features[n];
std::cerr << feature;
if (n < missing_features.size() - 1)
std::cerr << ", ";
}
std::cerr << std::endl;
return EXIT_FAILURE;
}
std::cout << "Your computer does meet all requirements to run Anbox" << std::endl;
return EXIT_SUCCESS;
#else
std::cerr << "You're running Anbox on a not yet supported architecture" << std::endl;
return EXIT_FAILURE;
#endif
});
}
/*
* Copyright (C) 2018 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ANBOX_CMDS_CHECK_FEATURES_H_
#define ANBOX_CMDS_CHECK_FEATURES_H_
#include <functional>
#include <iostream>
#include <memory>
#include "anbox/cli.h"
namespace anbox {
namespace cmds {
class CheckFeatures : public cli::CommandWithFlagsAndAction {
public:
CheckFeatures();
};
} // namespace cmds
} // namespace anbox
#endif
......@@ -28,6 +28,7 @@
#include "anbox/cmds/launch.h"
#include "anbox/cmds/version.h"
#include "anbox/cmds/wait_ready.h"
#include "anbox/cmds/check_features.h"
#include <boost/filesystem.hpp>
......@@ -42,7 +43,8 @@ Daemon::Daemon()
.command(std::make_shared<cmds::Launch>())
.command(std::make_shared<cmds::ContainerManager>())
.command(std::make_shared<cmds::SystemInfo>())
.command(std::make_shared<cmds::WaitReady>());
.command(std::make_shared<cmds::WaitReady>())
.command(std::make_shared<cmds::CheckFeatures>());
Log().Init(anbox::Logger::Severity::kWarning);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册