Debian Codegraph @

src/system/term/user_term.rs

raw symbols SCIP
1 //! This module is a port of ogsudo's `lib/util/term.c` with some minor changes to make it
2 //! rust-like.
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
5 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#},
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#, OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#},
7 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-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#},
8 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#,
9 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#, BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#},
10 syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::{AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#},
11 };
12
13 use libcrust-analyzer cargo libc 0.2.186 crate/::{
14 CS7rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/CS7., CS8rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/CS8., ECHOrust-analyzer cargo libc 0.2.186 unix/linux_like/ECHO., ECHOCTLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOCTL., ECHOErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOE., ECHOKrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOK., ECHOKErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOKE., ECHONLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHONL., ICANONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ICANON., ICRNLrust-analyzer cargo libc 0.2.186 unix/linux_like/ICRNL., IEXTENrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IEXTEN., IGNCRrust-analyzer cargo libc 0.2.186 unix/linux_like/IGNCR., IGNPARrust-analyzer cargo libc 0.2.186 unix/linux_like/IGNPAR.,
15 IMAXBELrust-analyzer cargo libc 0.2.186 unix/linux_like/IMAXBEL., INLCRrust-analyzer cargo libc 0.2.186 unix/linux_like/INLCR., INPCKrust-analyzer cargo libc 0.2.186 unix/linux_like/INPCK., ISIGrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ISIG., ISTRIPrust-analyzer cargo libc 0.2.186 unix/linux_like/ISTRIP., IXANYrust-analyzer cargo libc 0.2.186 unix/linux_like/IXANY., IXOFFrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IXOFF., IXONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IXON., NOFLSHrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/NOFLSH., OCRNLrust-analyzer cargo libc 0.2.186 unix/linux_like/OCRNL., ONLCRrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ONLCR., ONLRETrust-analyzer cargo libc 0.2.186 unix/linux_like/ONLRET., ONOCRrust-analyzer cargo libc 0.2.186 unix/linux_like/ONOCR.,
16 OPOSTrust-analyzer cargo libc 0.2.186 unix/linux_like/OPOST., PARENBrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PARENB., PARMRKrust-analyzer cargo libc 0.2.186 unix/linux_like/PARMRK., PARODDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PARODD., PENDINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PENDIN., SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU., TCSADRAINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSADRAIN., TCSAFLUSHrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSAFLUSH., TIOCGWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCGWINSZ., TIOCSWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCSWINSZ.,
17 TOSTOPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TOSTOP., cfgetispeedrust-analyzer cargo libc 0.2.186 cfgetispeed()., cfgetospeedrust-analyzer cargo libc 0.2.186 cfgetospeed()., cfmakerawrust-analyzer cargo libc 0.2.186 cfmakeraw()., cfsetispeedrust-analyzer cargo libc 0.2.186 cfsetispeed()., cfsetospeedrust-analyzer cargo libc 0.2.186 cfsetospeed()., ioctlrust-analyzer cargo libc 0.2.186 ioctl()., sigactionrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction#,
18 sigemptysetrust-analyzer cargo libc 0.2.186 sigemptyset()., sighandler_trust-analyzer cargo libc 0.2.186 unix/sighandler_t#, siginfo_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#, sigset_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/sigset_t#, tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t#, tcgetattrrust-analyzer cargo libc 0.2.186 tcgetattr()., tcsetattrrust-analyzer cargo libc 0.2.186 tcsetattr()., termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#,
19 winsizerust-analyzer cargo libc 0.2.186 unix/winsize#,
20 };
21 #[cfg(target_os = "linux")]
22 use libcrust-analyzer cargo libc 0.2.186 crate/::{IUTF8rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/IUTF8., OLCUCrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/OLCUC.};
23
24 #[cfg(not(target_os = "linux"))]
25 const IUTF8: libcrust-analyzer cargo libc 0.2.186 crate/::tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = 0;
26 #[cfg(not(target_os = "linux"))]
27 const OLCUC: libcrust-analyzer cargo libc 0.2.186 crate/::tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = 0;
28
29 use superrust-analyzer cargo sudo-rs 0.2.14 system/term/::{TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#, Terminalrust-analyzer cargo sudo-rs 0.2.14 system/term/Terminal#};
30 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::{
31 cutilsrust-analyzer cargo sudo-rs 0.2.14 cutils/::cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().,
32 systemrust-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#, make_zeroed_sigactionrust-analyzer cargo sudo-rs 0.2.14 system/make_zeroed_sigaction().},
33 };
34
35 const INPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/INPUT_FLAGS.: tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = IGNPARrust-analyzer cargo libc 0.2.186 unix/linux_like/IGNPAR.
36 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().PARMRKrust-analyzer cargo libc 0.2.186 unix/linux_like/PARMRK.
37 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().INPCKrust-analyzer cargo libc 0.2.186 unix/linux_like/INPCK.
38 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ISTRIPrust-analyzer cargo libc 0.2.186 unix/linux_like/ISTRIP.
39 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().INLCRrust-analyzer cargo libc 0.2.186 unix/linux_like/INLCR.
40 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IGNCRrust-analyzer cargo libc 0.2.186 unix/linux_like/IGNCR.
41 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ICRNLrust-analyzer cargo libc 0.2.186 unix/linux_like/ICRNL.
42 // | IUCLC /* FIXME: not in libc */rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().
43 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IXONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IXON.
44 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IXANYrust-analyzer cargo libc 0.2.186 unix/linux_like/IXANY.
45 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IXOFFrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IXOFF.
46 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IMAXBELrust-analyzer cargo libc 0.2.186 unix/linux_like/IMAXBEL.
47 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IUTF8rust-analyzer cargo libc 0.2.186 unix/linux_like/linux_l4re_shared/IUTF8.;
48 const OUTPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/OUTPUT_FLAGS.: tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = OPOSTrust-analyzer cargo libc 0.2.186 unix/linux_like/OPOST. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().OLCUCrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/OLCUC. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ONLCRrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ONLCR. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().OCRNLrust-analyzer cargo libc 0.2.186 unix/linux_like/OCRNL. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ONOCRrust-analyzer cargo libc 0.2.186 unix/linux_like/ONOCR. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ONLRETrust-analyzer cargo libc 0.2.186 unix/linux_like/ONLRET.;
49 const CONTROL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/CONTROL_FLAGS.: tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = CS7rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/CS7. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().CS8rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/CS8. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().PARENBrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PARENB. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().PARODDrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PARODD.;
50 const LOCAL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/LOCAL_FLAGS.: tcflag_trust-analyzer cargo libc 0.2.186 unix/linux_like/tcflag_t# = ISIGrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ISIG.
51 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ICANONrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ICANON.
52 // | XCASE /* FIXME: not in libc */rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().
53 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHOrust-analyzer cargo libc 0.2.186 unix/linux_like/ECHO.
54 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHOErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOE.
55 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHOKrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOK.
56 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHONLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHONL.
57 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().NOFLSHrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/NOFLSH.
58 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().TOSTOPrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TOSTOP.
59 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().IEXTENrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/IEXTEN.
60 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHOCTLrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOCTL.
61 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().ECHOKErust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ECHOKE.
62 |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().PENDINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/PENDIN.;
63
64 static GOT_SIGTTOUrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/GOT_SIGTTOU.: AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool# = AtomicBoolrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicBool#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]new().(false);
65
66 /// This is like `tcsetattr` but it only succeeds if we are in the foreground process group.
67 /// # Safety
68 ///
69 /// The arguments to this function have to be valid arguments to `tcsetattr`.
70 unsafe fn tcsetattr_nobgrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/tcsetattr_nobg().(fd: c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, flags: c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, tp: *const termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#) -> 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#<()> {
71 // This function is based around the fact that we receive `SIGTTOU` if we call `tcsetattr` and
72 // we are not in the foreground process group.
73
74 // SAFETY: is the responsibility of the caller of `tcsetattr_nobg`
75 let setattr = || cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { tcsetattrrust-analyzer cargo libc 0.2.186 tcsetattr().(fd, flags, tp) }).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| ());
76
77 catching_sigttourust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/catching_sigttou().(setattr)
78 }
79
80 fn catching_sigttourust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/catching_sigttou().(mut function: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#() -> 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#<()>) -> 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#<()> {
81 extern "C" fn on_sigttourust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/on_sigttou().(_signal: c_intrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_int#, _info: *mut siginfo_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#, _: *mut c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#) {
82 GOT_SIGTTOUrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/GOT_SIGTTOU..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]store().(true, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#);
83 }
84
85 let action = {
86 let mut raw: libcrust-analyzer cargo libc 0.2.186 crate/::sigactionrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction# = make_zeroed_sigactionrust-analyzer cargo sudo-rs 0.2.14 system/make_zeroed_sigaction().();
87 // Call `on_sigttou` if `SIGTTOU` arrives.
88 raw.sa_sigactionrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction#sa_sigaction. = on_sigttourust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/on_sigttou(). as *const () as sighandler_trust-analyzer cargo libc 0.2.186 unix/sighandler_t#;
89 // Exclude any other signals from the set
90 raw.sa_maskrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction#sa_mask. = {
91 let mut sa_mask = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<sigset_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/sigset_t#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
92 // SAFETY: sa_mask is a valid and dereferenceble pointer; it will
93 // become initialized by `sigemptyset`
94 unsafe {
95 sigemptysetrust-analyzer cargo libc 0.2.186 sigemptyset().(sa_mask.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().());
96 sa_mask.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().()
97 }
98 };
99 raw.sa_flagsrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction#sa_flags. = 0;
100 raw
101 };
102 // Reset `GOT_SIGTTOU`.
103 GOT_SIGTTOUrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/GOT_SIGTTOU..storerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]store().(false, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#);
104
105 // Set `action` as the action for `SIGTTOU` and store the original action in `original_action`
106 // to restore it later.
107 //
108 // SAFETY: `original_action` is a valid pointer; second, the `action` installed (on_sigttou):
109 // - is itself a safe function
110 // - only updates an atomic variable, so cannot violate memory unsafety that way
111 // - doesn't call any async-unsafe functions (refer to signal-safety(7))
112 // Therefore it can safely be installed as a signal handler.
113 // Furthermore, `sigaction` will initialize `original_action`.
114 let original_action = unsafe {
115 let mut original_action = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<sigactionrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/sigaction#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
116 sigactionrust-analyzer cargo libc 0.2.186 sigaction().(SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU., &action, original_action.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().());
117 original_action.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().()
118 };
119
120 // Call `tcsetattr` until it suceeds and ignore interruptions if we did not receive `SIGTTOU`.
121 let result = loop {
122 match function() {
123 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => break Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
124 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
125 let got_sigttou = GOT_SIGTTOUrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/GOT_SIGTTOU..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicBool]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#);
126 if got_sigttou || err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().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#::Interruptedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Interrupted# {
127 break Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err);
128 }
129 }
130 }
131 };
132
133 // Restore the original action.
134 //
135 // SAFETY: `original_action` is a valid pointer, and was initialized by the preceding
136 // call to `sigaction` (and not subsequently altered, since it is not mut). The third parameter
137 // is allowed to be NULL (this means we ignore the previously-installed handler)
138 unsafe { sigactionrust-analyzer cargo libc 0.2.186 sigaction().(SIGTTOUrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/SIGTTOU., &original_action, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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().()) };
139
140 result
141 }
142
143 /// Type to manipulate the settings of the user's terminal.
144 pub struct UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {
145 ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty.: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#,
146 original_termiosrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#original_termios.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#>,
147 }
148
149 impl UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {
150 /// Open the user's terminal.
151 pub fn openrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]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/user_term/impl#[UserTerm]> {
152 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/user_term/impl#[UserTerm] {
153 ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty.: OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().().readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true).writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().("/dev/tty")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
154 original_termiosrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#original_termios.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
155 })
156 }
157
158 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn get_sizerust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]get_size().(&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#<TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#> {
159 let mut term_size = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<TermSizerust-analyzer cargo sudo-rs 0.2.14 system/term/TermSize#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
160
161 // SAFETY: This passes a valid file descriptor and valid pointer (of
162 // the correct type) to the TIOCGWINSZ ioctl; see:
163 // https://man7.org/linux/man-pages/man2/TIOCGWINSZ.2const.html
164 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe {
165 ioctlrust-analyzer cargo libc 0.2.186 ioctl().(
166 self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().(),
167 TIOCGWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCGWINSZ.,
168 term_size.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<winsizerust-analyzer cargo libc 0.2.186 unix/winsize#>(),
169 )
170 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
171
172 // SAFETY: if we arrived at this point, `term_size` was initialized.
173 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { term_size.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().() })
174 }
175
176 /// Copy the settings of the user's terminal to the `dst` terminal.
177 pub fn copy_torust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]copy_to().<D: AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#>(&self, dst: &D) -> 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#<()> {
178 let src = self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().();
179 let dst = dst.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().();
180
181 // SAFETY: tt_src and tt_dst will be initialized by `tcgetattr`.
182 let (tt_src, mut tt_dst) = unsafe {
183 let mut tt_src = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
184 let mut tt_dst = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<termiosrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
185
186 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(tcgetattrrust-analyzer cargo libc 0.2.186 tcgetattr().(src, tt_src.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
187 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(tcgetattrrust-analyzer cargo libc 0.2.186 tcgetattr().(dst, tt_dst.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
188
189 (tt_src.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().(), tt_dst.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().())
190 };
191
192 // Clear select input, output, control and local flags.
193 tt_dst.c_iflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_iflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().INPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/INPUT_FLAGS.;
194 tt_dst.c_oflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_oflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().OUTPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/OUTPUT_FLAGS.;
195 tt_dst.c_cflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().CONTROL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/CONTROL_FLAGS.;
196 tt_dst.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAndAssign<Self>`]bitand_assign().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][Not]not().LOCAL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/LOCAL_FLAGS.;
197
198 // Copy select input, output, control and local flags.
199 tt_dst.c_iflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_iflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().tt_src.c_iflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_iflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().INPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/INPUT_FLAGS.;
200 tt_dst.c_oflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_oflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().tt_src.c_oflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_oflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().OUTPUT_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/OUTPUT_FLAGS.;
201 tt_dst.c_cflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().tt_src.c_cflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().CONTROL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/CONTROL_FLAGS.;
202 tt_dst.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().tt_src.c_lflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_lflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().LOCAL_FLAGSrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/LOCAL_FLAGS.;
203
204 // Copy special chars from src verbatim.
205 tt_dst.c_ccrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cc..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&tt_src.c_ccrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cc.);
206
207 // Copy speed from `src`.
208 //
209 // SAFETY: the cfXXXXspeed calls are passed valid pointers and
210 // cannot cause UB even if the speed would be incorrect.
211 unsafe {
212 let mut speed = cfgetospeedrust-analyzer cargo libc 0.2.186 cfgetospeed().(&tt_src);
213 // Zero output speed closes the connection.
214 if speed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().libcrust-analyzer cargo libc 0.2.186 crate/::B0rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/B0. {
215 speed = libcrust-analyzer cargo libc 0.2.186 crate/::B38400rust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/B38400.;
216 }
217 cfsetospeedrust-analyzer cargo libc 0.2.186 cfsetospeed().(&mut tt_dst, speed);
218
219 speed = cfgetispeedrust-analyzer cargo libc 0.2.186 cfgetispeed().(&tt_src);
220 cfsetispeedrust-analyzer cargo libc 0.2.186 cfsetispeed().(&mut tt_dst, speed);
221 }
222
223 // SAFETY: dst is a valid file descriptor and `tt_dst` is an
224 // initialized struct obtained through tcgetattr; so this is safe to
225 // pass to `tcsetattr`.
226 unsafe { tcsetattr_nobgrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/tcsetattr_nobg().(dst, TCSAFLUSHrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSAFLUSH., &tt_dst) }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
227
228 let mut wsize = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<winsizerust-analyzer cargo libc 0.2.186 unix/winsize#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
229 // SAFETY: TIOCGWINSZ ioctl expects one argument of type *mut winsize
230 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { ioctlrust-analyzer cargo libc 0.2.186 ioctl().(src, TIOCGWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCGWINSZ., wsize.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
231 // SAFETY: wsize has been initialized by the TIOCGWINSZ ioctl
232 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(unsafe { ioctlrust-analyzer cargo libc 0.2.186 ioctl().(dst, TIOCSWINSZrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/arch/generic/TIOCSWINSZ., wsize.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_ptr().()) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
233
234 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
235 }
236
237 /// Set the user's terminal to raw mode. Enable terminal signals if `with_signals` is set to
238 /// `true`.
239 pub fn set_raw_moderust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]set_raw_mode().(&mut self, with_signals: bool, preserve_oflag: bool) -> 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#<()> {
240 let fd = self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().();
241
242 // Retrieve the original terminal (if we haven't done so already)
243 let mut term = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(termios) = self.original_termiosrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#original_termios. {
244 termios
245 } else {
246 // SAFETY: `termios` is a valid pointer to pass to tcgetattr; if that calls succeeds,
247 // it will have initialized the `termios` structure
248 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.original_termiosrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#original_termios..insertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]insert().(unsafe {
249 let mut termios = MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
250 cerrrust-analyzer cargo sudo-rs 0.2.14 cutils/cerr().(tcgetattrrust-analyzer cargo libc 0.2.186 tcgetattr().(fd, termios.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
251 termios.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().()
252 })
253 };
254
255 // Set terminal to raw mode.
256 let oflag = term.c_oflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_oflag.;
257 // SAFETY: `term` is a valid, initialized struct of type `termios`, which
258 // was previously obtained through `tcgetattr`.
259 unsafe { cfmakerawrust-analyzer cargo libc 0.2.186 cfmakeraw().(&mut term) };
260 if preserve_oflag {
261 term.c_oflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_oflag. = oflag;
262 }
263 // Enable terminal signals.
264 if with_signals {
265 term.c_cflagrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/termios#c_cflag. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOrAssign<Self>`]bitor_assign().ISIGrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/ISIG.;
266 }
267
268 // SAFETY: `fd` is a valid file descriptor for the tty; for `term`: same as above.
269 unsafe { tcsetattr_nobgrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/tcsetattr_nobg().(fd, TCSADRAINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSADRAIN., &term) }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
270
271 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
272 }
273
274 /// Restore the saved terminal settings if we are in the foreground process group.
275 ///
276 /// This change is done after waiting for all the queued output to be written. To discard the
277 /// queued input `flush` must be set to `true`.
278 pub fn restorerust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]restore().(&mut self, flush: bool) -> 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#<()> {
279 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(termios) = self.original_termiosrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#original_termios..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
280 let fd = self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().();
281 let flags = if flush { TCSAFLUSHrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSAFLUSH. } else { TCSADRAINrust-analyzer cargo libc 0.2.186 unix/linux_like/linux/gnu/b64/x86_64/TCSADRAIN. };
282 // SAFETY: `fd` is a valid file descriptor for the tty; and `termios` is a valid pointer
283 // that was obtained through `tcgetattr`.
284 unsafe { tcsetattr_nobgrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/tcsetattr_nobg().(fd, flags, &termios) }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
285 }
286
287 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
288 }
289
290 /// This is like `tcsetpgrp` but it only suceeds if we are in the foreground process group.
291 pub fn tcsetpgrp_nobgrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm]tcsetpgrp_nobg().(&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#<()> {
292 // This function is based around the fact that we receive `SIGTTOU` if we call `tcsetpgrp` and
293 // we are not in the foreground process group.
294
295 catching_sigttourust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/catching_sigttou().(|| self.tcsetpgrprust-analyzer cargo sudo-rs 0.2.14 system/term/impl#[F][Terminal]tcsetpgrp().(pgrp))
296 }
297 }
298
299 impl AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd# for UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {
300 fn as_fdrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm][AsFd]as_fd().(&self) -> BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#<'_> {
301 self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().()
302 }
303 }
304
305 impl Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {
306 fn readrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm][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> {
307 self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read().(buf)
308 }
309 }
310
311 impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for UserTermrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm# {
312 fn writerust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm][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> {
313 self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Write]write().(buf)
314 }
315
316 fn flushrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/impl#[UserTerm][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#<()> {
317 self.ttyrust-analyzer cargo sudo-rs 0.2.14 system/term/user_term/UserTerm#tty..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Write]flush().()
318 }
319 }