public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Linda Walsh <cygwin@tlinx.org>
To: cygwin@cygwin.com
Subject: Re: Bash uses lseek while reading from serial device
Date: Sun, 17 Aug 2014 22:19:00 -0000	[thread overview]
Message-ID: <53F12A72.2090805@tlinx.org> (raw)
In-Reply-To: <20140816184739.3078D27C7E@mail.csclub.uwaterloo.ca>

Being a bit of a busybody...

I forwarded this to the bash list and chet responded there...

so forwarding it back here... not sure what isatty is supposed to do
with a serial line, let alone one on windows...



-------- Original Message --------
Subject: Re: Fwd: Bash uses lseek while reading from serial device
Date: Sun, 17 Aug 2014 18:12:23 -0400
From: Chet Ramey
Organization: ITS, Case Western Reserve University
To: Linda Walsh,   bug-bash
CC: chet.ramey
References: <53F041FD.3050509@tlinx.org>

On 8/17/14, 1:47 AM, Linda Walsh wrote:
>  ??  Could this be a cygwin bug?  It's hard to see why cygwin
>  would start using lseek calls when running bash unless bash called
>  them... but then tha's not to say something else entirely may be going 
on as
>  this is running on Windows... ;-/

The original poster's speculation is correct.  Bash is not allowed to
read more input from stdin than it actually consumes, so commands that
it runs get the intended input.  To that end, it tries to detect whether
or not the fd it is using for standard input is seekable: if it is, bash
assumes that it can correctly position the file pointer by seeking
backwards; if it is not, bash reads a character at a time.

Bash uses lseek to the current file position to check this.  If the lseek
returns -1/EPIPE, bash assumes the fd is not seekable.  If it returns 0,
bash assumes that it can move around freely.  Since bash is trying to seek
backwards in the file, stdin is either a regular file or a tty (in which
case bash assumes that reads are newline-delimited by the device driver).

I suspect what happens is that isatty() returns 1 for serial devices, but
reads are not newline-delimited.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
         ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2014-08-17 22:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-16 18:47 Ross Ridge
2014-08-17 22:19 ` Linda Walsh [this message]
2014-08-18 11:21   ` Corinna Vinschen
2014-08-19  2:40 Ross Ridge
2014-08-19  8:35 ` Corinna Vinschen

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=53F12A72.2090805@tlinx.org \
    --to=cygwin@tlinx.org \
    --cc=cygwin@cygwin.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).