1
0
Fork 0
forked from wry/wry

config: add pid client criteria

This commit is contained in:
Julian Orth 2025-05-03 12:46:56 +02:00
parent 587ffc7ee5
commit a952e658da
13 changed files with 55 additions and 1 deletions

View file

@ -1886,6 +1886,7 @@ impl ConfigProxyHandler {
}
ClientCriterionIpc::Sandboxed => mgr.sandboxed(),
ClientCriterionIpc::Uid(p) => mgr.uid(*p),
ClientCriterionIpc::Pid(p) => mgr.pid(*p),
};
let cached = Rc::new(CachedCriterion {
crit: criterion.clone(),

View file

@ -7,6 +7,7 @@ use {
CritDestroyListener, CritLiteralOrRegex, CritMatcherId, CritMatcherIds, CritMgrExt,
CritUpstreamNode, FixedRootMatcher, RootMatcherMap,
clm::clm_matchers::{
clmm_pid::ClmMatchPid,
clmm_sandboxed::ClmMatchSandboxed,
clmm_string::{
ClmMatchSandboxAppId, ClmMatchSandboxEngine, ClmMatchSandboxInstanceId,
@ -54,6 +55,7 @@ pub struct RootMatchers {
sandbox_engine: ClmRootMatcherMap<ClmMatchSandboxEngine>,
sandbox_instance_id: ClmRootMatcherMap<ClmMatchSandboxInstanceId>,
uid: ClmRootMatcherMap<ClmMatchUid>,
pid: ClmRootMatcherMap<ClmMatchPid>,
}
pub async fn handle_cl_changes(state: Rc<State>) {
@ -154,6 +156,7 @@ impl ClMatcherManager {
unconditional!(sandbox_app_id);
unconditional!(sandbox_engine);
unconditional!(uid);
unconditional!(pid);
fixed!(sandboxed);
self.constant[true].handle(data);
}
@ -178,6 +181,10 @@ impl ClMatcherManager {
pub fn uid(&self, pid: i32) -> Rc<ClmUpstreamNode> {
self.root(ClmMatchUid(pid as _))
}
pub fn pid(&self, pid: i32) -> Rc<ClmUpstreamNode> {
self.root(ClmMatchPid(pid as _))
}
}
impl CritTarget for Rc<Client> {

View file

@ -17,6 +17,7 @@ macro_rules! fixed_root_criterion {
};
}
pub mod clmm_pid;
pub mod clmm_sandboxed;
pub mod clmm_string;
pub mod clmm_uid;

View file

@ -0,0 +1,20 @@
use {
crate::{
client::Client,
criteria::{RootMatcherMap, clm::RootMatchers, crit_graph::CritRootCriterion},
},
std::rc::Rc,
uapi::c,
};
pub struct ClmMatchPid(pub c::pid_t);
impl CritRootCriterion<Rc<Client>> for ClmMatchPid {
fn matches(&self, data: &Rc<Client>) -> bool {
data.pid_info.pid == self.0
}
fn nodes(roots: &RootMatchers) -> Option<&RootMatcherMap<Rc<Client>, Self>> {
Some(&roots.pid)
}
}