lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Quoth M Joonas Pihlaja <>, on 2010-02-27 15:47:18 +0200:
> On Sat, 27 Feb 2010, Drake Wilson wrote:
> > More specifically, I imagine "improving" it in this case would
> > introduce a distinctly nonportable element for not very much gain.
> io.popen() is already a distinctly nonportable element.

Earlier, I was under the impression that popen() and pclose() were
actually specified by ANSI C as part of stdio (and that mainly the
format of the command was left unspecified, much like for system()).
Upon further inspection, I was mistaken.  I retract the statement
quoted above.  I believe the weaker idea that SIGPIPE catching is less
portable than popen() is still approximately true, but I move to a
more neutral position regarding what to do about it.

SIGPIPE is something of a historical artifact from early Unix, AIUI;
it only makes sense for programs that would not already abort upon
finding that they couldn't write part of their output.  This may have
been true for many Unix programs due to a pervasive lack of checking
error returns, and it's certainly a convenient property sometimes.
One can't simply change all the Unixes to not deliver SIGPIPE, because
that would be a breaking change to the semantics, and this also means
it is possible that Lua scripts that run only on Unix systems and that
depend on SIGPIPE being delivered (for, say, writes to stdout) will
break if Lua changes to stop delivering SIGPIPE, though they will
break in a fixable way.  I'm not sure there's a good solution here.

A similar but less implementationally prominent issue also appears for
SIGXFSZ, and possibly for things like SIGXCPU.  These don't happen as
much because the relevant rlimits are not as commonly set, but:

  $ uname -a
  Linux drache 2.6.29-1-amd64 #1 SMP Fri Apr 17 10:12:36 UTC 2009 x86_64 GNU/Linux
  $ (ulimit -f 1; lua)
  Lua 5.1.4  Copyright (C) 1994-2008, PUC-Rio
  > f ='xyzzy', 'w')
  > s = 'x'; for i = 1, 15 do s = s .. s end
  > f:write(s)
  $ (c=$?; echo $c; echo $((c - 128)); ce -Fs 'strsignal('$((c - 128))')')
  File size limit exceeded
   ---> Drake Wilson