lua-users home
lua-l archive

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


It was thus said that the Great sur-behoffski once stated:
> G'day,

  Hello.

> I've tried to come up with ways to execute commands without leaving
> scripts open to shell-special syntax hacks.

  I have some comments about the code.  First off, you don't have an option
to send stdout or stderr to a file.  And there are times when I don't care
out stdout or stderr and will redirect both to /dev/null.  Speaking of that,
you might want an option to redirect /dev/null into stdin so that any input
on stdin on the parent process isn't sucked up by the script being run.

  On <http://unixwiz.net/techtips/remap-pipe-fds.html>, I've never
encountered a process on a POSIX system that didn't have stdin, stdout and
stderr already open.  I don't know how much of a concern this is, but to me,
it seems a bit excessive.  

  You really need to be careful what you do in the child process before you
exec().  I noticed you check the options in the child process and call
error() on them.  Where does the error go?  It's the child process.  There's
a chance that the caller has a pcall() around the function call and the
child process will never actually exit, leading to some weird results.  I
would really check the options before the call to fork(), and in the child
process if there are any errors, call _Exit() [1] as that avoids any cleanup
that exit() does, like flushing any output buffers of open files (including
stdout, stderr and anything from fopen()).

  If execp() fails, there's probably nothing to gain from attepmting to
flush the pipes you've created.  Just call _Exit()---it's the safest thing
you can do.

  I also noticed this:

        local pid = posix.fork()
        if pid < 0 then
                return nil, "raw_exec: Unable to fork(): "
                        .. posix.errno(pid)

  You probably want this:

	local pid,err = posix.fork()
	if not pid then
		return nil, "raw_exec: Unable to fork(): " .. err

> I have only tried PosixExec under GNU/Linux because:
>      (a) That was what lglicua was all about; and
>      (b) I don't have a workable Windows installation to use.

  It may work under Windows, but Windows isn't POSIX so ... 

  -spc

[1]	C99.  POSIX also defines _exit(), which does the same thing as
	_Exit().