From f6c102053537659ec00957e8c083a2f7c1dbe05f Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Fri, 13 May 2022 20:33:41 -0700 Subject: [PATCH] Remove the need for rust nightly My pidfd implmentation is simple enough, and Option.contains() is not worth requiring nightly. --- Dockerfile | 2 +- Makefile | 17 +++++------------ dbus-service/src/main.rs | 3 ++- debian/rules | 4 ---- locker/Cargo.toml | 4 ---- locker/src/main.rs | 37 ++++--------------------------------- locker/src/pidfd.rs | 6 ++---- util/src/lib.rs | 4 ++++ 8 files changed, 18 insertions(+), 59 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0492d0..67a2122 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 51206a2..960db15 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dbus-service/src/main.rs b/dbus-service/src/main.rs index d93b1af..61305ee 100644 --- a/dbus-service/src/main.rs +++ b/dbus-service/src/main.rs @@ -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>) -> 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); } diff --git a/debian/rules b/debian/rules index fad658d..a7f7ceb 100755 --- a/debian/rules +++ b/debian/rules @@ -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 diff --git a/locker/Cargo.toml b/locker/Cargo.toml index 53c0ebd..7983f0e 100644 --- a/locker/Cargo.toml +++ b/locker/Cargo.toml @@ -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" diff --git a/locker/src/main.rs b/locker/src/main.rs index c6a855b..945d0df 100644 --- a/locker/src/main.rs +++ b/locker/src/main.rs @@ -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> { } 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(o: &Option, 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 -} diff --git a/locker/src/pidfd.rs b/locker/src/pidfd.rs index ef46166..857519e 100644 --- a/locker/src/pidfd.rs +++ b/locker/src/pidfd.rs @@ -21,13 +21,11 @@ fn pidfd_open(pid: RawFd) -> nix::Result { 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; + fn create_pidfd(&self) -> nix::Result; } impl CreatePidFd for Child { - fn create_pidfd(&mut self) -> nix::Result { + fn create_pidfd(&self) -> nix::Result { pidfd_open(self.id() as RawFd) } } diff --git a/util/src/lib.rs b/util/src/lib.rs index 0794f6d..46d1273 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -12,6 +12,10 @@ pub fn init_logging(env_name: &str) { .init(); } +pub fn opt_contains(o: &Option, v: &T) -> bool { + o.as_ref().filter(|ov| ov == &v).is_some() +} + pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result { let cookie = conn.send_request(&x::InternAtom { only_if_exists: false,