@@ -5,7 +5,7 @@ use std::{
55 fmt,
66 fs:: File ,
77 io,
8- os:: fd:: { AsRawFd , FromRawFd , OwnedFd } ,
8+ os:: fd:: { AsFd , AsRawFd , FromRawFd , OwnedFd } ,
99 ptr:: null_mut,
1010} ;
1111
@@ -115,9 +115,9 @@ impl io::Write for PtyLeader {
115115 }
116116}
117117
118- impl AsRawFd for PtyLeader {
119- fn as_raw_fd ( & self ) -> std:: os:: fd:: RawFd {
120- self . file . as_raw_fd ( )
118+ impl AsFd for PtyLeader {
119+ fn as_fd ( & self ) -> std:: os:: fd:: BorrowedFd < ' _ > {
120+ self . file . as_fd ( )
121121 }
122122}
123123
@@ -131,9 +131,9 @@ impl PtyFollower {
131131 }
132132}
133133
134- impl AsRawFd for PtyFollower {
135- fn as_raw_fd ( & self ) -> std:: os:: fd:: RawFd {
136- self . file . as_raw_fd ( )
134+ impl AsFd for PtyFollower {
135+ fn as_fd ( & self ) -> std:: os:: fd:: BorrowedFd < ' _ > {
136+ self . file . as_fd ( )
137137 }
138138}
139139
@@ -144,11 +144,11 @@ impl From<PtyFollower> for std::process::Stdio {
144144}
145145
146146mod sealed {
147- use std:: os:: fd:: AsRawFd ;
147+ use std:: os:: fd:: AsFd ;
148148
149149 pub ( crate ) trait Sealed { }
150150
151- impl < F : AsRawFd > Sealed for F { }
151+ impl < F : AsFd > Sealed for F { }
152152}
153153
154154pub ( crate ) trait Terminal : sealed:: Sealed {
@@ -160,49 +160,49 @@ pub(crate) trait Terminal: sealed::Sealed {
160160 fn tcgetsid ( & self ) -> io:: Result < ProcessId > ;
161161}
162162
163- impl < F : AsRawFd > Terminal for F {
163+ impl < F : AsFd > Terminal for F {
164164 /// Get the foreground process group ID associated with this terminal.
165165 fn tcgetpgrp ( & self ) -> io:: Result < ProcessId > {
166166 // SAFETY: tcgetpgrp cannot cause UB
167- let id = cerr ( unsafe { libc:: tcgetpgrp ( self . as_raw_fd ( ) ) } ) ?;
167+ let id = cerr ( unsafe { libc:: tcgetpgrp ( self . as_fd ( ) . as_raw_fd ( ) ) } ) ?;
168168 Ok ( ProcessId :: new ( id) )
169169 }
170170 /// Set the foreground process group ID associated with this terminal to `pgrp`.
171171 fn tcsetpgrp ( & self , pgrp : ProcessId ) -> io:: Result < ( ) > {
172172 // SAFETY: tcsetpgrp cannot cause UB
173- cerr ( unsafe { libc:: tcsetpgrp ( self . as_raw_fd ( ) , pgrp. inner ( ) ) } ) . map ( |_| ( ) )
173+ cerr ( unsafe { libc:: tcsetpgrp ( self . as_fd ( ) . as_raw_fd ( ) , pgrp. inner ( ) ) } ) . map ( |_| ( ) )
174174 }
175175
176176 /// Make the given terminal the controlling terminal of the calling process.
177177 fn make_controlling_terminal ( & self ) -> io:: Result < ( ) > {
178178 // SAFETY: this is a correct way to call the TIOCSCTTY ioctl, see:
179179 // https://www.man7.org/linux/man-pages/man2/TIOCNOTTY.2const.html
180- cerr ( unsafe { libc:: ioctl ( self . as_raw_fd ( ) , libc:: TIOCSCTTY , 0 ) } ) ?;
180+ cerr ( unsafe { libc:: ioctl ( self . as_fd ( ) . as_raw_fd ( ) , libc:: TIOCSCTTY , 0 ) } ) ?;
181181 Ok ( ( ) )
182182 }
183183
184184 /// Get the filename of the tty
185185 fn ttyname ( & self ) -> io:: Result < OsString > {
186186 let mut buf: [ libc:: c_char ; 1024 ] = [ 0 ; 1024 ] ;
187187
188- if !safe_isatty ( self . as_raw_fd ( ) ) {
188+ if !safe_isatty ( self . as_fd ( ) ) {
189189 return Err ( io:: ErrorKind :: Unsupported . into ( ) ) ;
190190 }
191191
192192 // SAFETY: `buf` is a valid and initialized pointer, and its correct length is passed
193- cerr ( unsafe { libc:: ttyname_r ( self . as_raw_fd ( ) , buf. as_mut_ptr ( ) , buf. len ( ) ) } ) ?;
193+ cerr ( unsafe { libc:: ttyname_r ( self . as_fd ( ) . as_raw_fd ( ) , buf. as_mut_ptr ( ) , buf. len ( ) ) } ) ?;
194194 // SAFETY: `buf` will have been initialized by the `ttyname_r` call, if it succeeded
195195 Ok ( unsafe { os_string_from_ptr ( buf. as_ptr ( ) ) } )
196196 }
197197
198198 /// Rust standard library "IsTerminal" is not secure for setuid programs (CVE-2023-2002)
199199 fn is_terminal ( & self ) -> bool {
200- safe_isatty ( self . as_raw_fd ( ) )
200+ safe_isatty ( self . as_fd ( ) )
201201 }
202202
203203 fn tcgetsid ( & self ) -> io:: Result < ProcessId > {
204204 // SAFETY: tcgetsid cannot cause UB
205- let id = cerr ( unsafe { libc:: tcgetsid ( self . as_raw_fd ( ) ) } ) ?;
205+ let id = cerr ( unsafe { libc:: tcgetsid ( self . as_fd ( ) . as_raw_fd ( ) ) } ) ?;
206206 Ok ( ProcessId :: new ( id) )
207207 }
208208}
0 commit comments