Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "ego"
version = "1.2.0"
edition = "2021"
rust-version = "1.74.0"
edition = "2024"
rust-version = "1.85.0"

# Metadata
authors = ["Marti Raudsepp <marti@juffo.org>"]
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{command, Arg, ArgAction, ArgGroup, Command, ValueHint};
use clap::{Arg, ArgAction, ArgGroup, Command, ValueHint, command};
use log::Level;
use std::ffi::OsString;

Expand Down
2 changes: 1 addition & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::util::paint;
use anstyle::{AnsiColor, Color, Style};
use log::{trace, Level, Log, Metadata, Record};
use log::{Level, Log, Metadata, Record, trace};

struct SimpleLogger {
level: Level,
Expand Down
27 changes: 16 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#[macro_use]
extern crate simple_error;

use crate::cli::{parse_args, Method};
use crate::errors::{print_error, AnyErr, ErrorWithHint};
use crate::cli::{Method, parse_args};
use crate::errors::{AnyErr, ErrorWithHint, print_error};
use crate::util::{exec_command, have_command, sd_booted};
use crate::x11::{x11_add_acl_with_fallback, x11_xhost_add_acl};
use log::{debug, info, log, warn, Level};
use log::{Level, debug, info, log, warn};
use nix::libc::uid_t;
use nix::unistd::{Uid, User};
use posix_acl::{PosixACL, Qualifier, ACL_EXECUTE, ACL_READ, ACL_RWX};
use posix_acl::{ACL_EXECUTE, ACL_READ, ACL_RWX, PosixACL, Qualifier};
use simple_error::SimpleError;
use std::env::VarError;
use std::fs::{DirBuilder, Metadata};
Expand Down Expand Up @@ -243,7 +243,10 @@ fn prepare_x11(ctx: &EgoContext, old_xhost: bool) -> Result<Vec<String>, AnyErr>
}

if old_xhost {
warn!("--old-xhost is deprecated. If there are issues with the new method, please report a bug.");
warn!(
"--old-xhost is deprecated. \
If there are issues with the new method, please report a bug."
);
x11_xhost_add_acl("localuser", &ctx.target_user)?;
} else {
x11_add_acl_with_fallback("localuser", &ctx.target_user)?;
Expand Down Expand Up @@ -420,12 +423,14 @@ fn run_machinectl_command(
args.push("/bin/sh".to_string());
args.push("-c".to_string());
let remote_cmd = if remote_cmd.is_empty() {
vec![require_with!(
ctx.target_user_shell.to_str(),
"User '{}' shell has unexpected characters",
ctx.target_user
)
.to_string()]
vec![
require_with!(
ctx.target_user_shell.to_str(),
"User '{}' shell has unexpected characters",
ctx.target_user
)
.to_string(),
]
} else {
remote_cmd
};
Expand Down
20 changes: 11 additions & 9 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::fmt::Write;
use std::path::PathBuf;
use std::sync::OnceLock;

use clap_complete::shells::{Bash, Fish, Zsh};
use clap_complete::Generator;
use log::{info, Level};
use clap_complete::shells::{Bash, Fish, Zsh};
use log::{Level, info};
use snapbox::Assert;
use snapbox::{file, Data};
use snapbox::{Data, file};

use crate::cli::{build_cli, parse_args, Method};
use crate::cli::{Method, build_cli, parse_args};
use crate::util::have_command;
use crate::x11::x11_xcb_add_acl;
use crate::{check_user_homedir, get_wayland_socket, EgoContext};
use crate::{EgoContext, check_user_homedir, get_wayland_socket};

/// `vec![]` constructor that converts arguments to String
macro_rules! string_vec {
Expand Down Expand Up @@ -80,26 +80,28 @@ fn test_context() -> EgoContext {
}
}

/// SAFETY: unsafe changes to environment variables
#[test]
fn wayland_socket() {
let ctx = test_context();
env::remove_var("WAYLAND_DISPLAY");
unsafe { env::remove_var("WAYLAND_DISPLAY") };
assert_eq!(get_wayland_socket(&ctx).unwrap(), None);

env::set_var("WAYLAND_DISPLAY", "wayland-7");
unsafe { env::set_var("WAYLAND_DISPLAY", "wayland-7") };
assert_eq!(
get_wayland_socket(&ctx).unwrap().unwrap(),
PathBuf::from("/run/user/1000/wayland-7")
);

env::set_var("WAYLAND_DISPLAY", "/tmp/wayland-7");
unsafe { env::set_var("WAYLAND_DISPLAY", "/tmp/wayland-7") };
assert_eq!(get_wayland_socket(&ctx).unwrap().unwrap(), PathBuf::from("/tmp/wayland-7"));
}

/// SAFETY: unsafe changes to environment variables
#[test]
#[cfg_attr(not(target_os = "linux"), ignore = "Linux-specifix")]
fn test_x11_error() {
env::remove_var("DISPLAY");
unsafe { env::remove_var("DISPLAY") };

let err = x11_xcb_add_acl("test", "test").unwrap_err();
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::{debug, warn};
use xcb::x::{ChangeHosts, Family, HostMode};
use xcb::{ConnError, Connection};

use crate::errors::{print_error, AnyErr, ErrorWithHint};
use crate::errors::{AnyErr, ErrorWithHint, print_error};
use crate::util::run_command;

/// Try `libxcb`, fall back to `xhost`.
Expand Down