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

Re: [PATCH] git-log: detect dup and fdopen failure

From
Jim Meyering <jim@meyering.net>
Date
Jun 27, 2007, 13:32 UTC
Message-ID
<87d4zho74h.fsf@rho.meyering.net>
In-Reply-To
<81b0412b0706270618p850df2dy41b2b797d82e3276@mail.gmail.com>
"Alex Riesen" <raa.lkml@gmail.com> wrote:
> On 6/27/07, Jim Meyering <jim@meyering.net> wrote:
>> I didn't see that fdopen could fail with ENOMEM.
>> That'll teach me to trust the man page.  I see POSIX does mention it.
s/trust/use/ :)
> I wouldn't trust Linux man pages nor POSIX, if I were you.
Ha.  Normally I don't rely solely on the man pages.
> Check if this works in some exotic but common
> environments (like MacOSX, Cygwin or HP-UX).

What do you mean? I know that dup and fdopen work in those environments.

Show 11 quoted lines
> (And yes, they probably are broken, and no, you can't fix them,
> and no, people are not going to stop using them).
>
>> +       if (!use_stdout) {
>> +               int fd = dup(1);
>> +               if (fd < 0 || (realstdout = fdopen(fd, "w")) == NULL)
>> +                       die("failed to duplicate standard output: %s",
>> +                           strerror(errno));
>> +       }
>
> Kinda stuffed in here. What's wrong with plain

It's ok, but for the fact that when dup fails, all you get is the uninformative EINVAL from fdopen.

Show 6 quoted lines
>  realstdout = fdopen(dup(1), "w");
>  if (!realstdout)
>    die("%s", strerror(errno));
>
> (Yes, I do think that "duplicate standard output" is useless,
> except for debugging. Exactly as strerror is, but that is shorter).

I like to include *something* in the diagnostic so that when someone sees it and reports it developers have an easier time finding where it comes from in the code. Especially with something as unlikely (and hard to reproduce) as this, that might be useful.

Previous: Alex RiesenNext: Alex Riesen
Message 5 of 15 in “detect dup failure”
  1. detect dup failureJim Meyering, Jun 27, 2007
  2. Alex RiesenJun 27, 2007
  3. git-log: detect dup and fdopen failureJim Meyering, Jun 27, 2007
  4. Alex RiesenJun 27, 2007
  5. Jim MeyeringJun 27, 2007
  6. Alex RiesenJun 27, 2007
  7. Jim MeyeringJun 27, 2007
  8. Alex RiesenJun 27, 2007
  9. Jim MeyeringJun 27, 2007
  10. Geert BoschJun 27, 2007
  11. Jim MeyeringJun 27, 2007
  12. Jim MeyeringJun 27, 2007
  13. Linus TorvaldsJun 27, 2007
  14. Josh TriplettJun 28, 2007
  15. Shawn O. PearceJun 28, 2007

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.