From 4f03764433bdfa519eee3a13055b0daa3a34d697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Sat, 12 Oct 2024 13:08:11 +0200 Subject: [PATCH 1/4] new: add component-monitor Add a component monitor that will manage content in the target path based on the contents of a sentinel file under the source path. --- .gitignore | 1 + component-monitor/.gitignore | 1 + component-monitor/Cargo.lock | 326 ++++++++++++++++++++++++++++++++++ component-monitor/Cargo.toml | 13 ++ component-monitor/src/main.rs | 238 +++++++++++++++++++++++++ 5 files changed, 579 insertions(+) create mode 100644 .gitignore create mode 100644 component-monitor/.gitignore create mode 100644 component-monitor/Cargo.lock create mode 100644 component-monitor/Cargo.toml create mode 100644 component-monitor/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..722d5e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode diff --git a/component-monitor/.gitignore b/component-monitor/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/component-monitor/.gitignore @@ -0,0 +1 @@ +/target diff --git a/component-monitor/Cargo.lock b/component-monitor/Cargo.lock new file mode 100644 index 0000000..18803f1 --- /dev/null +++ b/component-monitor/Cargo.lock @@ -0,0 +1,326 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "clap" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "component-monitor" +version = "0.1.0" +dependencies = [ + "clap", + "exitcode", + "log", + "nix", + "signal-hook", + "systemd-journal-logger", + "walkdir", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "exitcode" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "libc" +version = "0.2.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "systemd-journal-logger" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5f3848dd723f2a54ac1d96da793b32923b52de8dfcced8722516dac312a5b2a" +dependencies = [ + "log", + "rustix", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/component-monitor/Cargo.toml b/component-monitor/Cargo.toml new file mode 100644 index 0000000..c21eead --- /dev/null +++ b/component-monitor/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "component-monitor" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4", default-features = false, features = ["derive", "env", "help", "std", "usage"] } +exitcode = { version = "1", default-features = false } +log = { version = "0.4", default-features = false } +nix = { version = "0.29", default-features = false, features = ["inotify"] } +signal-hook = { version = "0.3", default-features = false, features = ["iterator"] } +systemd-journal-logger = { version = "2", default-features = false } +walkdir = { version = "2", default-features = false } diff --git a/component-monitor/src/main.rs b/component-monitor/src/main.rs new file mode 100644 index 0000000..c79221c --- /dev/null +++ b/component-monitor/src/main.rs @@ -0,0 +1,238 @@ +use log::{debug, error, info, warn, LevelFilter}; +use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify, InotifyEvent}; +use signal_hook::{consts::SIGINT, consts::SIGTERM, iterator::Signals}; +use std::{fs, path::PathBuf, thread}; +use systemd_journal_logger::JournalLog; +use walkdir::WalkDir; + +use clap::Parser; + +/// Manage the kernel-gpu-2404 contents +#[derive(Debug, Parser)] +#[command(version, about)] +struct Cli { + /// The source path to monitor + #[arg(env = "COMPONENT_SOURCE")] + source: PathBuf, + /// The sentinel file name + #[arg(env = "COMPONENT_SENTINEL", value_parser = clap::builder::NonEmptyStringValueParser::new())] + sentinel: String, + /// The target path to manage content in + #[arg(env = "COMPONENT_TARGET")] + target: PathBuf, + /// Turn on debug logging + #[arg(env, long, short)] + debug: bool, +} + +/// Remove the sentinel file from target, then clear the target directory +fn cleanup(target: &PathBuf, sentinel: &String) { + info!(target: "files", "cleaning up {target:?}"); + let sentinel_path = target.join(sentinel); + if sentinel_path.exists() { + match fs::remove_file(&sentinel_path) { + Ok(()) => { + debug!(target: "files", "removed sentinel ({0:?})", &sentinel_path) + } + Err(e) => { + warn!(target: "files", "failed to remove {0:?}: {e}", &sentinel_path) + } + } + } + for entry in fs::read_dir(target).expect("ERROR: failed to list target directory") { + match entry { + Ok(e) => { + let path = e.path(); + if path.is_dir() { + match fs::remove_dir_all(&path) { + Ok(()) => { + debug!(target: "files", "removed {0:?} recursively", &path) + } + Err(e) => { + error!(target: "files", "failed to remove {0:?}: {e}", &path) + } + } + } else { + match fs::remove_file(&path) { + Ok(()) => { + debug!(target: "files", "removed {0:?}", &path) + } + Err(e) => { + error!(target: "files", "failed to remove {0:?}: {e}", &path) + } + } + } + } + Err(e) => { + error!(target: "files", "{e}"); + } + } + } +} + +/// Check if the sentinel file is current, else clean the target directory and populate again, +/// sentinel file being last +fn populate(source: &PathBuf, sentinel: &String, target: &PathBuf) { + info!(target: "files", "populating {target:?} from {source:?} with sentinel {sentinel:?}"); + let sentinel_src = source.join(sentinel); + + if !sentinel_src.exists() { + info!(target: "files", "sentinel file ({0:?}) not found, skipping", &sentinel_src); + return; + } + + let sentinel_data = match fs::read(&sentinel_src) { + Ok(d) if d.trim_ascii() == b"" => { + error!(target: "files", "found empty sentinel file ({0:?})", &sentinel_src); + return; + } + Ok(d) => d, + Err(e) => { + error!(target: "files", "failed to read sentinel file: {e}"); + return; + } + }; + + let sentinel_tgt = target.join(sentinel); + if sentinel_data == fs::read(&sentinel_tgt).unwrap_or_default() { + info!(target: "files", "found current sentinel, skipping"); + return; + } + + cleanup(target, sentinel); + info!(target: "files", "copying from {source:?} to {target:?}"); + for entry in WalkDir::new(&source) { + match entry { + Ok(e) => { + let path = e.path(); + let relative_path = path.strip_prefix(source).unwrap(); + if path == source { + continue; + } + if *(relative_path.to_str().unwrap()) == **sentinel { + continue; + } + + let target_path = target.join(relative_path); + if path.is_dir() { + match fs::create_dir(&target_path) { + Ok(()) => { + debug!(target: "files", "created {0:?}", &target_path) + } + Err(e) => { + error!(target: "files", "failed to create {0:?}: {e}", &target_path) + } + } + } else { + match fs::copy(path, &target_path) { + Ok(_) => { + debug!(target: "files", "copied {0:?} to {1:?}", &path, &target_path); + } + Err(e) => { + error!(target: "files", "failed to copy {0:?} to {1:?}: {e}", &path, &target_path); + } + } + } + } + Err(e) => { + error!(target: "files", "{e}"); + } + } + } + + match fs::copy(&sentinel_src, &sentinel_tgt) { + Ok(_) => { + debug!(target: "files", "copied sentinel ({0:?} to {0:?})", sentinel_src); + } + Err(e) => { + error!(target: "files", "failed to copy sentinel: {e}"); + } + } +} + +/// Handle inotify events: +/// - run cleanup on sentinel deletion +/// - populate on sentinel written +/// - panic on source remove +fn monitor(inotify: &Inotify, args: &Cli) { + info!(target: "inotify", "starting event monitoring on {0:?}", &args.source); + loop { + let events = inotify + .read_events() + .expect("ERROR: Failed to read inotify events"); + + for event in events { + debug!( + target: "inotify", + "handling {0:?} event for {1:?}", + event.mask, + event.name + ); + match event { + InotifyEvent { + name: Some(name), + mask, + .. + } if *name == *args.sentinel => match mask { + AddWatchFlags::IN_DELETE => { + cleanup(&args.target, &args.sentinel); + } + _ => { + populate(&args.source, &args.sentinel, &args.target); + } + }, + InotifyEvent { + mask: AddWatchFlags::IN_DELETE_SELF | AddWatchFlags::IN_MOVE_SELF, + .. + } => panic!("ERROR: Monitored folder disappeared"), + _ => (), + } + } + } +} + +/// Set up source directory monitoring, populate the target directory and start monitoring +/// the source for sentinel changes +fn main() { + let args = Cli::parse(); + let mut signals = Signals::new([SIGINT, SIGTERM]).expect("ERROR: Failed to set up signals"); + let inotify = Inotify::init(InitFlags::IN_CLOEXEC).expect("ERROR: Failed to set up inotify"); + + assert!( + args.source.is_dir(), + "ERROR: source ({0:?}) is not a directory", + args.source + ); + assert!( + args.target.is_dir(), + "ERROR: target ({0:?}) is not a directory", + args.target + ); + + thread::spawn(move || { + for _sig in signals.forever() { + std::process::exit(exitcode::OK); + } + }); + + inotify + .add_watch( + &args.source, + AddWatchFlags::IN_CLOSE_WRITE + | AddWatchFlags::IN_DELETE + | AddWatchFlags::IN_MOVE_SELF + | AddWatchFlags::IN_DELETE_SELF, + ) + .expect("ERROR: Failed to add inotify watcher"); + + JournalLog::new().unwrap().install().unwrap(); + let log_level = if args.debug { + LevelFilter::Debug + } else { + LevelFilter::Info + }; + log::set_max_level(log_level); + + populate(&args.source, &args.sentinel, &args.target); + monitor(&inotify, &args); +} From 3d98ad49dead5da7aa6fb4a19c10e57b67fdfe0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Sat, 12 Oct 2024 13:09:51 +0200 Subject: [PATCH 2/4] snap: add kernel-gpu-2404 content support Using hooks and the component monitor, ensure the content is managed in ${SNAP_DATA}/kernel-gpu-2404 --- snap/hooks/connect-plug-kernel-gpu-2404 | 4 ++++ snap/hooks/disconnect-plug-kernel-gpu-2404 | 6 ++++++ snap/hooks/install | 12 +++++++++++ snap/hooks/post-refresh | 1 + snap/snapcraft.yaml | 23 ++++++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 snap/hooks/connect-plug-kernel-gpu-2404 create mode 100644 snap/hooks/disconnect-plug-kernel-gpu-2404 create mode 100644 snap/hooks/install create mode 120000 snap/hooks/post-refresh diff --git a/snap/hooks/connect-plug-kernel-gpu-2404 b/snap/hooks/connect-plug-kernel-gpu-2404 new file mode 100644 index 0000000..a57323d --- /dev/null +++ b/snap/hooks/connect-plug-kernel-gpu-2404 @@ -0,0 +1,4 @@ +#!bin/sh +set -xeu + +snapctl start --enable ${SNAP_INSTANCE_NAME}.component-monitor diff --git a/snap/hooks/disconnect-plug-kernel-gpu-2404 b/snap/hooks/disconnect-plug-kernel-gpu-2404 new file mode 100644 index 0000000..540cb40 --- /dev/null +++ b/snap/hooks/disconnect-plug-kernel-gpu-2404 @@ -0,0 +1,6 @@ +#!bin/sh +set -xeu + +rm --force --verbose ${COMPONENT_TARGET}/${COMPONENT_SENTINEL} +snapctl stop --disable ${SNAP_INSTANCE_NAME}.component-monitor +find ${COMPONENT_TARGET} -mindepth 1 -delete diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100644 index 0000000..c7a9a13 --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,12 @@ +#!bin/sh +set -xeu + +mkdir --parents --verbose ${COMPONENT_TARGET} + +HOOKS="$( cd -- "$(dirname "$0")" ; pwd -P )" + +if snapctl is-connected ${COMPONENT_INTERFACE}; then + . ${HOOKS}/connect-plug-${COMPONENT_INTERFACE} +else + . ${HOOKS}/disconnect-plug-${COMPONENT_INTERFACE} +fi diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 120000 index 0000000..f7ffc47 --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1 @@ +install \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 8acef3d..57e4000 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -391,7 +391,30 @@ parts: > ${CRAFT_PART_INSTALL}/${SCRIPT} chmod 555 ${CRAFT_PART_INSTALL}/${SCRIPT} + component-monitor: + after: [file-list] + plugin: rust + source: component-monitor + +plugs: + kernel-gpu-2404: + interface: content + target: $SNAP/kernel-gpu-2404 + slots: gpu-2404: interface: content read: [$SNAP] + +environment: + COMPONENT_INTERFACE: kernel-gpu-2404 + COMPONENT_SENTINEL: kernel-gpu-2404-sentinel + COMPONENT_SOURCE: ${SNAP}/kernel-gpu-2404 + COMPONENT_TARGET: ${SNAP_DATA}/kernel-gpu-2404 + +apps: + component-monitor: + daemon: simple + restart-condition: always + restart-delay: 3s + command: bin/component-monitor From e35f73c3a0aedaa57c5055d3156d2d3fee12ebbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Sat, 12 Oct 2024 14:18:48 +0200 Subject: [PATCH 3/4] snap: use the kernel component wrapper Check for sentinel existence in the second content location and run through the wrapper within. --- scripts/bin/gpu-2404-provider-wrapper.in | 8 ++++++++ snap/snapcraft.yaml | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/bin/gpu-2404-provider-wrapper.in b/scripts/bin/gpu-2404-provider-wrapper.in index c0e0bc1..2445aea 100755 --- a/scripts/bin/gpu-2404-provider-wrapper.in +++ b/scripts/bin/gpu-2404-provider-wrapper.in @@ -49,6 +49,14 @@ if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm fi +# The second content element is mounted at "${content_target}-2" +COMPONENT_PATH="$( cd -- "$(dirname "$0")"/.. ; pwd -P )-2" + +# Use the component mangler to amend the environment further +if [ -f ${COMPONENT_PATH}/@COMPONENT_SENTINEL@ ]; then + . ${COMPONENT_PATH}/@COMPONENT_MANGLER@ +fi + export LD_LIBRARY_PATH export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 57e4000..72c18c3 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -386,7 +386,10 @@ parts: [ ${CRAFT_ARCH_BUILD_FOR} == amd64 ] && ARCH_TRIPLETS+=( i386-linux-gnu ) mkdir -p ${CRAFT_PART_INSTALL}/bin - sed "s/@ARCH_TRIPLETS@/${ARCH_TRIPLETS[*]}/" \ + sed \ + -e "s/@ARCH_TRIPLETS@/${ARCH_TRIPLETS[*]}/" \ + -e "s/@COMPONENT_SENTINEL@/kernel-gpu-2404-sentinel/" \ + -e "s/@COMPONENT_MANGLER@/bin\/kernel-gpu-2404-provider-mangler/" \ ${CRAFT_PART_SRC}/${SCRIPT}.in \ > ${CRAFT_PART_INSTALL}/${SCRIPT} chmod 555 ${CRAFT_PART_INSTALL}/${SCRIPT} @@ -404,7 +407,9 @@ plugs: slots: gpu-2404: interface: content - read: [$SNAP] + read: + - $SNAP + - $SNAP_DATA/kernel-gpu-2404 environment: COMPONENT_INTERFACE: kernel-gpu-2404 From f557a7b1b2b89360a717bee8d84d4a0f292b6348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Wed, 16 Oct 2024 08:34:07 +0200 Subject: [PATCH 4/4] kernel-gpu: make the component precede Mesa Since the component is likely to be more appropriate for the hardware, make it go first. --- scripts/bin/gpu-2404-provider-wrapper.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/bin/gpu-2404-provider-wrapper.in b/scripts/bin/gpu-2404-provider-wrapper.in index 2445aea..beab726 100755 --- a/scripts/bin/gpu-2404-provider-wrapper.in +++ b/scripts/bin/gpu-2404-provider-wrapper.in @@ -1,6 +1,14 @@ #!/bin/bash set -euo pipefail +# The second content element is mounted at "${content_target}-2" +COMPONENT_PATH="$( cd -- "$(dirname "$0")"/.. ; pwd -P )-2" + +# Use the component mangler to bootstrap the environment +if [ -f ${COMPONENT_PATH}/@COMPONENT_SENTINEL@ ]; then + . ${COMPONENT_PATH}/@COMPONENT_MANGLER@ +fi + SELF="$( cd -- "$(dirname "$0")/.." ; pwd -P )/usr" ARCH_TRIPLETS=( @ARCH_TRIPLETS@ ) @@ -49,14 +57,6 @@ if [ -d "/var/lib/snapd/lib/gl/gbm" ]; then export GBM_BACKENDS_PATH=/var/lib/snapd/lib/gl/gbm fi -# The second content element is mounted at "${content_target}-2" -COMPONENT_PATH="$( cd -- "$(dirname "$0")"/.. ; pwd -P )-2" - -# Use the component mangler to amend the environment further -if [ -f ${COMPONENT_PATH}/@COMPONENT_SENTINEL@ ]; then - . ${COMPONENT_PATH}/@COMPONENT_MANGLER@ -fi - export LD_LIBRARY_PATH export LIBGL_DRIVERS_PATH if [ "${__NV_PRIME_RENDER_OFFLOAD:-}" != 1 ]; then