All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Ben Walton <bwalton@artsci.utoronto.ca>
Cc: Junio C Hamano <gitster@pobox.com>, git <git@vger.kernel.org>,
	Tay Ray Chuan <rctay89@gmail.com>
Subject: Re: [PATCH] Avoid crippled getpass function on Solaris
Date: Mon, 6 Aug 2012 18:31:13 -0400	[thread overview]
Message-ID: <20120806223113.GA16298@sigill.intra.peff.net> (raw)
In-Reply-To: <1344290892-sup-1108@pinkfloyd.chass.utoronto.ca>

On Mon, Aug 06, 2012 at 06:09:08PM -0400, Ben Walton wrote:

> > I'm currently in pkgutil hell trying to remember how to get a working
> > gcc on Solaris. Bleh. What kind of OS doesn't ship with a compiler by
> > default? :)
> 
> One that's losing mindshare and isn't gaining traction? *g*  Feel free
> to message me offline if you need a hand with that.

Thanks, I figured it out (I installed opencsw's gcc, but I had no
standard include files. Turns out that I needed the system/header
package from upstream).

The stdio behavior on Solaris is weird. If I run this sample program:

  #include <stdio.h>
  int main(void)
  {
    FILE *fh = fopen("/dev/tty", "w+");
    char buf[32] = {0};
    fgets(buf, sizeof(buf), fh);
    fprintf(fh, "got %s\n", buf);
    return 0;
  }

on Linux, I get:

  $ ./a.out
  foo        <-- me typing
  got foo    <-- program output

On Solaris, I get:

  $ ./a.out
  foo        <-- me typing
  foo        <-- ???
  got foo    <-- program output

If you step it through the debugger, the mystery output comes as part of
the fprintf, as if it is in the buffer waiting to be flushed. And
indeed, if you dump the FILE handle via gdb, there is only a single
buffer, and it contains "foo\n". Whereas with glibc, there are separate
read/write buffers.

I suspect the single buffer is enough to handle normal files, but not
bidirectional pipes where the input and output content are unrelated. I
don't think Solaris is _buggy_ per se, as we have probably stepped
outside the realm of what the standard promises, but it's certainly a
quality-of-implementation issue.

So I think it could be solved by opening /dev/tty twice (or fdopen()ing
the same descriptor twice). Or by just doing away with stdio entirely.

Looking over the code, I recall now why I used stdio: strbuf_getline
requires it. These days we have strbuf_getwholeline_fd. It's slightly
less efficient (it has to read() a character at a time), but since we
are talking about a few characters of keyboard input, it should be OK.

-Peff

  reply	other threads:[~2012-08-06 22:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-05 23:17 [PATCH] Avoid crippled getpass function on Solaris Ben Walton
2012-08-06  1:56 ` Tay Ray Chuan
2012-08-06  2:41   ` Ben Walton
2012-08-06  1:59 ` Junio C Hamano
2012-08-06  2:35   ` Ben Walton
2012-08-06 19:39     ` Jeff King
2012-08-06 19:57       ` Junio C Hamano
2012-08-06 21:31       ` Ben Walton
2012-08-06 21:34         ` Jeff King
2012-08-06 22:09           ` Ben Walton
2012-08-06 22:31             ` Jeff King [this message]
2012-08-06 22:39               ` Ben Walton
2012-08-06 22:42                 ` Jeff King
2012-08-06 23:31                   ` Ben Walton
2012-08-07  0:01                     ` Jeff King
2012-08-06 23:05               ` Andreas Schwab
2012-08-07  0:23                 ` Jeff King
2012-08-07  0:35                   ` Jeff King
2012-08-07  2:18                     ` Tay Ray Chuan
2012-08-07  3:01                     ` Ben Walton
2012-08-07  3:07                     ` [PATCH] Enable HAVE_DEV_TTY for Solaris Ben Walton
2012-08-07  3:43                       ` Junio C Hamano
2012-08-07  4:03                         ` Jeff King
2012-08-07  4:10                           ` Jeff King
2012-08-07 15:31                             ` Ben Walton
2012-08-08 14:13                             ` Erik Faye-Lund
2012-08-08 21:05                               ` Jeff King

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=20120806223113.GA16298@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=bwalton@artsci.utoronto.ca \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rctay89@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.