@@ -6,7 +6,7 @@ use std::net::TcpStream;
6
6
#[ cfg( unix) ]
7
7
use std:: os:: unix:: io:: { AsRawFd , IntoRawFd } ;
8
8
#[ cfg( unix) ]
9
- use std:: os:: unix:: net:: UnixStream ;
9
+ use std:: os:: unix:: net:: { UnixListener , UnixStream } ;
10
10
use std:: process:: Child ;
11
11
12
12
#[ cfg( unix) ]
@@ -28,13 +28,11 @@ pub fn varlink_connect<S: ?Sized + AsRef<str>>(address: &S) -> Result<(Box<dyn S
28
28
Box :: new ( TcpStream :: connect ( addr) . map_err ( map_context ! ( ) ) ?) ,
29
29
new_address,
30
30
) )
31
+ } else if let Some ( addr) = new_address. strip_prefix ( "unix:@" ) {
32
+ let addr = addr. split ( ';' ) . next ( ) . unwrap_or ( addr) ;
33
+ get_abstract_unixstream ( addr) . map ( |v| ( Box :: new ( v) as Box < dyn Stream > , new_address) )
31
34
} else if let Some ( addr) = new_address. strip_prefix ( "unix:" ) {
32
- let mut addr = String :: from ( addr. split ( ';' ) . next ( ) . unwrap ( ) ) ;
33
- if addr. starts_with ( '@' ) {
34
- addr = addr. replacen ( '@' , "\0 " , 1 ) ;
35
- return get_abstract_unixstream ( & addr)
36
- . map ( |v| ( Box :: new ( v) as Box < dyn Stream > , new_address) ) ;
37
- }
35
+ let addr = addr. split ( ';' ) . next ( ) . unwrap_or ( addr) ;
38
36
Ok ( (
39
37
Box :: new ( UnixStream :: connect ( addr) . map_err ( map_context ! ( ) ) ?) ,
40
38
new_address,
@@ -46,18 +44,11 @@ pub fn varlink_connect<S: ?Sized + AsRef<str>>(address: &S) -> Result<(Box<dyn S
46
44
47
45
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
48
46
fn get_abstract_unixstream ( addr : & str ) -> Result < UnixStream > {
49
- // FIXME: abstract unix domains sockets still not in std
50
- // FIXME: https://github.com/rust-lang/rust/issues/14194
51
- use std:: os:: unix:: io:: FromRawFd ;
52
- use unix_socket:: UnixStream as AbstractStream ;
47
+ use std:: os:: linux:: net:: SocketAddrExt ;
48
+ use std:: os:: unix:: net:: SocketAddr ;
53
49
54
- unsafe {
55
- Ok ( UnixStream :: from_raw_fd (
56
- AbstractStream :: connect ( addr)
57
- . map_err ( map_context ! ( ) ) ?
58
- . into_raw_fd ( ) ,
59
- ) )
60
- }
50
+ let addr = SocketAddr :: from_abstract_name ( addr) . map_err ( map_context ! ( ) ) ?;
51
+ UnixStream :: connect_addr ( & addr) . map_err ( map_context ! ( ) )
61
52
}
62
53
63
54
#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
@@ -85,8 +76,6 @@ pub fn varlink_exec<S: ?Sized + AsRef<str>>(
85
76
86
77
let executable = String :: from ( "exec " ) + address. as_ref ( ) ;
87
78
88
- use unix_socket:: UnixListener ;
89
-
90
79
let dir = tempdir ( ) . map_err ( map_context ! ( ) ) ?;
91
80
let file_path = dir. path ( ) . join ( "varlink-socket" ) ;
92
81
@@ -153,7 +142,6 @@ pub fn varlink_bridge<S: ?Sized + AsRef<str>>(address: &S) -> Result<(Child, Box
153
142
use std:: process:: Command ;
154
143
155
144
let executable = address. as_ref ( ) ;
156
- // use unix_socket::UnixStream;
157
145
let ( stream0, stream1) = UnixStream :: pair ( ) . map_err ( map_context ! ( ) ) ?;
158
146
let fd = stream1. into_raw_fd ( ) ;
159
147
let childin = unsafe { :: std:: fs:: File :: from_raw_fd ( fd) } ;
0 commit comments