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
12 changes: 11 additions & 1 deletion api/dbus/org.deepin.linglong.PackageManager1.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
SPDX-License-Identifier: LGPL-3.0-or-later
-->
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "https://specifications.freedesktop.org/dbus/introspect-latest.dtd">
Expand Down Expand Up @@ -46,6 +46,12 @@ SPDX-License-Identifier: LGPL-3.0-or-later
<method name="Permissions">
<annotation name="org.freedesktop.DBus.Description" value="Used by the client to check whether it has permission to call privileged methods" />
</method>
<method name="InitRunContext">
<arg direction="in" name="runContextCfg" type="s" />
<arg direction="in" name="containerID" type="s" />
<arg direction="out" name="result" type="a{sv}" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap" />
</method>
<signal name="SearchFinished">
<arg name="taskID" type="s" />
<arg name="result" type="a{sv}" />
Expand All @@ -56,6 +62,10 @@ SPDX-License-Identifier: LGPL-3.0-or-later
<arg name="result" type="a{sv}" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap" />
</signal>
<signal name="InitRunContextFinished">
<arg name="taskID" type="s" />
<arg name="success" type="b" />
</signal>
<method name="ReplyInteraction">
<arg name="task" type="o" />
<arg name="replies" type="a{sv}" />
Expand Down
39 changes: 39 additions & 0 deletions api/schema/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,42 @@
}
}
}
},
"RunContextConfig": {
"title": "RunContextConfig",
"type": "object",
"required": [
"version"
],
"properties": {
"version": {
"type": "string"
},
"base": {
"type": "string"
},
"runtime": {
"type": "string"
},
"app": {
"type": "string"
},
"extensions": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"overlayfs": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
},
"type": "object",
Expand Down Expand Up @@ -1594,6 +1630,9 @@
},
"RuntimeConfigure": {
"$ref": "#/$defs/RuntimeConfigure"
},
"RunContextConfig": {
"$ref": "#/$defs/RunContextConfig"
}
}
}
26 changes: 25 additions & 1 deletion api/schema/v1.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# NOTE:
Expand Down Expand Up @@ -1097,6 +1097,30 @@ $defs:
type: array
items:
$ref: '#/$defs/ExtensionDefine'
RunContextConfig:
title: RunContextConfig
type: object
required:
- version
properties:
version:
type: string
base:
type: string
runtime:
type: string
app:
type: string
extensions:
type: object
additionalProperties:
type: array
items:
type: string
overlayfs:
type: string
timezone:
type: string
type: object
properties:
# NOTE: "properties" is auto generated by referring all types is $defs
13 changes: 5 additions & 8 deletions apps/ll-builder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,8 @@ You can report bugs to the linyaps team under this project: https://github.com/O
return 0;
}

// build command need run in namespace because:
// 1. fuse-overlayfs should run in new user_namespaces and
// run with CAP_DAC_OVERRIDE capbilities.
// 2. mount needs CAP_SYS_ADMIN capbilities in the
// user_namespaces associated with current mount_namespaces,
if (buildBuilder->parsed()) {
// command which runs container need run in new user namespace and mount namespace
if (buildBuilder->parsed() || buildExport->parsed() || buildRun->parsed()) {
auto res = linglong::utils::needRunInNamespace();
if (!res) {
LogE("failed to check need run in namespace {}", res.error());
Expand All @@ -1006,6 +1002,8 @@ You can report bugs to the linyaps team under this project: https://github.com/O
}
}

linglong::utils::checkPauseDebugger();

if (buildCreate->parsed()) {
return handleCreate(createOpts);
}
Expand Down Expand Up @@ -1093,8 +1091,7 @@ You can report bugs to the linyaps team under this project: https://github.com/O
std::rethrow_exception(ociRuntime.error());
}

auto *containerBuilder = new linglong::runtime::ContainerBuilder(**ociRuntime);
containerBuilder->setParent(QCoreApplication::instance());
auto containerBuilder = std::make_unique<linglong::runtime::ContainerBuilder>(**ociRuntime);

// use the current directory as the project(working) directory
std::error_code ec;
Expand Down
86 changes: 11 additions & 75 deletions apps/ll-cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "configure.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "configure.h" not found.
#include "linglong/api/dbus/v1/dbus_peer.h"
#include "linglong/cli/cli.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/api/dbus/v1/dbus_peer.h" not found.
#include "linglong/cli/cli_printer.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/cli/cli.h" not found.
#include "linglong/cli/dbus_notifier.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/cli/cli_printer.h" not found.
#include "linglong/cli/dummy_notifier.h"
#include "linglong/cli/json_printer.h"
#include "linglong/cli/terminal_notifier.h"
Expand Down Expand Up @@ -46,26 +45,6 @@

namespace {

void startProcess(const QString &program, const QStringList &args = {})
{
QProcess process;
auto envs = process.environment();
envs.push_back("QT_FORCE_STDERR_LOGGING=1");
process.setEnvironment(envs);
process.setProgram(program);
process.setArguments(args);

qint64 pid = 0;
process.startDetached(&pid);

LogD("start {} {} as {}", program.toStdString(), args.join(" ").toStdString(), pid);

QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, [pid]() {
LogD("kill {}", pid);
kill(pid, SIGTERM);
});
}

std::vector<std::string> transformOldExec(int argc, char **argv) noexcept
{
std::vector<std::string> res;
Expand Down Expand Up @@ -193,6 +172,8 @@
->delimiter(',') // 支持以逗号分隔
->allow_extra_args(false) // 避免吞掉后面的参数
->check(validatorString);
cliRun->add_option("--run-context", runOptions.runContext, _("Run context json string"))
->group("");
cliRun
->add_flag("--privileged", runOptions.privileged, _("Run the application in privileged mode"))
->group("");
Expand Down Expand Up @@ -712,56 +693,6 @@
break;
}

// connect to package manager
auto pkgManConn = QDBusConnection::systemBus();
auto *pkgMan =
new linglong::api::dbus::v1::PackageManager("org.deepin.linglong.PackageManager1",
"/org/deepin/linglong/PackageManager1",
pkgManConn,
QCoreApplication::instance());
// if --no-dbus flag is set, start package manager in sudo mode
if (*noDBusFlag) {
if (getuid() != 0) {
LogE("--no-dbus should only be used by root user.");
return -1;
}

LogW("some subcommands will failed in --no-dbus mode.");
const auto pkgManAddress = QString("unix:path=/tmp/linglong-package-manager.socket");
startProcess("sudo",
{ "--user",
LINGLONG_USERNAME,
"--preserve-env=QT_FORCE_STDERR_LOGGING",
"--preserve-env=QDBUS_DEBUG",
LINGLONG_LIBEXEC_DIR "/ll-package-manager",
"--no-dbus" });
QThread::sleep(1);

pkgManConn = QDBusConnection::connectToPeer(pkgManAddress, "ll-package-manager");
if (!pkgManConn.isConnected()) {
LogE("Failed to connect to ll-package-manager: {}",
pkgManConn.lastError().message().toStdString());
return -1;
}

pkgMan = new linglong::api::dbus::v1::PackageManager("",
"/org/deepin/linglong/PackageManager1",
pkgManConn,
QCoreApplication::instance());
} else {
// ping package manager to make it initialize system linglong repository
auto peer = linglong::api::dbus::v1::DBusPeer("org.deepin.linglong.PackageManager1",
"/org/deepin/linglong/PackageManager1",
pkgManConn);
auto reply = peer.Ping();
reply.waitForFinished();
if (!reply.isValid()) {
LogE("Failed to activate org.deepin.linglong.PackageManager1: {}",
reply.error().message().toStdString());
return -1;
}
}

// create printer
std::unique_ptr<Printer> printer;
if (*jsonFlag) {
Expand Down Expand Up @@ -790,8 +721,7 @@
}

// create container builder
auto *containerBuilder = new linglong::runtime::ContainerBuilder(**ociRuntime);
containerBuilder->setParent(QCoreApplication::instance());
auto containerBuilder = std::make_unique<linglong::runtime::ContainerBuilder>(**ociRuntime);

// create notifier
std::unique_ptr<InteractiveNotifier> notifier{ nullptr };
Expand All @@ -812,6 +742,8 @@
LogW("Using DummyNotifier, expected interactions and prompts will not be displayed.");
notifier = std::make_unique<linglong::cli::DummyNotifier>();
}

const bool peerMode = noDBusFlag->count() > 0;
auto repo = linglong::repo::OSTreeRepo::loadFromPath(LINGLONG_ROOT);
if (!repo.has_value()) {
LogE("failed to load repo: {}", repo.error());
Expand All @@ -821,7 +753,7 @@
auto *cli = new linglong::cli::Cli(*printer,
**ociRuntime,
*containerBuilder,
*pkgMan,
peerMode,
**repo,
std::move(notifier),
QCoreApplication::instance());
Expand Down Expand Up @@ -854,7 +786,11 @@
int result = -1;
// call corresponding function according to subcommand name and pass corresponding options
if (name == "run") {
result = cli->run(runOptions);
if (runOptions.runContext) {
result = cli->runWithContext(runOptions);
} else {
result = cli->run(runOptions);
}
} else if (name == "enter") {
result = cli->enter(enterOptions);
} else if (name == "ps") {
Expand Down
Loading
Loading