git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Avoid crippled getpass function on Solaris

From
Jeff King <peff@peff.net>
Date
Aug 6, 2012, 22:31 UTC
Message-ID
<20120806223113.GA16298@sigill.intra.peff.net>
In-Reply-To
<1344290892-sup-1108@pinkfloyd.chass.utoronto.ca>
On Mon, Aug 06, 2012 at 06:09:08PM -0400, Ben Walton wrote:
Show 6 quoted lines
> > 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
Previous: Ben WaltonNext: Ben Walton
Message 11 of 27 in “Avoid crippled getpass function on Solaris”
  1. Avoid crippled getpass function on SolarisBen Walton, Aug 5, 2012
  2. Tay Ray ChuanAug 6, 2012
  3. Ben WaltonAug 6, 2012
  4. Junio C HamanoAug 6, 2012
  5. Ben WaltonAug 6, 2012
  6. Jeff KingAug 6, 2012
  7. Junio C HamanoAug 6, 2012
  8. Ben WaltonAug 6, 2012
  9. Jeff KingAug 6, 2012
  10. Ben WaltonAug 6, 2012
  11. Jeff KingAug 6, 2012
  12. Ben WaltonAug 6, 2012
  13. Jeff KingAug 6, 2012
  14. Ben WaltonAug 6, 2012
  15. Jeff KingAug 7, 2012
  16. Andreas SchwabAug 6, 2012
  17. Jeff KingAug 7, 2012
  18. Jeff KingAug 7, 2012
  19. Tay Ray ChuanAug 7, 2012
  20. Ben WaltonAug 7, 2012
  21. Enable HAVE_DEV_TTY for SolarisBen Walton, Aug 7, 2012
  22. Junio C HamanoAug 7, 2012
  23. Jeff KingAug 7, 2012
  24. Jeff KingAug 7, 2012
  25. Ben WaltonAug 7, 2012
  26. Erik Faye-LundAug 8, 2012
  27. Jeff KingAug 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.