Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions apps/ll-cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
#include <sys/file.h>

#include <QDBusMetaType>
#include <QDBusObjectPath>

Check warning on line 27 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusObjectPath> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonDocument>

Check warning on line 28 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 29 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 30 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtGlobal> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtGlobal>

Check warning on line 32 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <algorithm> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <algorithm>

Check warning on line 33 in apps/ll-cli/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <functional> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <functional>
#include <map>
#include <memory>
Expand Down Expand Up @@ -685,6 +686,23 @@
}

const bool peerMode = noDBusFlag->count() > 0;
if (peerMode) {
if (getuid() != 0) {
LogE("--no-dbus should only be used by root user.");
return -1;
}

// Start ll-package-manager --no-dbus first to initialize the repository
QProcess::startDetached("sudo",
{ "--user",
LINGLONG_USERNAME,
"--preserve-env=QT_FORCE_STDERR_LOGGING",
"--preserve-env=QDBUS_DEBUG",
LINGLONG_LIBEXEC_DIR "/ll-package-manager",
"--no-dbus" });
using namespace std::chrono_literals;
std::this_thread::sleep_for(1s);
}
Comment thread
dengbo11 marked this conversation as resolved.
auto repo = linglong::repo::OSTreeRepo::loadFromPath(LINGLONG_ROOT);
if (!repo.has_value()) {
LogE("failed to load repo: {}", repo.error());
Expand Down
13 changes: 0 additions & 13 deletions libs/linglong/src/linglong/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,21 +464,8 @@ utils::error::Result<api::dbus::v1::PackageManager *> Cli::getPkgMan()
}

if (this->peerMode) {
if (getuid() != 0) {
return LINGLONG_ERR("--no-dbus should only be used by root user.");
}

LogW("some subcommands will failed in --no-dbus mode.");
const auto pkgManAddress = QString("unix:path=/tmp/linglong-package-manager.socket");
QProcess::startDetached("sudo",
{ "--user",
LINGLONG_USERNAME,
"--preserve-env=QT_FORCE_STDERR_LOGGING",
"--preserve-env=QDBUS_DEBUG",
LINGLONG_LIBEXEC_DIR "/ll-package-manager",
"--no-dbus" });
using namespace std::chrono_literals;
std::this_thread::sleep_for(1s);

const auto &pkgManConn =
QDBusConnection::connectToPeer(pkgManAddress, "ll-package-manager");
Expand Down
Loading