feat: portability, correctness, and quality improvements for v0.2

Portability (Linux distro-agnostic):
- Remove hardcoded Clang compiler enforcement; GCC now builds
- Add find_package(Threads REQUIRED) for older glibc
- Add cmake install() target
- FHS 3.0 default root: /kappa -> /usr/local/kappa
- fs::path operator/ for all init/bootloader paths (fixes prefix fragility)
- Multi-distro zoneinfo search (FHS, NixOS, Guix, alt)
- Portable tar extraction (drop GNU-only --no-same-permissions)
- Runit enable/disable commands now prefix-aware
- --root CLI flag before/after subcommand, lazy directory creation
- Shebang constants de-duplicated to types.hpp

Correctness (race conditions, UB, corruption):
- Fix CWD race in scheduler: per-child chdir() instead of process-global
- Fix UB const_cast in exec_cmd/exec_capture: mutable argv buffers
- Fix non-atomic installed DB writes: tmp+rename pattern
- Fix read_file() no longer calls exit(1), throws instead
- Fix silent catch(...) parse errors now print diagnostics
- Fix rebuild false positives with config_hash change detection
- Fix s6 disable_cmd copy-paste bug (was identical to enable)
- Fix runit enable_cmd incomplete, disable_cmd wrong target
- Fix dinit env vars: functional env-file + companion .env

Quality:
- Add -Wall -Wextra -Wpedantic to CMake, fix 2 pre-existing warnings
- Move parse_int from error.hpp to parse_util.hpp
- Fix hash verification guard checks all three hash types
- Check patch return code in fetch.cpp
- Add explicit system_dir creation in ensure_directories()
- Add resolve to needs_dirs for build_registry() consistency
- Update stale /kappa path references in examples
- Remove inaccurate -Werror claim in CONTRIBUTING.md
- Add build-gcc/ and agent dirs to .gitignore
- Suppress clang-tidy portability-avoid-pragma-once
- Fix .gitignore /kappa pattern (was matching include/kappa/)
- Delete stale vcpkg_installed/ directory

54/54 tests pass. Builds on Clang and GCC with 0 warnings.
This commit is contained in:
2026-07-31 08:28:49 -04:00
parent dd984f96d4
commit 7e93db2d07
25 changed files with 353 additions and 133 deletions
+2 -5
View File
@@ -55,12 +55,9 @@ std::string generate_dinit_service(const ServiceSpec& spec) {
out << std::format("run-as = {}\n", spec.user);
}
// Environment variables (as comments — dinit doesn't support inline env)
// Environment variables — dinit uses env-file directive
if (!spec.env.empty()) {
out << "\n# Environment variables:\n";
for (const auto& [key, value] : spec.env) {
out << std::format("# {}={}\n", key, value);
}
out << std::format("env-file = {}.env\n", spec.name);
}
// description
+12 -1
View File
@@ -110,7 +110,7 @@ ServiceInstallResult install_service(InitSystem is,
return {false, {},
std::format("Failed to write {}", run_path.string())};
}
out << "#!/bin/execlineb -P\n";
out << s6_execline_shebang;
out << "# Generated by kappa — do not edit manually\n";
out << std::format("# s6 service: {}\n", spec.name);
if (!spec.working_dir.empty()) {
@@ -196,6 +196,17 @@ ServiceInstallResult install_service(InitSystem is,
out << content;
}
// Dinit: also write companion .env file
if (is == InitSystem::Dinit && !spec.env.empty()) {
fs::path env_path = fs::path(paths.service_dir) / std::format("{}.env", spec.name);
std::ofstream env_out(env_path);
if (env_out) {
for (const auto& [key, value] : spec.env) {
env_out << key << "=" << value << "\n";
}
}
}
return {true, file_path.string(), {}};
}
+3 -1
View File
@@ -8,6 +8,8 @@ namespace kappa::service {
namespace {
static constexpr std::string_view openrc_run_shebang = "#!/sbin/openrc-run\n";
bool is_background_type(std::string_view type) {
return type == "longrun" || type == "notify" || type == "forking";
}
@@ -18,7 +20,7 @@ std::string generate_openrc_service(const ServiceSpec& spec) {
std::ostringstream os;
// Shebang and header
os << "#!/sbin/openrc-run\n";
os << openrc_run_shebang;
os << "# Generated by kappa — do not edit manually\n";
// Description
+1 -1
View File
@@ -19,7 +19,7 @@ std::string generate_s6_service(const ServiceSpec& spec) {
// --- run file content ---
std::ostringstream run;
run << "#!/bin/execlineb -P\n";
run << s6_execline_shebang;
run << "# Generated by kappa — do not edit manually\n";
run << std::format("# s6 service: {}\n", spec.name);
+9 -8
View File
@@ -3,6 +3,7 @@
#include <algorithm>
#include <cctype>
#include <filesystem>
#include <format>
#include <ranges>
@@ -61,31 +62,31 @@ InitPaths init_paths(InitSystem is, std::string_view prefix) {
switch (is) {
case InitSystem::Systemd:
return {
.service_dir = std::format("{}etc/systemd/system", prefix),
.service_dir = (std::filesystem::path(prefix) / "etc/systemd/system").string(),
.enable_cmd = "systemctl enable",
.disable_cmd = "systemctl disable",
};
case InitSystem::OpenRC:
return {
.service_dir = std::format("{}etc/init.d", prefix),
.service_dir = (std::filesystem::path(prefix) / "etc/init.d").string(),
.enable_cmd = "rc-update add",
.disable_cmd = "rc-update del",
};
case InitSystem::S6:
return {
.service_dir = std::format("{}etc/s6/sv", prefix),
.service_dir = (std::filesystem::path(prefix) / "etc/s6/sv").string(),
.enable_cmd = "s6-rc-bundle-update",
.disable_cmd = "s6-rc-bundle-update",
.disable_cmd = "s6-rc-bundle-update delete",
};
case InitSystem::Runit:
return {
.service_dir = std::format("{}etc/sv", prefix),
.enable_cmd = "ln -sf /etc/sv",
.disable_cmd = "rm -f /var/service",
.service_dir = (std::filesystem::path(prefix) / "etc/sv").string(),
.enable_cmd = std::format("ln -sf {}/etc/sv/{{name}} {}/var/service/", prefix, prefix),
.disable_cmd = std::format("rm -f {}/var/service/{{name}}", prefix),
};
case InitSystem::Dinit:
return {
.service_dir = std::format("{}etc/dinit.d", prefix),
.service_dir = (std::filesystem::path(prefix) / "etc/dinit.d").string(),
.enable_cmd = "dinitctl enable",
.disable_cmd = "dinitctl disable",
};