fix: shutdown
This commit is contained in:
1 parent
2cff6be976
commit
140bbe0e84
1 file changed
+20
-10
+20
-10
@@ -13,7 +13,6 @@ use crate::password;
|
|||||||
const GIO_UNIMAP: Opcode = 0x4B66;
|
const GIO_UNIMAP: Opcode = 0x4B66;
|
||||||
const VT_GETSTATE: Opcode = 0x5603;
|
const VT_GETSTATE: Opcode = 0x5603;
|
||||||
const VT_ACTIVATE: Opcode = 0x5606;
|
const VT_ACTIVATE: Opcode = 0x5606;
|
||||||
const VT_WAITACTIVE: Opcode = 0x5607;
|
|
||||||
const VIRTUAL_TERMINAL_PREFIX: &str = "/dev/tty";
|
const VIRTUAL_TERMINAL_PREFIX: &str = "/dev/tty";
|
||||||
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
||||||
const ALERTS_ONLY: &str = "1";
|
const ALERTS_ONLY: &str = "1";
|
||||||
@@ -61,6 +60,9 @@ impl Console {
|
|||||||
if let Some(quiet_kernel) = &mut self.quiet_kernel {
|
if let Some(quiet_kernel) = &mut self.quiet_kernel {
|
||||||
quiet_kernel.keep_quiet();
|
quiet_kernel.keep_quiet();
|
||||||
}
|
}
|
||||||
|
if let Some(foreground) = &self.foreground {
|
||||||
|
foreground.insist();
|
||||||
|
}
|
||||||
self.glyphs = font_glyphs();
|
self.glyphs = font_glyphs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,9 +154,16 @@ struct VtState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ForegroundVt {
|
struct ForegroundVt {
|
||||||
|
own: u16,
|
||||||
previous: u16,
|
previous: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn active_vt() -> Option<u16> {
|
||||||
|
let state: VtState =
|
||||||
|
unsafe { ioctl(stdin(), Getter::<VT_GETSTATE, VtState>::new()) }.ok()?;
|
||||||
|
Some(state.active)
|
||||||
|
}
|
||||||
|
|
||||||
impl ForegroundVt {
|
impl ForegroundVt {
|
||||||
fn take() -> Option<Self> {
|
fn take() -> Option<Self> {
|
||||||
let name = ttyname(stdin(), Vec::new()).ok()?;
|
let name = ttyname(stdin(), Vec::new()).ok()?;
|
||||||
@@ -165,14 +174,17 @@ impl ForegroundVt {
|
|||||||
.parse()
|
.parse()
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|number| *number > 0)?;
|
.filter(|number| *number > 0)?;
|
||||||
let state: VtState =
|
let previous = active_vt()?;
|
||||||
unsafe { ioctl(stdin(), Getter::<VT_GETSTATE, VtState>::new()) }.ok()?;
|
if previous != own {
|
||||||
if state.active != own {
|
|
||||||
activate(own).ok()?;
|
activate(own).ok()?;
|
||||||
}
|
}
|
||||||
Some(Self {
|
Some(Self { own, previous })
|
||||||
previous: state.active,
|
}
|
||||||
})
|
|
||||||
|
fn insist(&self) {
|
||||||
|
if active_vt().is_some_and(|active| active != self.own) {
|
||||||
|
let _ = activate(self.own);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +200,5 @@ impl Drop for ForegroundVt {
|
|||||||
|
|
||||||
fn activate(number: u16) -> Result<(), Errno> {
|
fn activate(number: u16) -> Result<(), Errno> {
|
||||||
let number = usize::from(number);
|
let number = usize::from(number);
|
||||||
unsafe { ioctl(stdin(), IntegerSetter::<VT_ACTIVATE>::new_usize(number)) }?;
|
unsafe { ioctl(stdin(), IntegerSetter::<VT_ACTIVATE>::new_usize(number)) }
|
||||||
unsafe { ioctl(stdin(), IntegerSetter::<VT_WAITACTIVE>::new_usize(number)) }?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user