add a environment variable to the direct session...
...that is used as a fallback if no explicit tty is requested
This commit is contained in:
parent
3392c0c675
commit
453f33d5a4
|
@ -11,7 +11,8 @@
|
||||||
//! ### Initialization
|
//! ### Initialization
|
||||||
//!
|
//!
|
||||||
//! To initialize the session you may pass the path to any tty device, that shall be used.
|
//! To initialize the session you may pass the path to any tty device, that shall be used.
|
||||||
//! If no path is given the tty used to start this compositor (if any) will be used.
|
//! If no path is given the tty used to start this compositor (if any) will be used unless
|
||||||
|
//! the [SMITHAY_DIRECT_TTY_ENV] environment variable is set.
|
||||||
//! A new session and its notifier will be returned.
|
//! A new session and its notifier will be returned.
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```rust,no_run
|
||||||
|
@ -59,7 +60,8 @@ use nix::{
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
os::unix::io::RawFd,
|
os::unix::io::RawFd,
|
||||||
path::Path,
|
path::{Path, PathBuf},
|
||||||
|
str::FromStr,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
|
@ -68,6 +70,11 @@ use std::{
|
||||||
#[cfg(feature = "backend_udev")]
|
#[cfg(feature = "backend_udev")]
|
||||||
use udev::Device as UdevDevice;
|
use udev::Device as UdevDevice;
|
||||||
|
|
||||||
|
/// This environment variable can be used to specify a tty path
|
||||||
|
/// that will be used in [DirectSession::new] in case no explicit
|
||||||
|
/// tty path has been provided.
|
||||||
|
pub const SMITHAY_DIRECT_TTY_ENV: &str = "SMITHAY_DIRECT_TTY";
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod tty {
|
mod tty {
|
||||||
ioctl_read_bad!(kd_get_mode, 0x4B3B, i16);
|
ioctl_read_bad!(kd_get_mode, 0x4B3B, i16);
|
||||||
|
@ -185,7 +192,8 @@ impl fmt::Debug for DirectSessionNotifier {
|
||||||
impl DirectSession {
|
impl DirectSession {
|
||||||
/// Tries to create a new session via the legacy virtual terminal interface.
|
/// Tries to create a new session via the legacy virtual terminal interface.
|
||||||
///
|
///
|
||||||
/// If you do not provide a tty device path, it will try to open the currently active tty if any.
|
/// If you do not provide a tty device path, it will try to open the tty set
|
||||||
|
/// in the [SMITHAY_DIRECT_TTY_ENV] environment variable or if unset the currently active tty if any.
|
||||||
pub fn new<L>(tty: Option<&Path>, logger: L) -> Result<(DirectSession, DirectSessionNotifier), Error>
|
pub fn new<L>(tty: Option<&Path>, logger: L) -> Result<(DirectSession, DirectSessionNotifier), Error>
|
||||||
where
|
where
|
||||||
L: Into<Option<::slog::Logger>>,
|
L: Into<Option<::slog::Logger>>,
|
||||||
|
@ -193,6 +201,39 @@ impl DirectSession {
|
||||||
let logger = crate::slog_or_fallback(logger)
|
let logger = crate::slog_or_fallback(logger)
|
||||||
.new(o!("smithay_module" => "backend_session", "session_type" => "direct/vt"));
|
.new(o!("smithay_module" => "backend_session", "session_type" => "direct/vt"));
|
||||||
|
|
||||||
|
let direct_path: PathBuf;
|
||||||
|
let tty = if tty.is_none() {
|
||||||
|
if let Ok(direct_tty) = std::env::var(SMITHAY_DIRECT_TTY_ENV) {
|
||||||
|
info!(
|
||||||
|
logger,
|
||||||
|
"{} is set in environment, trying to open {}", SMITHAY_DIRECT_TTY_ENV, &direct_tty
|
||||||
|
);
|
||||||
|
|
||||||
|
let path = PathBuf::from_str(&direct_tty);
|
||||||
|
|
||||||
|
match path {
|
||||||
|
Ok(path) => {
|
||||||
|
direct_path = path;
|
||||||
|
Some(direct_path.as_path())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
warn!(
|
||||||
|
logger,
|
||||||
|
"Failed to parse {} with value \"{}\": {}",
|
||||||
|
SMITHAY_DIRECT_TTY_ENV,
|
||||||
|
direct_tty,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tty
|
||||||
|
};
|
||||||
|
|
||||||
let fd = tty
|
let fd = tty
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
open(
|
open(
|
||||||
|
|
Loading…
Reference in New Issue