Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
isolated_scanner.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3
4// Crash-isolated plugin scanner.
5//
6// Loads a single plugin bundle in a CHILD PROCESS via the canonical
7// `pulp::platform::ChildProcess` API + the pre-existing
8// `pulp-scan-worker` helper binary (tools/scan-worker/). A crash, hang,
9// or format error in the worker is reported back to the parent as a
10// `ScanResult` with a structured `ScanStatus` instead of taking down
11// the host.
12//
13// Uses the `pulp-scan-worker` binary.
14//
15// Usage:
16// pulp::host::IsolatedPluginScanner s{worker_path};
17// auto result = s.scan(bundle_path, /*timeout_ms=*/5000);
18// if (result.status == ScanStatus::Ok) {
19// use(result.descriptor);
20// } else if (result.status == ScanStatus::Crash) {
21// blacklist.blacklist(bundle_path, result.error_message);
22// }
23
24#include <pulp/host/scanner.hpp>
25
26#include <optional>
27#include <string>
28#include <string_view>
29#include <vector>
30
31namespace pulp::host {
32
46std::string find_scan_worker(std::string_view explicit_path = {});
47
72
73struct ScanResult {
77 std::optional<PluginInfo> descriptor;
82 std::vector<PluginInfo> descriptors;
85 int exit_code = -1;
89 std::string error_message;
90};
91
93public:
99 explicit IsolatedPluginScanner(std::string worker_path)
100 : worker_path_(std::move(worker_path)) {}
101
104 ScanResult scan(const std::string& bundle_path, int timeout_ms = 5000) const;
105
107 const std::string& worker_path() const noexcept { return worker_path_; }
108
109private:
110 std::string worker_path_;
111};
112
113} // namespace pulp::host
ScanResult scan(const std::string &bundle_path, int timeout_ms=5000) const
Scan a single bundle in a child process.
const std::string & worker_path() const noexcept
Accessor for the resolved worker path (mostly for diagnostics).
Definition isolated_scanner.hpp:107
IsolatedPluginScanner(std::string worker_path)
Construct with the path to the pulp-scan-worker binary that will be exec'd for each scan.
Definition isolated_scanner.hpp:99
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
std::string find_scan_worker(std::string_view explicit_path={})
Locate the pulp-scan-worker binary for isolated scanning.
ScanStatus
Outcome of an isolated scan attempt.
Definition isolated_scanner.hpp:51
@ Crash
Worker terminated abnormally (signal / non-zero code with no JSON).
Definition isolated_scanner.hpp:53
@ FormatError
Worker rejected the bundle (exit code 3 — extension not recognized).
Definition isolated_scanner.hpp:58
@ WorkerMissing
The configured worker_path doesn't exist or can't be exec'd.
Definition isolated_scanner.hpp:62
@ Timeout
Worker exceeded the per-scan timeout.
Definition isolated_scanner.hpp:56
@ ProtocolError
The worker exited 0 but its stdout could not be trusted: it exceeded the capture limit or a line did ...
Definition isolated_scanner.hpp:65
@ NotPlugin
Worker ran cleanly but emitted no descriptor (the file at path was not a plugin we can scan).
Definition isolated_scanner.hpp:60
@ Ok
Definition baked_graph_processor.hpp:156
STL namespace.
Definition isolated_scanner.hpp:73
ScanStatus status
Definition isolated_scanner.hpp:74
std::string error_message
Human-readable error explanation (stderr tail, "timeout", or "worker not found").
Definition isolated_scanner.hpp:89
std::optional< PluginInfo > descriptor
The first descriptor, populated only when status == Ok.
Definition isolated_scanner.hpp:77
std::vector< PluginInfo > descriptors
Every descriptor the worker emitted, in bundle order, populated only when status == Ok.
Definition isolated_scanner.hpp:82
int exit_code
Worker exit status (raw OS exit code, or -1 if it never started / was signal-killed).
Definition isolated_scanner.hpp:85