lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
> That is true. Perhaps the best solution to all these problems would be
> to prohibit Lua from closing a standard file (stdin/stdout/stderr).
> Older versions of Lua had this restriction, I cannot remember why
> we lifted it.

Well, the implementation in Lua 5.0 was problematic:

  if (f == stdin || f == stdout || f == stderr) {... don't close ...}

Now imagine a process is started with any of these closed (e.g. a
daemon) and then opens a regular file with Some stdio
implementations map the new file handle to one of these three
slots and so the file cannot be properly closed from Lua.

Fortunately liolib has changed in Lua 5.1 and allows per-file
close functions (e.g. fclose vs. pclose). The obvious change is
to set a dummy close function for the three standard handles.