Skip to content

Commit

Permalink
ceviche-rs: add workflow, add feature for systemd-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
thenextman committed Mar 14, 2024
1 parent 6c5c277 commit d99c62b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:

jobs:
build:
strategy:
fail-fast: false
matrix:
os: ['pc-windows-msvc', 'apple-darwin', 'unknown-linux-gnu']
arch: [x86_64, aarch64]
include:
- runner: ubuntu-latest
os: unknown-linux-gnu
- runner: windows-latest
os: pc-windows-msvc
- runner: macos-latest
os: apple-darwin
runs-on: ${{ matrix.runner }}

steps:
- uses: actions/checkout@v4

- name: Configure runner
run: rustup target add ${{matrix.arch}}-${{matrix.os}}

- name: Configure runner
if: matrix.os == 'unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get -o Acquire:retries=3 install libsystemd-dev
- name: Build
shell: pwsh
run: cargo build --target ${{matrix.arch}}-${{matrix.os}}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ winapi = { version = "0.3", features = ["winbase", "winerror", "winuser", "winsv
widestring = "0.4.3"

[target.'cfg(target_os = "linux")'.dependencies]
systemd-rs = "^0.1.2"
systemd-rs = { version="^0.1.2", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9"
Expand Down
13 changes: 10 additions & 3 deletions src/controller/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use std::sync::mpsc;

use ctrlc;
use log::{debug, info};
use systemd_rs::login::monitor::{Category, Monitor};
use systemd_rs::login::session as login_session;

use crate::controller::{ControllerInterface, ServiceMainFn};
use crate::session;
use crate::Error;
use crate::ServiceEvent;

#[cfg(feature = "systemd-rs")]
use {systemd_rs::login::monitor::{Category, Monitor}, systemd_rs::login::session as login_session};

type LinuxServiceMainWrapperFn = extern "system" fn(args: Vec<String>);
pub type Session = session::Session_<String>;

Expand Down Expand Up @@ -179,9 +180,11 @@ impl ControllerInterface for LinuxController {
}
}

#[cfg(feature = "systemd-rs")]
fn run_monitor<T: Send + 'static>(
tx: mpsc::Sender<ServiceEvent<T>>,
) -> Result<Monitor, std::io::Error> {

let monitor = Monitor::new()?;

let mut current_session = match login_session::get_active_session() {
Expand Down Expand Up @@ -239,8 +242,12 @@ macro_rules! Service {
#[doc(hidden)]
pub fn dispatch<T: Send + 'static>(service_main: ServiceMainFn<T>, args: Vec<String>) {
let (tx, rx) = mpsc::channel();

#[cfg(feature = "systemd-rs")]
{
let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor");
}

let _monitor = run_monitor(tx.clone()).expect("Failed to run session monitor");
let _tx = tx.clone();

ctrlc::set_handler(move || {
Expand Down

0 comments on commit d99c62b

Please sign in to comment.