Skip to content

Commit 85251ed

Browse files
committed
fix(ci): harden Linux recovery and Windows runtime
1 parent 258ca76 commit 85251ed

12 files changed

Lines changed: 238 additions & 21 deletions

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ set(CAS_CORE_PORTABLE_SOURCES
131131
src/cas/agent_state.cpp
132132
src/cas/agent_state_service.cpp
133133
src/cas/runtime_supervisor.cpp
134+
src/cas/runtime_process_unsupported.cpp
134135
src/cas/telemetry_event.cpp
135136
src/cas/telemetry_registry.cpp
136137
src/cas/control_protocol.cpp

‎src/cas/control_protocol.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,12 @@ std::string dispatch(Daemon& daemon,
12711271
// the supervisor while Daemon::snapshot_runtime / restore_runtime drive
12721272
// the matching side.
12731273
// -----------------------------------------------------------------
1274+
if (cmd.rfind("runtime.", 0) == 0) {
1275+
std::string error;
1276+
if (!daemon.runtime_supervisor().supported(error))
1277+
return json_err(error);
1278+
}
1279+
12741280
if (cmd == "runtime.create") {
12751281
std::string rest; std::getline(iss, rest);
12761282
RuntimeCreateRequest req;

‎src/cas/daemon.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,11 @@ RuntimeSnapshotResult Daemon::snapshot_runtime(const RuntimeSnapshotRequest& req
801801
result.runtime_id = request.runtime_id;
802802
std::string error;
803803

804+
if (!runtime_supervisor_.supported(error)) {
805+
result.error = error;
806+
return result;
807+
}
808+
804809
// 1. Validate runtime, cooperativity, and branch resolvability.
805810
RuntimeStatus status;
806811
if (!runtime_supervisor_.status(request.runtime_id, status, error)) {
@@ -998,6 +1003,11 @@ RuntimeRestoreResult Daemon::restore_runtime(const std::string& union_state_id_h
9981003
RuntimeRestoreResult result;
9991004
std::string error;
10001005

1006+
if (!runtime_supervisor_.supported(error)) {
1007+
result.error = error;
1008+
return result;
1009+
}
1010+
10011011
// 1. Parse the union-state id.
10021012
Hash id;
10031013
if (!hex_to_hash_strict(union_state_id_hex, id)) {

‎src/cas/daemon.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
#include "object_store.h"
1111
#include "policy_installer.h"
1212
#include "refs.h"
13+
#ifdef _WIN32
14+
#include "runtime_process_unsupported.h"
15+
#else
1316
#include "runtime_process_posix.h"
17+
#endif
1418
#include "runtime_supervisor.h"
1519
#include "working_tree.h"
1620
#include "write_buffer.h"
@@ -27,6 +31,12 @@
2731

2832
namespace cas {
2933

34+
#ifdef _WIN32
35+
using PlatformRuntimeProcessController = UnsupportedRuntimeProcessController;
36+
#else
37+
using PlatformRuntimeProcessController = PosixRuntimeProcessController;
38+
#endif
39+
3040
class TelemetryRegistry;
3141
class CgroupWatch;
3242

@@ -276,7 +286,7 @@ class Daemon {
276286
// supervisor so it constructs first; the supervisor holds a raw pointer
277287
// to it. Both precede registry_ so they outlive any telemetry backend
278288
// that may capture `daemon`.
279-
PosixRuntimeProcessController runtime_process_controller_;
289+
PlatformRuntimeProcessController runtime_process_controller_;
280290
RuntimeSupervisor runtime_supervisor_;
281291

282292
// Owned. Declared LAST so it is destroyed FIRST (members destruct in
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "runtime_process_unsupported.h"
2+
3+
namespace cas {
4+
namespace {
5+
6+
constexpr const char* kUnsupportedError =
7+
"cooperative runtime control is unsupported on this platform";
8+
9+
bool reject(std::string& error) {
10+
error = kUnsupportedError;
11+
return false;
12+
}
13+
14+
} // namespace
15+
16+
bool UnsupportedRuntimeProcessController::supported(std::string& error) const {
17+
return reject(error);
18+
}
19+
20+
bool UnsupportedRuntimeProcessController::process_alive(int64_t) {
21+
return false;
22+
}
23+
24+
bool UnsupportedRuntimeProcessController::freeze_process_group(
25+
int64_t, std::string& error) {
26+
return reject(error);
27+
}
28+
29+
bool UnsupportedRuntimeProcessController::resume_process_group(
30+
int64_t, std::string& error) {
31+
return reject(error);
32+
}
33+
34+
bool UnsupportedRuntimeProcessController::terminate_process_group(
35+
int64_t, std::string& error) {
36+
return reject(error);
37+
}
38+
39+
} // namespace cas
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include "runtime_supervisor.h"
4+
5+
namespace cas {
6+
7+
// Used on platforms where cooperative runtime snapshots have no process-group
8+
// implementation. It keeps the daemon buildable while rejecting runtime
9+
// control instead of pretending that signals or liveness checks succeeded.
10+
class UnsupportedRuntimeProcessController final : public RuntimeProcessController {
11+
public:
12+
bool supported(std::string& error) const override;
13+
bool process_alive(int64_t pid) override;
14+
bool freeze_process_group(int64_t pgid, std::string& error) override;
15+
bool resume_process_group(int64_t pgid, std::string& error) override;
16+
bool terminate_process_group(int64_t pgid, std::string& error) override;
17+
};
18+
19+
} // namespace cas

‎src/cas/runtime_supervisor.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ namespace cas {
1616
RuntimeSupervisor::RuntimeSupervisor(RuntimeProcessController* process_controller)
1717
: process_controller_(process_controller) {}
1818

19+
bool RuntimeSupervisor::supported(std::string& error) const {
20+
return process_controller_->supported(error);
21+
}
22+
1923
bool RuntimeSupervisor::register_runtime(const RuntimeCreateRequest& request,
2024
std::string& error) {
25+
if (!supported(error)) return false;
2126
std::lock_guard<std::mutex> lk(mu_);
2227
std::string id = request.runtime_id;
2328
if (id.empty()) id = make_runtime_id_locked();

‎src/cas/runtime_supervisor.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ struct RuntimeRestoreResult {
9696
class RuntimeProcessController {
9797
public:
9898
virtual ~RuntimeProcessController() = default;
99+
virtual bool supported(std::string& error) const {
100+
error.clear();
101+
return true;
102+
}
99103
virtual bool process_alive(int64_t pid) = 0;
100104
virtual bool freeze_process_group(int64_t pgid, std::string& error) = 0;
101105
virtual bool resume_process_group(int64_t pgid, std::string& error) = 0;
@@ -115,6 +119,7 @@ class RuntimeProcessController {
115119
class RuntimeSupervisor {
116120
public:
117121
explicit RuntimeSupervisor(RuntimeProcessController* process_controller);
122+
bool supported(std::string& error) const;
118123

119124
// --- registry --------------------------------------------------------
120125
bool register_runtime(const RuntimeCreateRequest& request,

‎src/cas/workspace_cli.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,16 @@ static bool mountpoint_active(const std::string& path) {
646646
int rc = system(cmd.c_str());
647647
return rc == 0;
648648
#else
649-
std::string cmd = "mountpoint -q ";
649+
// mountpoint(1) stats the target and reports a system error for a
650+
// disconnected FUSE mount. findmnt reads the mount table directly, so it
651+
// can still identify the mount after the daemon has been killed.
652+
std::string cmd = "findmnt -rn --mountpoint ";
650653
cmd += "'";
651654
for (char c : path) {
652655
if (c == '\'') cmd += "'\\''";
653656
else cmd.push_back(c);
654657
}
655-
cmd += "'";
658+
cmd += "' >/dev/null 2>&1";
656659
int rc = system(cmd.c_str());
657660
return rc == 0;
658661
#endif

‎tests/CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ add_executable(cas_test_telemetry_event unit/test_telemetry_event.cpp ../src/cas
156156
target_include_directories(cas_test_telemetry_event PRIVATE ../include ../src ../src/cas)
157157
target_compile_features(cas_test_telemetry_event PRIVATE cxx_std_17)
158158

159+
add_executable(cas_test_runtime_process_unsupported
160+
unit/test_runtime_process_unsupported.cpp)
161+
target_link_libraries(cas_test_runtime_process_unsupported PRIVATE cas_core)
162+
159163
if(UNIX)
160164
add_executable(cas_test_telemetry_registry unit/test_telemetry_registry.cpp ../src/cas/telemetry_registry.cpp ../src/cas/telemetry_event.cpp)
161165
target_include_directories(cas_test_telemetry_registry PRIVATE ../include ../src ../src/cas)
@@ -314,6 +318,7 @@ set(AGENTVFS_STANDALONE_TEST_TARGETS
314318
cas_test_agent_state_service
315319
cas_test_runtime_supervisor
316320
cas_test_runtime_process_posix
321+
cas_test_runtime_process_unsupported
317322
cas_test_branch_merge_commit
318323
cas_test_branch_merge_daemon
319324
cas_test_branch_persistence

0 commit comments

Comments
 (0)