File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ use crate::ttrpc::{Code, Request};
16
16
use crate :: MessageHeader ;
17
17
use futures:: StreamExt as _;
18
18
use std:: marker:: Unpin ;
19
- use std:: os:: unix:: io:: FromRawFd ;
19
+ use std:: os:: unix:: io:: { AsRawFd , FromRawFd } ;
20
20
use std:: os:: unix:: net:: UnixListener as SysUnixListener ;
21
21
use tokio:: {
22
22
self ,
@@ -118,11 +118,12 @@ impl Server {
118
118
pub async fn do_start < I , S > ( & self , listenfd : RawFd , mut incoming : I ) -> Result < ( ) >
119
119
where
120
120
I : Stream < Item = std:: io:: Result < S > > + Unpin ,
121
- S : AsyncRead + AsyncWrite + Send + ' static ,
121
+ S : AsyncRead + AsyncWrite + AsRawFd + Send + ' static ,
122
122
{
123
123
while let Some ( result) = incoming. next ( ) . await {
124
124
match result {
125
125
Ok ( stream) => {
126
+ common:: set_fd_close_exec ( stream. as_raw_fd ( ) ) ?;
126
127
let methods = self . methods . clone ( ) ;
127
128
tokio:: spawn ( async move {
128
129
let ( mut reader, mut writer) = split ( stream) ;
Original file line number Diff line number Diff line change 8
8
#![ allow( unused_macros) ]
9
9
10
10
use crate :: error:: { Error , Result } ;
11
- use nix:: fcntl:: { fcntl, FcntlArg , OFlag } ;
11
+ use nix:: fcntl:: { fcntl, FcntlArg , FdFlag , OFlag } ;
12
12
use nix:: sys:: socket:: * ;
13
13
use std:: os:: unix:: io:: RawFd ;
14
14
use std:: str:: FromStr ;
@@ -54,6 +54,16 @@ pub fn parse_host(host: &str) -> Result<(Domain, Vec<&str>)> {
54
54
Ok ( ( domain, hostv) )
55
55
}
56
56
57
+ pub fn set_fd_close_exec ( fd : RawFd ) -> Result < RawFd > {
58
+ if let Err ( e) = fcntl ( fd, FcntlArg :: F_SETFD ( FdFlag :: FD_CLOEXEC ) ) {
59
+ return Err ( Error :: Others ( format ! (
60
+ "failed to set fd: {} as close-on-exec: {}" ,
61
+ fd, e
62
+ ) ) ) ;
63
+ }
64
+ Ok ( fd)
65
+ }
66
+
57
67
pub fn do_bind ( host : & str ) -> Result < ( RawFd , Domain ) > {
58
68
let ( domain, hostv) = parse_host ( host) ?;
59
69
You can’t perform that action at this time.
0 commit comments