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:
Brian Tarricone 2022-05-13 20:33:41 -07:00
parent 7e18b87707
commit f6c1020535
8 changed files with 18 additions and 59 deletions

View File

@ -9,7 +9,7 @@ RUN apt-get update && \
apt-get -y install curl devscripts && \
mkdir -p /build
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# Do this first to get our build deps cached.
COPY debian ./debian

View File

@ -44,13 +44,6 @@ RELEASE_MANPAGES := $(addprefix $(RELEASE_OUT)/,$(MANPAGES))
INSTALL ?= install
HELP2MAN ?= help2man
RUST_RELEASE_CHANNEL = nightly
ifeq ($(RUST_RELEASE_CHANNEL),nightly)
RUST_RELEASE_CHANNEL_ARG = +nightly
else
FEATURES_ARGS = --no-default-features
endif
DEV_LOG_LEVEL = debug
all: release manpages $(RELEASE_OUT)/bscreensaver-settings.desktop
@ -70,10 +63,10 @@ install: all
$(INSTALL) -m 0644 $(RELEASE_MANPAGES) $(DESTDIR)$(MANDIR)/man1
$(DEV_TARGETS): $(SOURCES)
HELPER_DIR=target/debug cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS)
HELPER_DIR=target/debug cargo build
$(RELEASE_TARGETS): $(SOURCES)
HELPER_DIR=$(HELPER_DIR) cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS) --release
HELPER_DIR=$(HELPER_DIR) cargo build --release
$(RELEASE_OUT)/%.1.gz: $(RELEASE_OUT)/%.1
mkdir -p $(dir $@)
@ -101,7 +94,7 @@ deb-pkg:
rm -rf /build/bscreensaver'
clean:
cargo $(RUST_RELEASE_CHANNEL_ARG) clean
cargo clean
uninstall:
rm -f $(addprefix $(DESTDIR)$(BINDIR),$(BINARIES)) $(addprefix $(HELPER_DIR)/,$(HELPERS))) || true
@ -118,10 +111,10 @@ run: $(DEV_TARGETS)
BSCREENSAVER_SYSTEMD_LOG=$(DEV_LOG_LEVEL) \
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
HELPER_DIR=target/debug \
cargo $(RUST_RELEASE_CHANNEL_ARG) run $(FEATURES_ARGS) --bin bscreensaver
cargo run --bin bscreensaver
run-dialog:
RUST_BACKTRACE=1 \
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
BSCREENSAVER_DIALOG_STANDALONE=1 \
cargo $(RUST_RELEASE_CHANNEL_ARG) run $(FEATURES_ARGS) --bin bscreensaver-dialog-gtk3
cargo run --bin bscreensaver-dialog-gtk3

View File

@ -6,6 +6,7 @@ use std::{io, process::exit, time::{Duration, Instant}};
use zbus::{dbus_interface, fdo::{self, DBusProxy, RequestNameFlags}, names::{BusName, UniqueName, WellKnownName}, ConnectionBuilder, MessageHeader};
use bscreensaver_command::{bscreensaver_command, BCommand};
use bscreensaver_util::opt_contains;
const OUR_DBUS_NAME: &str = "org.freedesktop.ScreenSaver";
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(45);
@ -157,7 +158,7 @@ async fn dbus_task(state: Arc<Mutex<State>>) -> anyhow::Result<()> {
let args = name_owner_changed.args()?;
match args.name() {
BusName::WellKnown(name) if name == OUR_DBUS_NAME => {
if args.new_owner().is_none() || args.new_owner().as_ref().filter(|no| no != &our_unique_name).is_some() {
if args.new_owner().is_none() || opt_contains(&args.new_owner(), &our_unique_name) {
info!("Lost bus name {}; quitting", OUR_DBUS_NAME);
exit(0);
}

4
debian/rules vendored
View File

@ -1,10 +1,6 @@
#!/usr/bin/make -f
RUST_RELEASE_CHANNEL = nightly
MAKE_ARGS = \
RUST_RELEASE_CHANNEL=$(RUST_RELEASE_CHANNEL) \
PREFIX=/usr \
SYSCONFDIR=/etc \
DESTDIR=debian/bscreensaver

View File

@ -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"

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -12,6 +12,10 @@ pub fn init_logging(env_name: &str) {
.init();
}
pub fn opt_contains<T: PartialEq>(o: &Option<T>, v: &T) -> bool {
o.as_ref().filter(|ov| ov == &v).is_some()
}
pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result<x::Atom> {
let cookie = conn.send_request(&x::InternAtom {
only_if_exists: false,