docker-plugin: fix daemon state

Changed daemon state to actually check the docker runtime to determine
if its available or not.

Change-Id: I9e183658dfc7c34e229aec2a332cf303793284e5
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-04-05 11:43:56 +02:00
parent 1d63eaee23
commit 3af260b782
9 changed files with 223 additions and 29 deletions

View File

@@ -317,7 +317,7 @@ void DockerDevice::updateContainerAccess() const
void DockerDevicePrivate::stopCurrentContainer()
{
if (m_container.isEmpty() || !DockerPlugin::isDaemonRunning().value_or(false))
if (m_container.isEmpty() || !DockerApi::isDockerDaemonAvailable().value_or(false))
return;
if (m_shell) {
@@ -412,7 +412,7 @@ void DockerDevicePrivate::startContainer()
// negative exit codes indicate problems like no docker daemon, missing permissions,
// no shell and seem to result in exit codes 125+
if (exitCode > 120) {
DockerPlugin::setGlobalDaemonState(false);
DockerApi::recheckDockerDaemon();
LOG("DOCKER DAEMON NOT RUNNING?");
MessageManager::writeFlashing(tr("Docker daemon appears to be not running. "
"Verify daemon is up and running and reset the "
@@ -428,12 +428,10 @@ void DockerDevicePrivate::startContainer()
m_shell->waitForStarted();
if (!m_shell->isRunning()) {
DockerPlugin::setGlobalDaemonState(false);
DockerApi::recheckDockerDaemon();
LOG("DOCKER SHELL FAILED");
return;
}
DockerPlugin::setGlobalDaemonState(true);
}
void DockerDevicePrivate::updateContainerAccess()
@@ -441,7 +439,7 @@ void DockerDevicePrivate::updateContainerAccess()
if (!m_container.isEmpty())
return;
if (DockerPlugin::isDaemonRunning().value_or(true) == false)
if (DockerApi::isDockerDaemonAvailable().value_or(true) == false)
return;
if (m_shell)
@@ -899,7 +897,7 @@ bool DockerDevice::writeFileContents(const FilePath &filePath, const QByteArray
void DockerDevice::runProcess(QtcProcess &process) const
{
updateContainerAccess();
if (!DockerPlugin::isDaemonRunning().value_or(false))
if (!DockerApi::isDockerDaemonAvailable().value_or(false))
return;
if (d->m_container.isEmpty()) {
LOG("No container set to run " << process.commandLine().toUserOutput());
@@ -979,7 +977,7 @@ void DockerDevicePrivate::fetchSystemEnviroment()
bool DockerDevicePrivate::runInContainer(const CommandLine &cmd) const
{
if (!DockerPlugin::isDaemonRunning().value_or(false))
if (!DockerApi::isDockerDaemonAvailable().value_or(false))
return false;
CommandLine dcmd{"docker", {"exec", m_container}};
dcmd.addCommandLineAsArgs(cmd);
@@ -997,7 +995,7 @@ bool DockerDevicePrivate::runInContainer(const CommandLine &cmd) const
bool DockerDevicePrivate::runInShell(const CommandLine &cmd) const
{
if (!QTC_GUARD(DockerPlugin::isDaemonRunning().value_or(false))) {
if (!QTC_GUARD(DockerApi::isDockerDaemonAvailable().value_or(false))) {
LOG("No daemon. Could not run " << cmd.toUserOutput());
return false;
}
@@ -1023,7 +1021,7 @@ static QByteArray randomHex()
QByteArray DockerDevicePrivate::outputForRunInShell(const CommandLine &cmd) const
{
if (!DockerPlugin::isDaemonRunning().value_or(false))
if (!DockerApi::isDockerDaemonAvailable().value_or(false))
return {};
QTC_ASSERT(m_shell && m_shell->isRunning(), return {});
QMutexLocker l(&m_shellMutex);