From: Chet Murthy <murthy.chet@gmail.com>
To: Matthew Ryan <matthew@o1labs.org>
Cc: Helmut Brandl <helmut.brandl@gmx.net>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Turn echoing off on standard input to read e.g. passwords
Date: Fri, 29 Mar 2019 16:13:17 -0700 [thread overview]
Message-ID: <CA++P_gdWC8q4s5sHBGhi-Bh36EPyuYRYE4Od5e9ow1Wh1ms0gw@mail.gmail.com> (raw)
In-Reply-To: <CA++P_gcEW+_69-17sajueteW3eMwOxLmhY-+ztH-uUZ+E07XhA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]
A little Googling turns up that the author of the Unix library (Xavier,
IIRC) provided support for termios(3). So you can already do what you want
in Ocaml with no extra C ugly bits.
Here's a little ocaml program to demonstrate, and after it, some strace
output showing the way it calls ioctl(2) to manipulate the line discipline
(relevant bits bolded in HTML format mail).
let main () =
let open Unix in
let tios = tcgetattr stdin in
Printf.printf "c_echo: %b\n" tios.c_echo ;
Printf.printf "c_echoe: %b\n" tios.c_echoe ;
Printf.printf "c_echok: %b\n" tios.c_echok ;
Printf.printf "c_echonl: %b\n" tios.c_echonl ;
flush Pervasives.stdout ;
tios.c_echo <- false ;
tcsetattr stdin TCSANOW tios ;
let tios = tcgetattr stdin in
Printf.printf "AFTER c_echo: %b\nSleeping 10 sec ....\n" tios.c_echo ;
flush Pervasives.stdout ;
Unix.sleep 10;
tios.c_echo <- true ;
tcsetattr stdin TCSANOW tios ;
()
;;
main() ;;
=====================
$ strace -eioctl ./noecho
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
c_echo: true
c_echoe: true
c_echok: true
c_echonl: false
ioctl(0, TCGETS, {B38400 opost isig icanon *echo* ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon *echo* ...}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon *-echo *...})
= 0
ioctl(0, TCGETS, {B38400 opost isig icanon *-echo *...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon *-echo* ...}) = 0
AFTER c_echo: false
Sleeping 10 sec ....
ioctl(0, TCGETS, {B38400 opost isig icanon *-echo* ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon *-echo* ...}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon *echo* ...})
= 0
ioctl(0, TCGETS, {B38400 opost isig icanon *echo* ...}) = 0
+++ exited with 0 +++
[-- Attachment #2: Type: text/html, Size: 2436 bytes --]
next prev parent reply other threads:[~2019-03-29 23:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-28 20:03 Helmut Brandl
2019-03-28 20:33 ` Matthew Ryan
2019-03-28 20:40 ` Helmut Brandl
2019-03-28 21:12 ` Daniel Bünzli
2019-03-29 3:05 ` Chet Murthy
2019-03-29 23:13 ` Chet Murthy [this message]
2019-04-01 9:05 ` Jeremie Dimino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA++P_gdWC8q4s5sHBGhi-Bh36EPyuYRYE4Od5e9ow1Wh1ms0gw@mail.gmail.com \
--to=murthy.chet@gmail.com \
--cc=caml-list@inria.fr \
--cc=helmut.brandl@gmx.net \
--cc=matthew@o1labs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox