On 01/07/14 21:17, Jurjen Oskam wrote:
Philip Guenther <guenther <at> gmail.com> writes:
On Tue, Jan 7, 2014 at 8:23 AM, Theo de Raadt <deraadt <at>
cvs.openbsd.org> wrote:
What you need to instead is wrap all this in a way which keeps the
tty open
(
stty 9600 sane parenb -parodd crtscts cs7 igncr
do your IO loop
) </dev/ttyU0 0>&1 0>&2
Something like that.
I think the desired redirections on the subshell-close would make that
last line:
) <>/dev/ttyU0 >&0
("open /dev/ttyU0 read-write as stdin, and then dup that to stdout")
Thank you for the responses. I sort of figured out that the stty settings
are set to default each time the device is opened, but now that's confirmed
I ran into the problem that open() does not seem to be returning.
I created the following simple shell script:
#!/bin/sh
( stty 9600 sane parenb -parodd crtscts cs7 igncr
while read line
do
echo $line
done
) <>/dev/ttyU0 >&0
Running it results in no output at all, without the prompt coming back.
No surprise, really, as you redireced the printed lines back into the
tty... :-)
Either print it to stderr (echo $line >&2), or I simply suspect you
don't want the '>&0' part.
/Alexander
Interrupting the process results in the following ktrace snippet:
486 sh 1389125130.342774 CALL
open(0x208ee2c50,0x202<O_RDWR|O_CREAT>,0x1b6<S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
|S_IROTH|S_IWOTH>)
486 sh 1389125130.342776 NAMI "/dev/ttyU0"
486 sh 1389125151.417307 PSIG SIGINT caught handler=0x4214f0
mask=0<>
486 sh 1389125151.417312 RET open -1 errno 4 Interrupted system
call
Looking at the timestamps, the open() only returns when I Ctrl-C the process.
The same happens with the following trivial Perl script:
#!/usr/bin/perl -w
$|=1;
open(METER,"/dev/ttyU0") or die;
print "opened terminal\n";
close(METER);
Running it produces no output without the prompt coming back, at least not
until I Ctrl-C the Perl script:
15860 perl 1389125426.222462 CALL open(0x12f6694a1d70,0<O_RDONLY>)
15860 perl 1389125426.222465 NAMI "/dev/ttyU0"
15860 perl 1389125451.261414 PSIG SIGINT SIG_DFL
Again, open() doesn't seem to return.
Am I doing something wrong here?
Regards,
Jurjen Oskam