11use anyhow:: Result ;
2- use bpaf:: { construct, long, OptionParser , Parser } ;
32use nix:: errno:: Errno ;
43use nix:: fcntl:: readlink;
54use nix:: libc:: {
@@ -18,7 +17,7 @@ use nix::sys::socket::{
1817use nix:: sys:: stat:: fstat;
1918use nix:: sys:: uio:: { process_vm_writev, RemoteIoVec } ;
2019use nix:: sys:: wait:: { waitpid, WaitPidFlag , WaitStatus } ;
21- use nix:: unistd:: { getresgid , getresuid , mkstemp, read, setegid , seteuid , Pid } ;
20+ use nix:: unistd:: { mkstemp, read, Pid } ;
2221use nix:: { cmsg_space, ioctl_read, ioctl_readwrite, ioctl_write_ptr, NixPath } ;
2322use std:: borrow:: Cow ;
2423use std:: cell:: RefCell ;
@@ -1445,36 +1444,8 @@ fn find_vdso(pid: Option<Pid>) -> Result<(usize, usize), Errno> {
14451444 Err ( Errno :: EINVAL )
14461445}
14471446
1448- #[ derive( Clone , Debug ) ]
1449- pub struct Options {
1450- listen_display : String ,
1451- }
1452-
1453- pub fn options ( ) -> OptionParser < Options > {
1454- let listen_display = long ( "listen-display" )
1455- . short ( 'l' )
1456- . help ( "The X11 display number to listen on" )
1457- . argument ( "DISPLAY" )
1458- . fallback ( ":0" . into ( ) ) ;
1459-
1460- construct ! ( Options { listen_display } ) . to_options ( )
1461- }
1462-
1463- fn main ( ) {
1464- let options = options ( ) . fallback_to_usage ( ) . run ( ) ;
1465-
1466- let display = if options. listen_display . starts_with ( ':' ) {
1467- options. listen_display [ 1 ..] . parse :: < u32 > ( ) . ok ( )
1468- } else {
1469- None
1470- } ;
1471-
1472- let sock_path = if let Some ( display) = display {
1473- format ! ( "/tmp/.X11-unix/X{}" , display)
1474- } else {
1475- eprintln ! ( "Invalid --listen-display value" ) ;
1476- exit ( 1 )
1477- } ;
1447+ pub fn start_x11bridge ( display : u32 ) {
1448+ let sock_path = format ! ( "/tmp/.X11-unix/X{}" , display) ;
14781449
14791450 // Look for a syscall instruction in the vDSO. We assume all processes map
14801451 // the same vDSO (which should be true if they are running under the same
@@ -1495,21 +1466,7 @@ fn main() {
14951466
14961467 let epoll = Epoll :: new ( EpollCreateFlags :: empty ( ) ) . unwrap ( ) ;
14971468 _ = fs:: remove_file ( & sock_path) ;
1498- let resuid = getresuid ( ) . unwrap ( ) ;
1499- let resgid = getresgid ( ) . unwrap ( ) ;
1500- if resuid. real != resuid. effective {
1501- seteuid ( resuid. real ) . unwrap ( ) ;
1502- }
1503- if resgid. real != resgid. effective {
1504- setegid ( resgid. real ) . unwrap ( )
1505- }
15061469 let listen_sock = UnixListener :: bind ( sock_path) . unwrap ( ) ;
1507- if resuid. real != resuid. effective {
1508- seteuid ( resuid. effective ) . unwrap ( ) ;
1509- }
1510- if resgid. real != resgid. effective {
1511- setegid ( resgid. effective ) . unwrap ( )
1512- }
15131470 epoll
15141471 . add (
15151472 & listen_sock,
@@ -1640,13 +1597,3 @@ fn main() {
16401597 }
16411598 }
16421599}
1643-
1644- #[ cfg( test) ]
1645- mod tests {
1646- use super :: * ;
1647-
1648- #[ test]
1649- fn check_options ( ) {
1650- options ( ) . check_invariants ( false )
1651- }
1652- }
0 commit comments