Skip to content

Commit

Permalink
Merge pull request #23 from synacker/bug/fix_empty_host
Browse files Browse the repository at this point in the history
Bug/fix empty host
  • Loading branch information
synacker authored Jun 19, 2020
2 parents d1a21a3 + 35eac1a commit d8bf564
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 29 deletions.
26 changes: 18 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ jobs:
docker:
- image: synacker2/daggy_linux_gcc8_debian:2.0.0
user: daggy
environment:
CONAN_USER_HOME: ~/
working_directory: ~/build
steps:
- checkout:
path: ~/daggy
- restore_cache:
key: conan-cache-{{ arch }}
key: conan-data-{{ arch }}
- run:
name: Install or update conan
command: pip3 install conan --upgrade
Expand All @@ -23,14 +25,14 @@ jobs:
command: conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan || true
- run:
name: Conan install
command: conan install ../daggy
command: conan install ../daggy --build=missing
- run:
name: Conan build
command: conan build ../daggy
- save_cache:
key: conan-cache-{{ arch }}
key: conan-data-{{ arch }}
paths:
- ~/.conan
- ~/.conan/data
- run:
name: Pack artefacts
command: cpack
Expand All @@ -46,6 +48,8 @@ jobs:
msvs2019:
executor: win/default
working_directory: ~/build
environment:
CONAN_USER_HOME: ~/
steps:
- run:
name: Install CMake
Expand All @@ -61,7 +65,9 @@ jobs:
- checkout:
path: ~/daggy
- restore_cache:
key: conan-cache-{{ arch }}
key: conan-data-{{ arch }}
- restore_cache:
key: conan-{{ arch }}
- run:
name: Install or update conan
command: pip install conan --upgrade
Expand All @@ -70,14 +76,18 @@ jobs:
command: $(conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan) -or $(true)
- run:
name: Conan install
command: conan install ../daggy
command: conan install ../daggy --build=missing
- run:
name: Conan build
command: conan build ../daggy
- save_cache:
key: conan-cache-{{ arch }}
key: conan-data-{{ arch }}
paths:
- ~/.conan
- ~/.conan/data
- save_cache:
key: conan-{{ arch }}
paths:
- c:\.conan\
- run:
name: Pack artefacts
command: '& "c:/Program Files/CMake/bin/cpack.exe"'
Expand Down
4 changes: 2 additions & 2 deletions cmake/conan_cmake_wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ endmacro()

macro(conan_cmake_run)
parse_arguments(${ARGV})

if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES)
message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators")
elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE)
Expand Down Expand Up @@ -607,4 +607,4 @@ macro(conan_config_install)

message(STATUS "Conan: Installing config from ${CONAN_ITEM}")
execute_process(COMMAND ${CONAN_CMD} config install ${CONAN_CONFIG_INSTALL_ARGS} ${CONAN_ITEM})
endmacro()
endmacro()
34 changes: 30 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

class DaggyConan(ConanFile):
name = "daggy"
version = GitVersion().full_version()
license = "MIT"
url = "https://daggy.dev"
description = "Data Aggregation Utilty - aggregation and stream data via remote and local processes."
Expand All @@ -50,8 +49,12 @@ class DaggyConan(ConanFile):
exports = ["CMakeLists.txt", "git_version.py", "cmake/*", "src/*"]
export_sources = ["src/*"]

def set_version(self):
self.version = GitVersion().full_version()

def requirements(self):
self.requires("qt/[>=5.14.1]@bincrafters/stable")
self.requires("openssl/1.1.1g")
self.requires("qt/5.15.0@bincrafters/stable")
self.requires("kainjow-mustache/[>=3.2.1]@bincrafters/stable")

if self.options.yaml_support:
Expand All @@ -64,8 +67,31 @@ def configure(self):
self.options["qt"].shared = True
self.options["qt"].commercial = False

self.options["yaml-cpp"].shared = True
self.options["libssh2"].shared = True

self.options["qt"].opengl = "no"
self.options["qt"].openssl = False
self.options["qt"].with_vulkan = False
self.options["qt"].with_pcre2 = False
self.options["qt"].with_glib = False
self.options["qt"].with_freetype = False
self.options["qt"].with_fontconfig = False
self.options["qt"].with_harfbuzz = False
self.options["qt"].with_libjpeg = False
self.options["qt"].with_libpng = False
self.options["qt"].with_sqlite3 = False
self.options["qt"].with_mysql = False
self.options["qt"].with_pq = False
self.options["qt"].with_odbc = False
self.options["qt"].with_sdl2 = False
self.options["qt"].with_libalsa = False
self.options["qt"].with_openal = False
self.options["qt"].with_zstd = False
self.options["qt"].with_pq = False
self.options["qt"].GUI = False
self.options["qt"].widgets = False

self.options["yaml-cpp"].shared = False
self.options["libssh2"].shared = False

def _libdir(self):
result = "lib"
Expand Down
24 changes: 24 additions & 0 deletions src/DaggyCore/CLocalDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ void CLocalDataProvider::startCommands()
}
);
});

connect(process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this,
[=]()
{
emit commandStream
(
process->objectName(),
{
command.extension,
process->readAllStandardError(),
Command::Stream::Type::Error
}
);
emit commandStream
(
process->objectName(),
{
command.extension,
process->readAllStandardOutput(),
Command::Stream::Type::Standard
}
);
});

connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this,
[=](int exit_code, QProcess::ExitStatus)
{
Expand Down
25 changes: 24 additions & 1 deletion src/DaggyCore/CSsh2DataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ SOFTWARE.
using namespace daggycore;
using namespace daggyssh2;

namespace {
constexpr const char* kill_command_global =
"pids=$(pstree -p $PPID | grep -oP \"\\d+\" | grep -v $PPID | grep -v $$ | tac);"
"for pid in $pids; do "
"while kill -0 $pid; do "
"kill -9 $pid;"
"sleep 0.1;"
"done "
"done ";
}

CSsh2DataProvider::CSsh2DataProvider(QHostAddress host,
const Ssh2Settings& ssh2_settings,
Commands commands,
Expand Down Expand Up @@ -67,7 +78,19 @@ void CSsh2DataProvider::start()

void CSsh2DataProvider::stop()
{
ssh2_client_->disconnectFromHost();
auto terminate_process = ssh2_client_->createProcess(kill_command_global);
connect(terminate_process, &Ssh2Process::processStateChanged,
[this](const Ssh2Process::ProcessStates state)
{
switch (state) {
case Ssh2Process::ProcessStates::Finished:
case Ssh2Process::ProcessStates::FailedToStart:
ssh2_client_->disconnectFromHost();
break;
default:;
}
});
terminate_process->open();
}

QString CSsh2DataProvider::type() const
Expand Down
3 changes: 2 additions & 1 deletion src/DaggyCore/Ssh2Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void Ssh2Channel::close()
return;
if (ssh2_channel_state_ == Opened) {
emit aboutToClose();
//libssh2_channel_send_eof(ssh2_channel_);
std::error_code error_code = closeSession();
setLastError(error_code);
} else
Expand Down Expand Up @@ -203,7 +204,7 @@ std::error_code Ssh2Channel::closeSession()
std::error_code error_code = ssh2_success;
libssh2_channel_flush_ex(ssh2_channel_, 0);
libssh2_channel_flush_ex(ssh2_channel_, 1);
const int ssh2_method_result = libssh2_channel_close(ssh2_channel_);
const int ssh2_method_result = libssh2_channel_send_eof(ssh2_channel_);
switch (ssh2_method_result) {
case LIBSSH2_ERROR_EAGAIN:
setSsh2ChannelState(ChannelStates::Closing);
Expand Down
23 changes: 15 additions & 8 deletions src/DaggyCore/Ssh2Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void Ssh2Client::disconnectFromHost()
}
}
break;
case Closing:
destroySsh2Objects();
break;
default:;
}
}
Expand Down Expand Up @@ -297,12 +300,14 @@ std::error_code Ssh2Client::createSsh2Objects()
if (known_hosts_ == nullptr)
return Ssh2Error::UnexpectedError;

const int ssh2_method_result = libssh2_knownhost_readfile(
known_hosts_,
qPrintable(ssh2_settings_.known_hosts),
LIBSSH2_KNOWNHOST_FILE_OPENSSH);
if (ssh2_method_result < 0)
return Ssh2Error::ErrorReadKnownHosts;
if (ssh2_settings_.isKeyAuth()) {
const int ssh2_method_result = libssh2_knownhost_readfile(
known_hosts_,
qPrintable(ssh2_settings_.known_hosts),
LIBSSH2_KNOWNHOST_FILE_OPENSSH);
if (ssh2_method_result < 0)
return Ssh2Error::ErrorReadKnownHosts;
}

libssh2_session_set_blocking(ssh2_session_, 0);

Expand All @@ -311,6 +316,8 @@ std::error_code Ssh2Client::createSsh2Objects()

std::error_code Ssh2Client::checkKnownHosts() const
{
if (ssh2_settings_.isPasswordAuth())
return ssh2_success;
size_t length;
int type;
const char* fingerprint = libssh2_session_hostkey(ssh2_session_, &length, &type);
Expand Down Expand Up @@ -386,11 +393,11 @@ Ssh2Client::Ssh2AuthMethods Ssh2Client::getAuthenticationMethod(const QList<Ssh2
if (available_auth_methods.isEmpty())
result = Ssh2AuthMethods::NoAuth;
else if(available_auth_methods.contains(Ssh2AuthMethods::PasswordAuthentication) &&
!ssh2_settings_.passphrase.isNull())
ssh2_settings_.isPasswordAuth())
{
result = Ssh2AuthMethods::PasswordAuthentication;
} else if(available_auth_methods.contains(Ssh2AuthMethods::PublicKeyAuthentication) &&
!ssh2_settings_.key.isNull())
ssh2_settings_.isKeyAuth())
{
result = Ssh2AuthMethods::PublicKeyAuthentication;
}
Expand Down
10 changes: 10 additions & 0 deletions src/DaggyCore/Ssh2Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,13 @@ QString daggyssh2::defaultKnownHosts()
{
return QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.ssh/known_hosts";
}

bool Ssh2Settings::isPasswordAuth() const
{
return !passphrase.isEmpty();
}

bool Ssh2Settings::isKeyAuth() const
{
return !isPasswordAuth();
}
5 changes: 4 additions & 1 deletion src/DaggyCore/Ssh2Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ struct Ssh2Settings {
QString keyphrase;
QString known_hosts = defaultKnownHosts();
unsigned int timeout = 1000;

bool isPasswordAuth() const;
bool isKeyAuth() const;
};

enum Ssh2Error {
ErrorReadKnownHosts,
ErrorReadKnownHosts = 1,
SessionStartupError,
UnexpectedError,
HostKeyInvalidError,
Expand Down
4 changes: 0 additions & 4 deletions src/cmake/package_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ if(WIN32)
install(FILES
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Qt5Network.dll
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Qt5Core.dll
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libssh2.dll
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/yaml-cpp.dll
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT deps
)
Expand All @@ -14,7 +12,5 @@ else()
FILES_MATCHING
PATTERN libQt5Network.so*
PATTERN libQt5Core.so*
PATTERN libssh2.so*
PATTERN libyaml-cpp.so*
)
endif()

0 comments on commit d8bf564

Please sign in to comment.