Debian Codegraph @

src/system/term/mod.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 mod user_termrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/;
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
4 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#, c_ucharrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uchar#},
5 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/,
6 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#,
7 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/,
8 osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#, AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, FromRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/FromRawFd#, OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#},
9 ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().,
10 };
11
12 use libcrust-analyzer cargo libc 0.2.186 crate/::{TIOCSWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCSWINSZ., ioctlrust-analyzer cargo libc 0.2.186 ioctl()., winsizerust-analyzer cargo libc 0.2.186 unix/winsize#};
13
14 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::cutilsrust-analyzer cargo sudo-rs 0.2.14 cutils/::{cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr()., is_fifo_or_sockrust-analyzer cargo sudo-rs 0.2.14 cutils/is_fifo_or_sock()., os_string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/os_string_from_ptr()., safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().};
15
16 use superrust-analyzer cargo sudo-rs 0.2.14 system/::interfacerust-analyzer cargo sudo-rs 0.2.14 system/interface/::ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#;
17
18 mod find_ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/find_tty/;
19
20 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) use user_termrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/::UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#;
21
22 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty# {
23 /// The file path of the leader side of the pty.
24 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) pathrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#path.: CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#,
25 /// The leader side of the pty.
26 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) leaderrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#leader.: PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#,
27 /// The follower side of the pty.
28 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) followerrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#follower.: PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#,
29 }
30
31 impl Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty# {
32 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn openrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty]open().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty]> {
33 const PATH_MAXrust-analyzer cargo sudo-rs 0.2.14 system/term/PATH_MAX.: usize = libcrust-analyzer cargo libc 0.2.186 crate/::PATH_MAXrust-analyzer cargo libc 0.2.186 unix/linux_like/PATH_MAX. as _;
34 // Allocate a buffer to hold the path to the pty.
35 let mut path = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0 as c_ucharrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_uchar#; PATH_MAXrust-analyzer cargo sudo-rs 0.2.14 system/term/PATH_MAX.];
36 // Create two integers to hold the file descriptors for each side of the pty.
37 let (mut leader, mut follower) = (0, 0);
38
39 // SAFETY:
40 // - openpty is passed two valid pointers as its first two arguments
41 // - path is a valid array that can hold PATH_MAX characters; and casting `u8` to `i8` is
42 // valid since all values are initialized to zero.
43 // - the last two arguments are allowed to be NULL
44 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe {
45 libcrust-analyzer cargo libc 0.2.186 crate/::openptyrust-analyzer cargo libc 0.2.186 openpty().(
46 &mut leader,
47 &mut follower,
48 path.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().(),
49 null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().::<libcrust-analyzer cargo libc 0.2.186 crate/::termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#>(),
50 null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().::<libcrust-analyzer cargo libc 0.2.186 crate/::winsizerust-analyzer cargo libc 0.2.186 unix/winsize#>(),
51 )
52 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
53
54 // Get the index of the first null byte and truncate `path` so it doesn't have any null
55 // bytes. If there are no null bytes the path is left as it is.
56 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(index) = path
57 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
58 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
59 .find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|(index, &byte)| (byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0).then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(index))
60 {
61 path.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(index);
62 }
63
64 // This will not panic because `path` was truncated to not have any null bytes.
65 let path = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
66
67 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty] {
68 pathrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#path.,
69 leaderrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#leader.: PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
70 // SAFETY: `openpty` has set `leader` to an open fd suitable for assuming ownership by `OwnedFd`.
71 filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file.: unsafe { OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][FromRawFd]from_raw_fd().(leader) }.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
72 },
73 followerrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#follower.: PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower# {
74 // SAFETY: `openpty` has set `follower` to an open fd suitable for assuming ownership by `OwnedFd`.
75 filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file.: unsafe { OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#::from_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][FromRawFd]from_raw_fd().(follower) }.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
76 },
77 })
78 }
79 }
80
81 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
82 filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file.: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#,
83 }
84
85 impl PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
86 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn set_sizerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader]set_size().(&self, term_size: &TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
87 // SAFETY: the TIOCSWINSZ expects an initialized pointer of type `winsize`
88 // https://www.man7.org/linux/man-pages/man2/TIOCSWINSZ.2const.html
89 //
90 // An object of type TermSize is safe to cast to `winsize` since it is a
91 // repr(transparent) "newtype" struct.
92 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe {
93 ioctlrust-analyzer cargo libc 0.2.186 ioctl().(
94 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().(),
95 TIOCSWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCSWINSZ.,
96 (term_size as *const TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().::<libcrust-analyzer cargo libc 0.2.186 crate/::winsizerust-analyzer cargo libc 0.2.186 unix/winsize#>(),
97 )
98 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
99
100 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
101 }
102
103 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn set_nonblockingrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader]set_nonblocking().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
104 let fd = self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().();
105 // SAFETY: these two calls to fcntl are memory safe (and the file descriptor is valid as well)
106 unsafe {
107 let flags = cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(libcrust-analyzer cargo libc 0.2.186 crate/::fcntlrust-analyzer cargo libc 0.2.186 fcntl().(fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), libcrust-analyzer cargo libc 0.2.186 crate/::F_GETFLrust-analyzer cargo libc 0.2.186 unix/linux_like/F_GETFL.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
108
109 // Set the O_NONBLOCK flag
110 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(libcrust-analyzer cargo libc 0.2.186 crate/::fcntlrust-analyzer cargo libc 0.2.186 fcntl().(
111 fd.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(),
112 libcrust-analyzer cargo libc 0.2.186 crate/::F_SETFLrust-analyzer cargo libc 0.2.186 unix/linux_like/F_SETFL.,
113 flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().libcrust-analyzer cargo libc 0.2.186 crate/::O_NONBLOCKrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/O_NONBLOCK.,
114 ))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
115 }
116 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
117 }
118 }
119
120 impl iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
121 fn readrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader][Read]read().(&mut self, buf: &mut [u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
122 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read().(buf)
123 }
124 }
125
126 impl iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
127 fn writerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
128 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Write]write().(buf)
129 }
130
131 fn flushrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
132 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Write]flush().()
133 }
134 }
135
136 impl AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd# for PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {
137 fn as_fdrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyLeader][AsFd]as_fd().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'_> {
138 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()
139 }
140 }
141
142 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower# {
143 filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file.: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#,
144 }
145
146 impl PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower# {
147 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn try_clonerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyFollower]try_clone().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyFollower]> {
148 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file..try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|file| Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyFollower] { filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file. })
149 }
150 }
151
152 impl AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd# for PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower# {
153 fn as_fdrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[PtyFollower][AsFd]as_fd().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'_> {
154 self.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()
155 }
156 }
157
158 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#> for stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio# {
159 fn fromrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[`std::process::Stdio`][`From<PtyFollower>`]from().(follower: PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#) -> Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[`std::process::Stdio`][`From<PtyFollower>`] {
160 follower.filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
161 }
162 }
163
164 mod sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/ {
165 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#;
166
167 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) trait Sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/Sealed# {}
168
169 impl<F: AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#> Sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/Sealed# for F {}
170
171 /// This is known to be a real TTY. No need to use `safe_isatty` before calling any ioctl.
172 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) trait SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty# {}
173
174 impl<T: SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty#> SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty# for &mut T {}
175 impl SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty# for superrust-analyzer cargo sudo-rs 0.2.14 system/term/::UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {}
176 impl SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty# for superrust-analyzer cargo sudo-rs 0.2.14 system/term/::PtyLeaderrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader# {}
177 impl SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty# for superrust-analyzer cargo sudo-rs 0.2.14 system/term/::PtyFollowerrust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower# {}
178 }
179
180 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) trait Terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#: sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/::Sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/Sealed# {
181 fn is_terminal_for_pgrprust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#is_terminal_for_pgrp().(&self, pgrp: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#) -> bool;
182 fn tcgetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#tcgetpgrp().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#>
183 where
184 Self: sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/::SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty#;
185 fn tcsetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#tcsetpgrp().(&self, pgrp: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
186 where
187 Self: sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/::SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty#;
188 fn make_controlling_terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#make_controlling_terminal().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
189 where
190 Self: sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/::SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty#;
191 fn ttynamerust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#ttyname().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>;
192 fn is_pipe_or_socketrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#is_pipe_or_socket().(&self) -> bool;
193 fn tcgetsidrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#tcgetsid().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#>
194 where
195 Self: sealedrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/::SafeTtyrust-analyzer cargo sudo-rs 0.2.14 system/term/sealed/SafeTty#;
196 }
197
198 impl<F: AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#> Terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal# for F {
199 /// Check if the foreground process group ID associated with this terminal is `pgrp`.
200 /// Returns false if this is not actually a terminal.
201 fn is_terminal_for_pgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]is_terminal_for_pgrp().(&self, pgrp: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#) -> bool {
202 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().()) {
203 return false;
204 }
205
206 // SAFETY: tcgetpgrp cannot cause UB
207 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(id) = cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::tcgetpgrprust-analyzer cargo libc 0.2.186 tcgetpgrp().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().()) }) else {
208 return false;
209 };
210 ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(id) rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId][`PartialEq<Self>`]eq().pgrp
211 }
212 /// Get the foreground process group ID associated with this terminal.
213 fn tcgetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcgetpgrp().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#> {
214 // SAFETY: tcgetpgrp cannot cause UB
215 let id = cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::tcgetpgrprust-analyzer cargo libc 0.2.186 tcgetpgrp().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
216 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(id))
217 }
218 /// Set the foreground process group ID associated with this terminal to `pgrp`.
219 fn tcsetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcsetpgrp().(&self, pgrp: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
220 // SAFETY: tcsetpgrp cannot cause UB
221 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::tcsetpgrprust-analyzer cargo libc 0.2.186 tcsetpgrp().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), pgrp.innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().()) }).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| ())
222 }
223
224 /// Make the given terminal the controlling terminal of the calling process.
225 fn make_controlling_terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]make_controlling_terminal().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
226 // SAFETY: this is a correct way to call the TIOCSCTTY ioctl, see:
227 // https://www.man7.org/linux/man-pages/man2/TIOCNOTTY.2const.html
228 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::ioctlrust-analyzer cargo libc 0.2.186 ioctl().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), libcrust-analyzer cargo libc 0.2.186 crate/::TIOCSCTTYrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCSCTTY., 0) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
229 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
230 }
231
232 /// Get the filename of the tty
233 fn ttynamerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]ttyname().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#> {
234 let mut buf: [c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#; 1024] = [0; 1024];
235
236 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().()) {
237 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Unsupportedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Unsupported#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
238 }
239
240 // SAFETY: `buf` is a valid and initialized pointer, and its correct length is passed
241 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::ttyname_rrust-analyzer cargo libc 0.2.186 ttyname_r().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().(), buf.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().(), buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
242 // SAFETY: `buf` will have been initialized by the `ttyname_r` call, if it succeeded
243 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { os_string_from_ptrrust-analyzer cargo sudo-rs 0.2.14 cutils/os_string_from_ptr().(buf.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()) })
244 }
245
246 fn is_pipe_or_socketrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]is_pipe_or_socket().(&self) -> bool {
247 is_fifo_or_sockrust-analyzer cargo sudo-rs 0.2.14 cutils/is_fifo_or_sock().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().())
248 }
249
250 fn tcgetsidrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcgetsid().(&self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#> {
251 // SAFETY: tcgetsid cannot cause UB
252 let id = cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { libcrust-analyzer cargo libc 0.2.186 crate/::tcgetsidrust-analyzer cargo libc 0.2.186 tcgetsid().(self.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#as_fd().().as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`][AsRawFd]as_raw_fd().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
253 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(id))
254 }
255 }
256
257 /// Try to get the path of the current TTY
258 pub fn current_tty_namerust-analyzer cargo sudo-rs 0.2.14 system/term/current_tty_name().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#> {
259 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tty) = find_ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/find_tty/::ttyname_from_devrust-analyzer cargo sudo-rs 0.2.14 system/term/find_tty/ttyname_from_dev().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
260 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tty);
261 }
262
263 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().()
264 .ttynamerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]ttyname().()
265 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]or_else().(|_| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().ttynamerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]ttyname().())
266 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]or_else().(|_| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stderr().().ttynamerust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]ttyname().())
267 }
268
269 #[repr(transparent)]
270 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) struct TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize# {
271 rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw.: winsizerust-analyzer cargo libc 0.2.186 unix/winsize#,
272 }
273
274 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize# {
275 fn eqrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[TermSize][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[TermSize][`PartialEq<Self>`]) -> bool {
276 self.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_colrust-analyzer cargo libc 0.2.186 unix/winsize#ws_col. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().other.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_colrust-analyzer cargo libc 0.2.186 unix/winsize#ws_col. && self.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_rowrust-analyzer cargo libc 0.2.186 unix/winsize#ws_row. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().other.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_rowrust-analyzer cargo libc 0.2.186 unix/winsize#ws_row.
277 }
278 }
279
280 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize# {
281 fn fmtrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[TermSize][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
282 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{} x {}", self.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_rowrust-analyzer cargo libc 0.2.186 unix/winsize#ws_row., self.rawrust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#raw..ws_colrust-analyzer cargo libc 0.2.186 unix/winsize#ws_col.)
283 }
284 }
285
286 #[allow(clippy::undocumented_unsafe_blocks)]
287 #[cfg(test)]
288 mod testsrust-analyzer cargo sudo-rs 0.2.14 system/term/tests/ {
289 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
290 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#,
291 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#},
292 osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::{netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/::UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#, preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/prelude/::OsStringExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/OsStringExt#},
293 pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
294 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().,
295 };
296
297 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::{fork_for_testrust-analyzer cargo sudo-rs 0.2.14 system/fork_for_test()., getpgidrust-analyzer cargo sudo-rs 0.2.14 system/getpgid()., setsidrust-analyzer cargo sudo-rs 0.2.14 system/setsid()., termrust-analyzer cargo sudo-rs 0.2.14 system/term/::*};
298
299 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
300 fn open_ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/tests/open_pty().() {
301 let pty = Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#::openrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty]open().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
302 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(pty.leaderrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#leader..filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyLeader#file..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()));
303 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(safe_isattyrust-analyzer cargo sudo-rs 0.2.14 cutils/safe_isatty().(pty.followerrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#follower..filerust-analyzer cargo sudo-rs 0.2.14 system/term/PtyFollower#file..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()));
304
305 let path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<OsString>`]from().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::from_vecrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsString][OsStringExt]from_vec().(pty.pathrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#path..into_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]into_bytes().()));
306 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.try_existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]try_exists().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
307 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(path.starts_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]starts_with().("/dev/pts/"));
308 }
309
•310 //#[test]
311 fn tcsetpgrp_and_tcgetpgrp_are_consistentrust-analyzer cargo sudo-rs 0.2.14 system/term/tests/tcsetpgrp_and_tcgetpgrp_are_consistent().() {
312 // Create a socket so the child can send us a byte if successful.
313 let (mut rx, mut tx) = UnixStreamrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/UnixStream#::pairrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/net/stream/impl#[UnixStream]pair().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
314
315 unsafe {
316 fork_for_testrust-analyzer cargo sudo-rs 0.2.14 system/fork_for_test().(|| {
317 // Open a new pseudoterminal.
318 let leader = Ptyrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#::openrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[Pty]open().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().leaderrust-analyzer cargo sudo-rs 0.2.14 system/term/Pty#leader.;
319 // On FreeBSD this returns an unspecified PID when there is no foreground process
320 // group, so skip this check on FreeBSD.
321 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(not(target_os = "freebsd")) {
322 // The pty leader should not have a foreground process group yet.
323 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(leader.tcgetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcgetpgrp().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().(), 0);
324 }
325 // Create a new session so we can change the controlling terminal.
326 setsidrust-analyzer cargo sudo-rs 0.2.14 system/setsid().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
327 // Set the pty leader as the controlling terminal.
328 leader.make_controlling_terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]make_controlling_terminal().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
329 // Set us as the foreground process group of the pty leader.
330 let pgid = getpgidrust-analyzer cargo sudo-rs 0.2.14 system/getpgid().(ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(0)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
331 leader.tcsetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcsetpgrp().(pgid).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
332 // Check that we are in fact the foreground process group of the pty leader.
333 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pgid, leader.tcgetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcgetpgrp().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
334 // If we haven't panicked yet, send a byte to the parent.
335 tx.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[42]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
336
337 exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(0);
338 })
339 };
340
341 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(tx);
342
343 // Read one byte from the children to confirm that it did not panic.
344 let mut buf = [0];
345 rx.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
346 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 42);
347 }
348 }