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:
parent
7e18b87707
commit
f6c1020535
@ -9,7 +9,7 @@ RUN apt-get update && \
|
|||||||
apt-get -y install curl devscripts && \
|
apt-get -y install curl devscripts && \
|
||||||
mkdir -p /build
|
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.
|
# Do this first to get our build deps cached.
|
||||||
COPY debian ./debian
|
COPY debian ./debian
|
||||||
|
17
Makefile
17
Makefile
@ -44,13 +44,6 @@ RELEASE_MANPAGES := $(addprefix $(RELEASE_OUT)/,$(MANPAGES))
|
|||||||
INSTALL ?= install
|
INSTALL ?= install
|
||||||
HELP2MAN ?= help2man
|
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
|
DEV_LOG_LEVEL = debug
|
||||||
|
|
||||||
all: release manpages $(RELEASE_OUT)/bscreensaver-settings.desktop
|
all: release manpages $(RELEASE_OUT)/bscreensaver-settings.desktop
|
||||||
@ -70,10 +63,10 @@ install: all
|
|||||||
$(INSTALL) -m 0644 $(RELEASE_MANPAGES) $(DESTDIR)$(MANDIR)/man1
|
$(INSTALL) -m 0644 $(RELEASE_MANPAGES) $(DESTDIR)$(MANDIR)/man1
|
||||||
|
|
||||||
$(DEV_TARGETS): $(SOURCES)
|
$(DEV_TARGETS): $(SOURCES)
|
||||||
HELPER_DIR=target/debug cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS)
|
HELPER_DIR=target/debug cargo build
|
||||||
|
|
||||||
$(RELEASE_TARGETS): $(SOURCES)
|
$(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
|
$(RELEASE_OUT)/%.1.gz: $(RELEASE_OUT)/%.1
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
@ -101,7 +94,7 @@ deb-pkg:
|
|||||||
rm -rf /build/bscreensaver'
|
rm -rf /build/bscreensaver'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cargo $(RUST_RELEASE_CHANNEL_ARG) clean
|
cargo clean
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(addprefix $(DESTDIR)$(BINDIR),$(BINARIES)) $(addprefix $(HELPER_DIR)/,$(HELPERS))) || true
|
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_SYSTEMD_LOG=$(DEV_LOG_LEVEL) \
|
||||||
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
|
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
|
||||||
HELPER_DIR=target/debug \
|
HELPER_DIR=target/debug \
|
||||||
cargo $(RUST_RELEASE_CHANNEL_ARG) run $(FEATURES_ARGS) --bin bscreensaver
|
cargo run --bin bscreensaver
|
||||||
|
|
||||||
run-dialog:
|
run-dialog:
|
||||||
RUST_BACKTRACE=1 \
|
RUST_BACKTRACE=1 \
|
||||||
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
|
BSCREENSAVER_DIALOG_GTK3_LOG=$(DEV_LOG_LEVEL) \
|
||||||
BSCREENSAVER_DIALOG_STANDALONE=1 \
|
BSCREENSAVER_DIALOG_STANDALONE=1 \
|
||||||
cargo $(RUST_RELEASE_CHANNEL_ARG) run $(FEATURES_ARGS) --bin bscreensaver-dialog-gtk3
|
cargo run --bin bscreensaver-dialog-gtk3
|
||||||
|
@ -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 zbus::{dbus_interface, fdo::{self, DBusProxy, RequestNameFlags}, names::{BusName, UniqueName, WellKnownName}, ConnectionBuilder, MessageHeader};
|
||||||
|
|
||||||
use bscreensaver_command::{bscreensaver_command, BCommand};
|
use bscreensaver_command::{bscreensaver_command, BCommand};
|
||||||
|
use bscreensaver_util::opt_contains;
|
||||||
|
|
||||||
const OUR_DBUS_NAME: &str = "org.freedesktop.ScreenSaver";
|
const OUR_DBUS_NAME: &str = "org.freedesktop.ScreenSaver";
|
||||||
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(45);
|
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()?;
|
let args = name_owner_changed.args()?;
|
||||||
match args.name() {
|
match args.name() {
|
||||||
BusName::WellKnown(name) if name == OUR_DBUS_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);
|
info!("Lost bus name {}; quitting", OUR_DBUS_NAME);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
4
debian/rules
vendored
4
debian/rules
vendored
@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
|
||||||
RUST_RELEASE_CHANNEL = nightly
|
|
||||||
|
|
||||||
MAKE_ARGS = \
|
MAKE_ARGS = \
|
||||||
RUST_RELEASE_CHANNEL=$(RUST_RELEASE_CHANNEL) \
|
|
||||||
PREFIX=/usr \
|
PREFIX=/usr \
|
||||||
SYSCONFDIR=/etc \
|
SYSCONFDIR=/etc \
|
||||||
DESTDIR=debian/bscreensaver
|
DESTDIR=debian/bscreensaver
|
||||||
|
@ -12,10 +12,6 @@ readme = "README.md"
|
|||||||
keywords = ["gui", "screensaver", "screen-locker"]
|
keywords = ["gui", "screensaver", "screen-locker"]
|
||||||
categories = ["gui"]
|
categories = ["gui"]
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["use-nightly"]
|
|
||||||
use-nightly = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
clap = "3"
|
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;
|
mod pidfd;
|
||||||
|
|
||||||
use clap::{Arg, Command as ClapCommand};
|
use clap::{Arg, Command as ClapCommand};
|
||||||
@ -31,10 +27,6 @@ use xcb_xembed::embedder::Embedder;
|
|||||||
|
|
||||||
use bscreensaver_command::{BCommand, create_command_window};
|
use bscreensaver_command::{BCommand, create_command_window};
|
||||||
use bscreensaver_util::{*, settings::Configuration};
|
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};
|
use pidfd::{CreatePidFd, PidFd};
|
||||||
|
|
||||||
const BLANKED_ARG: &str = "blanked";
|
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)> {
|
fn start_subservice(binary_name: &str) -> anyhow::Result<(Child, PidFd)> {
|
||||||
let mut command = Command::new(format!("{}/{}", env!("HELPER_DIR"), binary_name));
|
let child = Command::new(format!("{}/{}", env!("HELPER_DIR"), binary_name))
|
||||||
#[cfg(feature = "use-nightly")]
|
.spawn()?;
|
||||||
command.create_pidfd(true);
|
|
||||||
let mut child = command.spawn()?;
|
|
||||||
|
|
||||||
#[cfg(feature = "use-nightly")]
|
|
||||||
let pidfd = child.take_pidfd()?;
|
|
||||||
#[cfg(not(feature = "use-nightly"))]
|
|
||||||
let pidfd = child.create_pidfd()?;
|
let pidfd = child.create_pidfd()?;
|
||||||
|
|
||||||
Ok((child, 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);
|
show_cursor(conn, state);
|
||||||
|
|
||||||
let mut command = Command::new(format!("{}/{}", env!("HELPER_DIR"), state.config.dialog_backend.binary_name()));
|
let mut child = Command::new(format!("{}/{}", env!("HELPER_DIR"), state.config.dialog_backend.binary_name()))
|
||||||
#[cfg(feature = "use-nightly")]
|
|
||||||
command.create_pidfd(true);
|
|
||||||
let mut child = command
|
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()?;
|
.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 child_pidfd = child.create_pidfd()?;
|
||||||
|
let mut child_out = child.stdout.take().unwrap();
|
||||||
|
|
||||||
let mut xid_buf: [u8; 4] = [0; 4];
|
let mut xid_buf: [u8; 4] = [0; 4];
|
||||||
child_out.read_exact(&mut xid_buf)?;
|
child_out.read_exact(&mut xid_buf)?;
|
||||||
@ -983,12 +963,3 @@ fn kill_child_processes(state: &mut State) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
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 struct PidFd(RawFd);
|
||||||
|
|
||||||
pub trait CreatePidFd {
|
pub trait CreatePidFd {
|
||||||
// mut isn't necessary here, but it is for the nightly PidFd stuff,
|
fn create_pidfd(&self) -> nix::Result<PidFd>;
|
||||||
// so keep it like this to avoid a warning when compiling using stable.
|
|
||||||
fn create_pidfd(&mut self) -> nix::Result<PidFd>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreatePidFd for Child {
|
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)
|
pidfd_open(self.id() as RawFd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ pub fn init_logging(env_name: &str) {
|
|||||||
.init();
|
.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> {
|
pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result<x::Atom> {
|
||||||
let cookie = conn.send_request(&x::InternAtom {
|
let cookie = conn.send_request(&x::InternAtom {
|
||||||
only_if_exists: false,
|
only_if_exists: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user