Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
53883d5
improve: add system error details to file operation error handling
ComixHe Aug 6, 2025
61d1b26
feat: add ns_last_pid extension test and enhance test framework
ComixHe Aug 6, 2025
2a8c21b
docs: Update linyaps-box documentation
taotieren Aug 19, 2025
2b51656
chore: suppress compiler warning
ComixHe Aug 22, 2025
e62d7d5
fix: early return if an exception is thrown while command parsing
ComixHe Aug 25, 2025
08c47ff
refactor: resolving the most of compiler warnings
ComixHe Aug 26, 2025
b1c7fa1
fix: handle broken symlinks during mount destination creation
ComixHe Aug 29, 2025
24a6a99
feat: implement preserve_fds support and fix file descriptor handling
ComixHe Sep 1, 2025
4ad30a7
fix: correct variable name
ComixHe Sep 5, 2025
3b94fbc
fix(deps): upgrade CLI11 to 2.5.0 to resolve bug in argument parsing
ComixHe Sep 11, 2025
9204ffb
fix: use O_PATH flag when masking paths to avoid permission issues
ComixHe Sep 15, 2025
0e5def0
refactor: change the default open flag
ComixHe Sep 15, 2025
881bcc9
fix: move the one of sockpairs to child container process
ComixHe Oct 9, 2025
53f0e1e
style: format code with ClangFormat and Prettier
deepsource-autofix[bot] Oct 9, 2025
08b7904
feat: allow cn.org.linyaps.runtime.ns_last_pid extension failed
ComixHe Oct 11, 2025
04aface
chore(tools): add clang-format script for formatting C++ sources
ComixHe Oct 13, 2025
11face2
chore: formatting codes
ComixHe Oct 13, 2025
72ca241
chore: update CPM.cmake to 0.42.0
ComixHe Oct 15, 2025
56bb0d1
build: CPM is disabled by default
ComixHe Oct 15, 2025
613cc27
refactor: standardize preserve_fds type for better portability
ComixHe Oct 20, 2025
8f1b042
refactor: change the type of mount flag to unsigned int
ComixHe Oct 20, 2025
27c0ae9
refactor: remove __S_ISTYPE for improving portability
ComixHe Oct 20, 2025
59ed24f
refactor: add <sys/types.h> for mode_t
ComixHe Oct 20, 2025
caf2cec
refactor: Add conditional compilation protection for SIGCLD signal
ComixHe Oct 20, 2025
e12e421
chore: Begin development of 2.1.3
ComixHe Oct 21, 2025
5a4eaff
fix: explicitly cast MS_NOUSER to unsigned int
ComixHe Oct 21, 2025
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
27 changes: 13 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.11.4) # for RHEL 8

project(
linyaps-box
VERSION 2.1.0
VERSION 2.1.3
DESCRIPTION "A simple OCI runtime for desktop applications"
HOMEPAGE_URL "https://github.com/OpenAtom-Linyaps/linyaps-box"
LANGUAGES CXX)
Expand Down Expand Up @@ -91,7 +91,7 @@ set(linyaps-box_ACTIVE_LOG_LEVEL
)

set(linyaps-box_ENABLE_CPM
ON
OFF
CACHE BOOL "enable CPM")

if(CMAKE_VERSION VERSION_LESS "3.14")
Expand All @@ -105,11 +105,6 @@ set(linyaps-box_CPM_LOCAL_PACKAGES_ONLY
OFF
CACHE BOOL "use local packages only")

if(linyaps-box_CPM_LOCAL_PACKAGES_ONLY)
message(STATUS "CPM is disabled")
set(linyaps-box_ENABLE_CPM OFF)
endif()

# ==============================================================================

set(linyaps-box_LIBRARY linyaps-box)
Expand All @@ -118,7 +113,7 @@ set(linyaps-box_LIBRARY_SOURCE
src/linyaps_box/app.cpp
src/linyaps_box/app.h
src/linyaps_box/cgroup.h
src/linyaps_box/cgroup_manager.c
src/linyaps_box/cgroup_manager.cpp
src/linyaps_box/cgroup_manager.h
src/linyaps_box/command/exec.cpp
src/linyaps_box/command/exec.h
Expand Down Expand Up @@ -195,8 +190,7 @@ if(NOT linyaps-box_MAKE_RELEASE)
COMMAND git rev-parse --short=7 HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(LINYAPS_BOX_VERSION "${LINYAPS_BOX_VERSION}-dev-${GIT_COMMIT_HASH}")
endif()
Expand Down Expand Up @@ -229,6 +223,10 @@ if(linyaps-box_ENABLE_CPM)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CPM)

if (linyaps-box_CPM_LOCAL_PACKAGES_ONLY)
set(CPM_USE_LOCAL_PACKAGES ON)
endif()

CPMFindPackage(
NAME nlohmann_json
VERSION 3.11.3
Expand All @@ -238,7 +236,7 @@ if(linyaps-box_ENABLE_CPM)
OPTIONS "JSON_BuildTests OFF")
CPMFindPackage(
NAME CLI11
VERSION 2.4.1
VERSION 2.5.0
GITHUB_REPOSITORY CLIUtils/CLI11
GIT_TAG v2.5.0
EXCLUDE_FROM_ALL ON
Expand All @@ -257,12 +255,12 @@ endif()
list(APPEND linyaps-box_LIBRARY_LINK_LIBRARIES PUBLIC
nlohmann_json::nlohmann_json)

find_package(CLI11 2.4.1 QUIET)
find_package(CLI11 2.5.0 QUIET)
if(NOT CLI11_FOUND)
add_subdirectory(external/CLI11)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake.external/CLI11")
find_package(CLI11 2.4.1 REQUIRED)
find_package(CLI11 2.5.0 REQUIRED)
message(STATUS "use vendor CLI11 ${CLI11_VERSION}")
endif()

Expand Down Expand Up @@ -438,7 +436,8 @@ function(setup_linyaps_box_smoke_tests)
./tests/ll-box-st/09-check-rlimit.json
./tests/ll-box-st/10-check-oom.json
./tests/ll-box-st/11-output-to-null.json
./tests/ll-box-st/12-bind-host-dev.json)
./tests/ll-box-st/12-bind-host-dev.json
./tests/ll-box-st/13-pid-extension.json)

foreach(test ${linyaps-box_SMOKE_TESTS})
add_test(
Expand Down
9 changes: 6 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 6,
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
Expand All @@ -21,7 +21,8 @@
"linyaps-box_CPACK_PACKAGING_INSTALL_PREFIX": "",
"linyaps-box_ENABLE_SMOKE_TESTS": true,
"linyaps-box_DEFAULT_LOG_LEVEL": "7",
"linyaps-box_ACTIVE_LOG_LEVEL": "7"
"linyaps-box_ACTIVE_LOG_LEVEL": "7",
"linyaps-box_ENABLE_CPM": "ON"
}
},
{
Expand All @@ -47,7 +48,9 @@
"CMAKE_COLOR_DIAGNOSTICS": true,
"CMAKE_CXX_FLAGS": "-fno-asynchronous-unwind-tables -fdata-sections -ffunction-sections -flto=auto $env{CXXFLAGS}",
"CMAKE_EXE_LINKER_FLAGS_INIT": "-Wl,--gc-sections,--strip-all,--exclude-libs,ALL -flto=auto",
"linyaps-box_STATIC": true
"linyaps-box_STATIC": true,
"linyaps-box_ENABLE_CPACK": "ON",
"linyaps-box_MAKE_RELEASE": "ON"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

\[ **en** | [zh_CN](./README.zh_CN.md) \]

[![Packaging status](https://repology.org/badge/vertical-allrepos/linyaps-box.svg)](https://repology.org/project/linyaps-box/versions)

This project is a simple [OCI runtime] mainly used by [linyaps],
which is a toolkit for Linux desktop application distributing.

Expand Down
2 changes: 2 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

\[ [en](./README.md) | **zh_CN** \]

[![Packaging status](https://repology.org/badge/vertical-allrepos/linyaps-box.svg)](https://repology.org/project/linyaps-box/versions)

这个项目是一个简单的[OCI运行时],主要由[玲珑]使用,
玲珑是一个用于Linux桌面应用程序分发的工具包。

Expand Down
92 changes: 82 additions & 10 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endif()
if(DEFINED EXTRACTED_CPM_VERSION)
set(CURRENT_CPM_VERSION "${EXTRACTED_CPM_VERSION}${CPM_DEVELOPMENT}")
else()
set(CURRENT_CPM_VERSION 0.40.8)
set(CURRENT_CPM_VERSION 0.42.0)
endif()

get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
Expand Down Expand Up @@ -202,6 +202,60 @@ function(cpm_package_name_from_git_uri URI RESULT)
endif()
endfunction()

# Find the shortest hash that can be used eg, if origin_hash is
# cccb77ae9609d2768ed80dd42cec54f77b1f1455 the following files will be checked, until one is found
# that is either empty (allowing us to assign origin_hash), or whose contents matches ${origin_hash}
#
# * .../cccb.hash
# * .../cccb77ae.hash
# * .../cccb77ae9609.hash
# * .../cccb77ae9609d276.hash
# * etc
#
# We will be able to use a shorter path with very high probability, but in the (rare) event that the
# first couple characters collide, we will check longer and longer substrings.
function(cpm_get_shortest_hash source_cache_dir origin_hash short_hash_output_var)
# for compatibility with caches populated by a previous version of CPM, check if a directory using
# the full hash already exists
if(EXISTS "${source_cache_dir}/${origin_hash}")
set(${short_hash_output_var}
"${origin_hash}"
PARENT_SCOPE
)
return()
endif()

foreach(len RANGE 4 40 4)
string(SUBSTRING "${origin_hash}" 0 ${len} short_hash)
set(hash_lock ${source_cache_dir}/${short_hash}.lock)
set(hash_fp ${source_cache_dir}/${short_hash}.hash)
# Take a lock, so we don't have a race condition with another instance of cmake. We will release
# this lock when we can, however, if there is an error, we want to ensure it gets released on
# it's own on exit from the function.
file(LOCK ${hash_lock} GUARD FUNCTION)

# Load the contents of .../${short_hash}.hash
file(TOUCH ${hash_fp})
file(READ ${hash_fp} hash_fp_contents)

if(hash_fp_contents STREQUAL "")
# Write the origin hash
file(WRITE ${hash_fp} ${origin_hash})
file(LOCK ${hash_lock} RELEASE)
break()
elseif(hash_fp_contents STREQUAL origin_hash)
file(LOCK ${hash_lock} RELEASE)
break()
else()
file(LOCK ${hash_lock} RELEASE)
endif()
endforeach()
set(${short_hash_output_var}
"${short_hash}"
PARENT_SCOPE
)
endfunction()

# Try to infer package name and version from a url
function(cpm_package_name_and_ver_from_url url outName outVer)
if(url MATCHES "[/\\?]([a-zA-Z0-9_\\.-]+)\\.(tar|tar\\.gz|tar\\.bz2|zip|ZIP)(\\?|/|$)")
Expand Down Expand Up @@ -594,14 +648,6 @@ endfunction()
function(CPMAddPackage)
cpm_set_policies()

list(LENGTH ARGN argnLength)
if(argnLength EQUAL 1)
cpm_parse_add_package_single_arg("${ARGN}" ARGN)

# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
endif()

set(oneValueArgs
NAME
FORCE
Expand All @@ -624,10 +670,26 @@ function(CPMAddPackage)

set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES)

list(LENGTH ARGN argnLength)

# Parse single shorthand argument
if(argnLength EQUAL 1)
cpm_parse_add_package_single_arg("${ARGN}" ARGN)

# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")

# Parse URI shorthand argument
elseif(argnLength GREATER 1 AND "${ARGV0}" STREQUAL "URI")
list(REMOVE_AT ARGN 0 1) # remove "URI gh:<...>@version#tag"
cpm_parse_add_package_single_arg("${ARGV1}" ARGV0)

set(ARGN "${ARGV0};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;${ARGN}")
endif()

cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")

# Set default values for arguments

if(NOT DEFINED CPM_ARGS_VERSION)
if(DEFINED CPM_ARGS_GIT_TAG)
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
Expand Down Expand Up @@ -798,9 +860,19 @@ function(CPMAddPackage)
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${CPM_ARGS_CUSTOM_CACHE_KEY})
elseif(CPM_USE_NAMED_CACHE_DIRECTORIES)
string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG")
cpm_get_shortest_hash(
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
"${origin_hash}" # Input hash
origin_hash # Computed hash
)
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME})
else()
string(SHA1 origin_hash "${origin_parameters}")
cpm_get_shortest_hash(
"${CPM_SOURCE_CACHE}/${lower_case_name}" # source cache directory
"${origin_hash}" # Input hash
origin_hash # Computed hash
)
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
endif()
# Expand `download_directory` relative path. This is important because EXISTS doesn't work for
Expand Down
29 changes: 14 additions & 15 deletions src/linyaps_box/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

#include "linyaps_box/command/exec.h"
#include "linyaps_box/command/kill.h"
#include "linyaps_box/command/list.h"

Check warning on line 9 in src/linyaps_box/app.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linyaps_box/command/list.h" not found.
#include "linyaps_box/command/run.h"

Check warning on line 10 in src/linyaps_box/app.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linyaps_box/command/run.h" not found.
#include "linyaps_box/utils/log.h"

Check warning on line 11 in src/linyaps_box/app.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linyaps_box/utils/log.h" not found.

#include <iostream>
#include "utils/log.h"

namespace {

Expand All @@ -32,38 +31,38 @@
// Command line arguments are parsed according to
// https://github.com/opencontainers/runtime-tools/blob/v0.9.0/docs/command-line-interface.md
// Extended commands and options should be compatible with crun.
int main(int argc, char **argv) noexcept
auto main(int argc, char **argv) noexcept -> int
try {
LINYAPS_BOX_DEBUG() << "linyaps box called with" << [=]() -> std::string {
std::stringstream result;
for (int i = 0; i < argc; ++i) {
result << " \"";
for (const char *c = argv[i]; *c != '\0'; ++c) {
if (*c == '\\') {
for (const auto ch : std::string_view(argv[i])) { // NOLINT
if (ch == '\\') {
result << "\\\\";
} else if (*c == '"') {
} else if (ch == '"') {
result << "\\\"";
} else {
result << *c;
result << ch;
}
}
result << "\"";
}
return result.str();
}();

command::options options = command::parse(argc, argv);
if (options.global.return_code != 0) {
return options.global.return_code;
auto opts = command::parse(argc, argv);
if (opts.global.return_code != 0) {
return opts.global.return_code;
}

return std::visit(subCommand{ [](const command::list_options &options) {
command::list(options);
return 0;
},
[](const command::exec_options &options) {
[](const command::exec_options &options) -> int {
command::exec(options);
return 0;
__builtin_unreachable();
},
[](const command::kill_options &options) {
command::kill(options);
Expand All @@ -72,10 +71,10 @@
[](const command::run_options &options) {
return command::run(options);
},
[code = options.global.return_code](const std::monostate &) {
return code;
[](const std::monostate &) {
return 0;
} },
options.subcommand_opt);
opts.subcommand_opt);
} catch (const std::exception &e) {
LINYAPS_BOX_ERR() << "Error: " << e.what();
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/linyaps_box/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

namespace linyaps_box {

int main(int argc, char **argv) noexcept;
auto main(int argc, char **argv) noexcept -> int;

} // namespace linyaps_box
Loading