XWayland works now
This commit is contained in:
parent
078a1a547b
commit
4632b9b5f4
@ -30,6 +30,7 @@ pub enum Error {
|
|||||||
LaunchFailed(String, io::Error),
|
LaunchFailed(String, io::Error),
|
||||||
RebootFailed(io::Error),
|
RebootFailed(io::Error),
|
||||||
OpenLogFailed(io::Error),
|
OpenLogFailed(io::Error),
|
||||||
|
XAuthFail(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
@ -65,6 +66,7 @@ impl fmt::Display for Error {
|
|||||||
LaunchFailed(exec, err) => write!(f, "unable to execute {}: {}", exec, err),
|
LaunchFailed(exec, err) => write!(f, "unable to execute {}: {}", exec, err),
|
||||||
RebootFailed(err) => write!(f, "could not reboot system: {}", err),
|
RebootFailed(err) => write!(f, "could not reboot system: {}", err),
|
||||||
OpenLogFailed(err) => write!(f, "failed to open log file: {}", err),
|
OpenLogFailed(err) => write!(f, "failed to open log file: {}", err),
|
||||||
|
XAuthFail(err) => write!(f, "error creating .Xauthority file: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
|
|
||||||
use crate::{Error, Result, Logger, LogLevel};
|
use crate::{Error, Result, Logger, LogLevel};
|
||||||
use crate::cmdline::CmdLine;
|
use crate::cmdline::CmdLine;
|
||||||
use crate::sys::{sethostname, setsid, set_controlling_tty, mount_devtmpfs, mount_tmpfs, mkdir, umount, mount_sysfs, mount_procfs, mount_devpts, chown, chmod, create_directories, mount_overlay, move_mount, pivot_root, mount_9p, mount, waitpid, reboot, getpid, mount_tmpdir, mount_cgroup, mkdir_mode};
|
use crate::sys::{sethostname, setsid, set_controlling_tty, mount_devtmpfs, mount_tmpfs, mkdir, umount, mount_sysfs, mount_procfs, mount_devpts, chown, chmod, create_directories, mount_overlay, move_mount, pivot_root, mount_9p, mount, waitpid, reboot, getpid, mount_tmpdir, mount_cgroup, mkdir_mode, umask, _chown};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fs, process, io, env};
|
use std::{fs, process, io, env};
|
||||||
use crate::service::{Service, ServiceLaunch};
|
use crate::service::{Service, ServiceLaunch};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
pub struct InitServer {
|
pub struct InitServer {
|
||||||
hostname: String,
|
hostname: String,
|
||||||
@ -38,6 +39,7 @@ impl InitServer {
|
|||||||
|
|
||||||
fn initialize(&self) -> Result<()> {
|
fn initialize(&self) -> Result<()> {
|
||||||
self.set_loglevel();
|
self.set_loglevel();
|
||||||
|
umask(0);
|
||||||
sethostname(&self.hostname)?;
|
sethostname(&self.hostname)?;
|
||||||
setsid()?;
|
setsid()?;
|
||||||
set_controlling_tty(0, true)?;
|
set_controlling_tty(0, true)?;
|
||||||
@ -161,6 +163,12 @@ impl InitServer {
|
|||||||
let dbus = ServiceLaunch::new("dbus-daemon", "/usr/bin/dbus-daemon")
|
let dbus = ServiceLaunch::new("dbus-daemon", "/usr/bin/dbus-daemon")
|
||||||
.base_environment()
|
.base_environment()
|
||||||
.uidgid(1000,1000)
|
.uidgid(1000,1000)
|
||||||
|
.env("HOME", "/home/user")
|
||||||
|
.env("NO_AT_BRIDGE", "1")
|
||||||
|
.env("QT_ACCESSIBILITY", "1")
|
||||||
|
.env("SHELL", "/bin/bash")
|
||||||
|
.env("USER", "user")
|
||||||
|
.env("WAYLAND_DISPLAY", "wayland-0")
|
||||||
.arg("--session")
|
.arg("--session")
|
||||||
.arg("--nosyslog")
|
.arg("--nosyslog")
|
||||||
.arg("--address=unix:path=/run/user/1000/bus")
|
.arg("--address=unix:path=/run/user/1000/bus")
|
||||||
@ -179,6 +187,51 @@ impl InitServer {
|
|||||||
|
|
||||||
self.services.insert(sommelier.pid(), sommelier);
|
self.services.insert(sommelier.pid(), sommelier);
|
||||||
|
|
||||||
|
Self::write_xauth().map_err(Error::XAuthFail)?;
|
||||||
|
|
||||||
|
let sommelierx = ServiceLaunch::new("sommelier-x", "/opt/ph/usr/bin/sommelier")
|
||||||
|
.base_environment()
|
||||||
|
.uidgid(1000,1000)
|
||||||
|
.arg("-X")
|
||||||
|
.arg("--x-display=0")
|
||||||
|
.arg("--no-exit-with-child")
|
||||||
|
.arg("--x-auth=/home/user/.Xauthority")
|
||||||
|
.arg("/bin/true")
|
||||||
|
.pipe_output()
|
||||||
|
.launch()?;
|
||||||
|
|
||||||
|
|
||||||
|
self.services.insert(sommelierx.pid(), sommelierx);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_xauth() -> io::Result<()> {
|
||||||
|
let xauth_path = "/home/user/.Xauthority";
|
||||||
|
|
||||||
|
let mut randbuf = [0; 16];
|
||||||
|
let mut file = fs::File::open("/dev/urandom")?;
|
||||||
|
file.read_exact(&mut randbuf)?;
|
||||||
|
|
||||||
|
let mut v: Vec<u8> = Vec::new();
|
||||||
|
|
||||||
|
// ???
|
||||||
|
v.extend_from_slice(&[0x01, 0x00]);
|
||||||
|
// "airwolf".len()
|
||||||
|
v.extend_from_slice(&[0x00, 0x07]);
|
||||||
|
v.extend_from_slice(b"airwolf");
|
||||||
|
// "0".len() (DISPLAY=:0)
|
||||||
|
v.extend_from_slice(&[0x00, 0x01]);
|
||||||
|
v.extend_from_slice(b"0");
|
||||||
|
// "MIT-MAGIC-COOKIE-a".len()
|
||||||
|
v.extend_from_slice(&[0x00, 0x12]);
|
||||||
|
v.extend_from_slice(b"MIT-MAGIC-COOKIE-1");
|
||||||
|
// randbuf.len()
|
||||||
|
v.extend_from_slice(&[0x00, 0x10]);
|
||||||
|
v.extend_from_slice(&randbuf);
|
||||||
|
|
||||||
|
fs::write("/home/user/.Xauthority", v)?;
|
||||||
|
_chown(xauth_path, 1000, 1000)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +242,7 @@ impl InitServer {
|
|||||||
|
|
||||||
let shell = ServiceLaunch::new_shell(root, home, realm)
|
let shell = ServiceLaunch::new_shell(root, home, realm)
|
||||||
.launch_with_preexec(move || {
|
.launch_with_preexec(move || {
|
||||||
|
// set_controlling_tty(0, true)?;
|
||||||
env::set_current_dir(home)?;
|
env::set_current_dir(home)?;
|
||||||
println!("{}", splash);
|
println!("{}", splash);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -15,7 +15,7 @@ pub fn mount_tmpfs(target: &str) -> Result<()> {
|
|||||||
|
|
||||||
pub fn mount_tmpdir(target: &str) -> Result<()> {
|
pub fn mount_tmpdir(target: &str) -> Result<()> {
|
||||||
mount("tmpfs", target, "tmpfs",
|
mount("tmpfs", target, "tmpfs",
|
||||||
libc::MS_NOSUID|libc::MS_NODEV,
|
libc::MS_NOSUID|libc::MS_NODEV|libc::MS_NOEXEC,
|
||||||
Some("mode=1777"))
|
Some("mode=1777"))
|
||||||
.map_err(|e| Error::MountTmpFS(target.to_string(), e))
|
.map_err(|e| Error::MountTmpFS(target.to_string(), e))
|
||||||
}
|
}
|
||||||
@ -88,6 +88,12 @@ pub fn create_directories<P: AsRef<Path>>(directories: &[P]) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn umask(mode: u32) {
|
||||||
|
unsafe {
|
||||||
|
libc::umask(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mkdir<P: AsRef<Path>>(path: P) -> Result<()> {
|
pub fn mkdir<P: AsRef<Path>>(path: P) -> Result<()> {
|
||||||
mkdir_mode(path, 0o755)
|
mkdir_mode(path, 0o755)
|
||||||
}
|
}
|
||||||
@ -217,11 +223,14 @@ pub fn chmod(path: &str, mode: u32) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn chown(path: &str, uid: u32, gid: u32) -> Result<()> {
|
pub fn chown(path: &str, uid: u32, gid: u32) -> Result<()> {
|
||||||
|
_chown(path, uid, gid).map_err(Error::ChmodFailed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn _chown(path: &str, uid: u32, gid: u32) -> io::Result<()> {
|
||||||
let path = cstr(path);
|
let path = cstr(path);
|
||||||
unsafe {
|
unsafe {
|
||||||
if libc::chown(path.as_ptr(), uid, gid) == -1 {
|
if libc::chown(path.as_ptr(), uid, gid) == -1 {
|
||||||
let last = io::Error::last_os_error();
|
return Err(io::Error::last_os_error());
|
||||||
return Err(Error::ChmodFailed(last));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user