OpenComputers icon indicating copy to clipboard operation
OpenComputers copied to clipboard

Fix OpenOS '/bin/sh cmd' failing due to lack of env table

Open 0x0ade opened this issue 5 years ago • 3 comments
trafficstars

/bin/sh.lua should be able to execute a command passed as an argument, but currently fails to do so in interactive shells as sh.execute (in /lib/sh.lua) expects an environment table as the first parameter:

image

That environment table is given when running commands in the interactive shell, but is missing from the non-interactive sh.execute call.

Meanwhile, /bin/source.lua passes an environment table as the first argument to /bin/sh.lua when starting the sh process manually.

As such, I've decided to add a simple check if the first parameter is a table. If it is, it's assumed to be the environment table and won't be passed on. Otherwise _ENV will be used and all arguments will be passed on.

image

This should maintain compatibility with any existing usages of /bin/sh.lua as a child process. Admittedly, I've only tested it locally by manipulating a copy of /bin/sh.lua after installing OpenOS onto an OC computer.

(Sidenote: I was not sure whether to remove the env table from the argument list, or whether to skip it when unpacking the arg list. I went with the second option as I thought it'd be preferred, given how returning does the same.)

0x0ade avatar Dec 25 '19 14:12 0x0ade

first of all, i greatly dislike that /bin/sh takes a table as an arg no /bin program should ever have been written this way we inherited this strangeness from ages ago and well, it's far too late to change it now.

payonel avatar Jun 09 '22 05:06 payonel

nope i dont care it just doesnt make sense to assume ENV is passed to /bin/sh it is easy to correct this, and all my tests pass the only way this breaks someone's code is if they call /bin/sh via loadfile my fix corrects shell.execute and os.execute, which honestly is what everyone is using

payonel avatar Jun 09 '22 06:06 payonel

Well, guess this is not so simple to fix.

asiekierka avatar Sep 03 '22 20:09 asiekierka