Remove the need for rust nightly
My pidfd implmentation is simple enough, and Option.contains() is not worth requiring nightly.
This commit is contained in:
@ -12,10 +12,6 @@ readme = "README.md"
|
||||
keywords = ["gui", "screensaver", "screen-locker"]
|
||||
categories = ["gui"]
|
||||
|
||||
[features]
|
||||
default = ["use-nightly"]
|
||||
use-nightly = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
clap = "3"
|
||||
|
@ -1,7 +1,3 @@
|
||||
#![cfg_attr(feature = "use-nightly", feature(linux_pidfd))]
|
||||
#![cfg_attr(feature = "use-nightly", feature(option_result_contains))]
|
||||
|
||||
#[cfg(not(feature = "use-nightly"))]
|
||||
mod pidfd;
|
||||
|
||||
use clap::{Arg, Command as ClapCommand};
|
||||
@ -31,10 +27,6 @@ use xcb_xembed::embedder::Embedder;
|
||||
|
||||
use bscreensaver_command::{BCommand, create_command_window};
|
||||
use bscreensaver_util::{*, settings::Configuration};
|
||||
|
||||
#[cfg(feature = "use-nightly")]
|
||||
use std::os::linux::process::{ChildExt, CommandExt, PidFd};
|
||||
#[cfg(not(feature = "use-nightly"))]
|
||||
use pidfd::{CreatePidFd, PidFd};
|
||||
|
||||
const BLANKED_ARG: &str = "blanked";
|
||||
@ -454,14 +446,8 @@ fn create_blanker_windows(conn: &xcb::Connection) -> xcb::Result<Vec<Monitor>> {
|
||||
}
|
||||
|
||||
fn start_subservice(binary_name: &str) -> anyhow::Result<(Child, PidFd)> {
|
||||
let mut command = Command::new(format!("{}/{}", env!("HELPER_DIR"), binary_name));
|
||||
#[cfg(feature = "use-nightly")]
|
||||
command.create_pidfd(true);
|
||||
let mut child = command.spawn()?;
|
||||
|
||||
#[cfg(feature = "use-nightly")]
|
||||
let pidfd = child.take_pidfd()?;
|
||||
#[cfg(not(feature = "use-nightly"))]
|
||||
let child = Command::new(format!("{}/{}", env!("HELPER_DIR"), binary_name))
|
||||
.spawn()?;
|
||||
let pidfd = child.create_pidfd()?;
|
||||
|
||||
Ok((child, pidfd))
|
||||
@ -713,18 +699,12 @@ fn start_unlock_dialog<'a>(conn: &'a xcb::Connection, state: &State<'a>, trigger
|
||||
|
||||
show_cursor(conn, state);
|
||||
|
||||
let mut command = Command::new(format!("{}/{}", env!("HELPER_DIR"), state.config.dialog_backend.binary_name()));
|
||||
#[cfg(feature = "use-nightly")]
|
||||
command.create_pidfd(true);
|
||||
let mut child = command
|
||||
let mut child = Command::new(format!("{}/{}", env!("HELPER_DIR"), state.config.dialog_backend.binary_name()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let mut child_out = child.stdout.take().unwrap();
|
||||
#[cfg(feature = "use-nightly")]
|
||||
let child_pidfd = child.take_pidfd()?;
|
||||
#[cfg(not(feature = "use-nightly"))]
|
||||
let child_pidfd = child.create_pidfd()?;
|
||||
let mut child_out = child.stdout.take().unwrap();
|
||||
|
||||
let mut xid_buf: [u8; 4] = [0; 4];
|
||||
child_out.read_exact(&mut xid_buf)?;
|
||||
@ -983,12 +963,3 @@ fn kill_child_processes(state: &mut State) -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn opt_contains<T: PartialEq>(o: &Option<T>, v: &T) -> bool {
|
||||
#[cfg(feature = "use-nightly")]
|
||||
let res = o.contains(v);
|
||||
#[cfg(not(feature = "use-nightly"))]
|
||||
let res = o.as_ref().filter(|ov| ov == &v).is_some();
|
||||
|
||||
res
|
||||
}
|
||||
|
@ -21,13 +21,11 @@ fn pidfd_open(pid: RawFd) -> nix::Result<PidFd> {
|
||||
pub struct PidFd(RawFd);
|
||||
|
||||
pub trait CreatePidFd {
|
||||
// mut isn't necessary here, but it is for the nightly PidFd stuff,
|
||||
// so keep it like this to avoid a warning when compiling using stable.
|
||||
fn create_pidfd(&mut self) -> nix::Result<PidFd>;
|
||||
fn create_pidfd(&self) -> nix::Result<PidFd>;
|
||||
}
|
||||
|
||||
impl CreatePidFd for Child {
|
||||
fn create_pidfd(&mut self) -> nix::Result<PidFd> {
|
||||
fn create_pidfd(&self) -> nix::Result<PidFd> {
|
||||
pidfd_open(self.id() as RawFd)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user