Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible crash when starting shell integration #11288

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/11288
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: fix crash on start-up when starting shell integration
fmoc marked this conversation as resolved.
Show resolved Hide resolved

A possible crash has been fixed that could occur during start-up, when
the shell integration started doing requests before the client itself
completed starting up.

https://github.com/owncloud/client/issues/11280
https://github.com/owncloud/client/pull/11288
6 changes: 5 additions & 1 deletion src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "common/version.h"
#include "gui/translations.h"
#include "libsync/logger.h"
#include "socketapi/socketapi.h"

#include <kdsingleapplication.h>

Expand Down Expand Up @@ -389,7 +390,7 @@ int main(int argc, char **argv)
return -1;
}

FolderMan::instance()->setSyncEnabled(true);
folderManager->setSyncEnabled(true);

auto ocApp = Application::createInstance(platform.get(), options.debugMode);

Expand Down Expand Up @@ -442,5 +443,8 @@ int main(int argc, char **argv)
QTimer::singleShot(0, ocApp->gui(), &ownCloudGui::runNewAccountWizard);
}

// Now that everything is up and running, start accepting connections/requests from the shell integration.
folderManager->socketApi()->startShellIntegration();

return app.exec();
}
32 changes: 17 additions & 15 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,28 @@ SocketApi::SocketApi(QObject *parent)
qRegisterMetaType<QSharedPointer<SocketApiJob>>("QSharedPointer<SocketApiJob>");
qRegisterMetaType<QSharedPointer<SocketApiJobV2>>("QSharedPointer<SocketApiJobV2>");

const QString socketPath = Utility::socketApiSocketPath();
_socketPath = Utility::socketApiSocketPath();

// Remove any old socket that might be lying around:
SocketApiServer::removeServer(socketPath);
SocketApiServer::removeServer(_socketPath);

// Create the socket path:
if (!Utility::isMac()) {
// Not on macOS: there the directory is there, and created for us by the sandboxing
// environment, because we belong to an App Group.
QFileInfo info(socketPath);
QFileInfo info(_socketPath);
if (!info.dir().exists()) {
bool result = info.dir().mkpath(QStringLiteral("."));
qCDebug(lcSocketApi) << "creating" << info.dir().path() << result;
if (result) {
QFile::setPermissions(socketPath,
QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner));
QFile::setPermissions(_socketPath, QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner));
}
}
}

// Wire up the server instance to us, so we can accept new connections:
connect(&_localServer, &SocketApiServer::newConnection, this, &SocketApi::slotNewConnection);

// Start listeneing:
if (_localServer.listen(socketPath)) {
qCInfo(lcSocketApi) << "server started, listening at " << socketPath;
} else {
qCWarning(lcSocketApi) << "can't start server" << socketPath;
}

// Now we're ready to start the native shell integration:
Utility::startShellIntegration();

connect(AccountManager::instance(), &AccountManager::accountRemoved, this, [this](const auto &accountState) {
if (_registeredAccounts.contains(accountState->account())) {
unregisterAccount(accountState->account());
Expand All @@ -189,6 +178,19 @@ SocketApi::~SocketApi()
_listeners.clear();
}

void SocketApi::startShellIntegration()
{
// Start listeneing:
if (_localServer.listen(_socketPath)) {
qCInfo(lcSocketApi) << "server started, listening at " << _socketPath;
} else {
qCWarning(lcSocketApi) << "can't start server" << _socketPath;
}

// Now we're ready to start the native shell integration:
Utility::startShellIntegration();
}

void SocketApi::slotNewConnection()
{
// Note that on macOS this is not actually a line-based QIODevice, it's a SocketApiSocket which is our
Expand Down
3 changes: 3 additions & 0 deletions src/gui/socketapi/socketapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SocketApi : public QObject
explicit SocketApi(QObject *parent = nullptr);
~SocketApi() override;

void startShellIntegration();

public slots:
void registerAccount(const AccountPtr &a);
void unregisterAccount(const AccountPtr &a);
Expand Down Expand Up @@ -155,6 +157,7 @@ private slots:

QString buildRegisterPathMessage(const QString &path);

QString _socketPath;
QSet<Folder *> _registeredFolders;
QSet<AccountPtr> _registeredAccounts;
QMap<SocketApiSocket *, QSharedPointer<SocketListener>> _listeners;
Expand Down