dspinellis / dgsh

Shell supporting pipelines to and from multiple processes
http://www.spinellis.gr/sw/dgsh/
Other
323 stars 22 forks source link

Piping to a bash builtin timeouts. #72

Closed mfragkoulis closed 7 years ago

mfragkoulis commented 7 years ago

Reported by @cinterloper. Awaiting for an example in order to reproduce the problem.

cinterloper commented 7 years ago

{cross post from #64 }

this will take a bit of explaining, but ill try and cut to the chase https://github.com/masterkorp/LuaBash this is a bash builtin that embeds a lua runtime in your bash enviornment it exposes a lua api to register new bash builtins

root@unit01:/home/g# cat echo.lua && echo

function l_echo()
  for line in io.lines() do
    print(line)
  end
end

bash.register("l_echo")
root@unit01:/home/g# type luabash
luabash is a shell builtin
root@unit01:/home/g# luabash
lua bash wrapper 0.0.3 (C) 2006 - 2009 Valentin Ziegler & Rene Rebe
usage:
    init
    load <lua chunk>
    call <lua function> [arguments]
root@unit01:/home/g# luabash load echo.lua
root@unit01:/home/g# ls / | l_echo
bin
boot
...

in dgsh it appears to load fine, however

root@unit01:/home/g# dgsh
root@unit01:/home/g# ps aux | grep  $$
root        36  0.0  0.0  18464  2480 pts/20   S    00:06   0:00 dgsh
...
root@unit01:/home/g# source /opt/luabash.bashrc
root@unit01:/home/g# type luabash
luabash is a shell builtin
root@unit01:/home/g# luabash load echo.lua
root@unit01:/home/g# type l_echo
l_echo is a function
l_echo ()
{
    luabash call l_echo $@
}
root@unit01:/home/g# ls / | l_echo
46 dgsh: timeout for negotiation. Exit.
cinterloper commented 7 years ago

On another inspection, im not 100% sure it has to do with builtins.

if i go to dgsh/unix-tools/bash/examples/loadables and run make, then load tee or head as a builtin, they appear to work

so, the best i can say now is "I experience the same issue as the | while read ticket when i use LuaBash"

cinterloper commented 7 years ago

@mfragkoulis with the latest dgsh, pipeing to while read, and pipeing to bash functions appears to work Where is the best place to look regarding information about this negotiation process so i may attempt to debug whats going on with LuaBash?

dspinellis commented 7 years ago

I've sent you our paper which contains a high level description via email. @mfragkoulis can provide more details regarding the implementation.

cinterloper commented 7 years ago

Thank you, this is very exciting.

mfragkoulis commented 7 years ago

I just reproduced your example (by the way I changed done -> end in the lua code you provided). It works fine on my side. The only difference I see to the workflow with dgsh that you included above is that I loaded luabash with enable -f build/luabash.so luabash (while you used source /opt/luabash.bashrc). I am not sure whether this is relevant but could you check? Here is the complete workflow I followed for your convenience:

mfg@stereo:~/dds/LuaBash$ ls
build  doc  echo.lua  Makefile  README.md  src
mfg@stereo:~/dds/LuaBash$ dgsh
mfg@stereo:~/dds/LuaBash$ enable -f build/luabash.so luabash
mfg@stereo:~/dds/LuaBash$ luabash load echo.lua
mfg@stereo:~/dds/LuaBash$ ls / | l_echo
build
doc
echo.lua
Makefile
README.md
src
cinterloper commented 7 years ago

Have you changed the Makefile for LuaBash at all so it compiles against something in the dgsh source tree instead of the normal bash headers?

mfragkoulis commented 7 years ago

The sole change in the Makefile regards the specific version of the linked Lua library.

diff --git a/Makefile b/Makefile
index 82fc52a..533d6c9 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CC=gcc
 SDIR=src
 ODIR=build
 DDIR=doc
-CFLAGS=-llua -shared -fPIC -Wall
+CFLAGS=-llua5.1 -shared -fPIC -Wall
 preffix=/usr/share
 # END
cinterloper commented 7 years ago

Ill tinker with this some more and get back to you, I still get 8178 dgsh: timeout for negotiation. Exit. when using the echo script from inside dgsh. I started exposing your dgsh_negotiate call in the lua api, but now your making me think somethings wrong with my build setup and that is probably unnecessary. Im using gcc 6.2 on Ubuntu 16.10 if that means anything to you.

g@unit01:~/code/LuaBash$ dgsh
dgsh-4.3$ enable -f build/luabash.so luabash
dgsh-4.3$ luabash load echo.lua
dgsh-4.3$ find / | l_echo
8497 dgsh: timeout for negotiation. Exit.
^Clua bash error: echo.lua:2: Interrupted system call
dgsh-4.3$ cat echo.lua
function l_echo()
  for line in io.lines() do
    print(line)
  end
end
bash.register("l_echo")

dgsh-4.3$ cat Makefile
# Luabash Makefile

# EDITABLE VARS
CC=gcc
SDIR=src
ODIR=build
DDIR=doc
CFLAGS= -I/opt/dgsh/core-tools/src/ -L/usr/include/luajit-2.1/ -lluajit-5.1 -shared -fPIC -Wall
preffix=/usr/share
# END

# Get targets and objects
TARGETS := $(wildcard  $(SDIR)/*.c)
OBJECTS := $(patsubst $(SDIR)%.c, $(ODIR)%.so, $(TARGETS))

build: $(TARGETS)
    @echo Making build dir
    @mkdir -p $(ODIR)
    $(CC) -o $(OBJECTS) $(TARGETS) $(CFLAGS)

.PHONY:  clean
clean:
    @rm -rf $(ODIR)
    @echo Done

install:
    @echo Installing the library..
    install -Dm 644 $(ODIR)/luabash.so $(DESTDIR)$(preffix)/luabash/luabash.so
    @echo Installing the documentation...
    install -Dm 644 README.md $(DESTDIR)$(preffix)/doc/luabash/README.md
    install -Dm 644 $(DDIR)/example.sh  $(DESTDIR)$(preffix)/doc/luabash/doc/example.sh
    install -Dm 644 $(DDIR)/internal.lua  $(DESTDIR)$(preffix)/doc/luabash/doc/internal.lua

dgsh-4.3$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.2.0-5ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)
dgsh-4.3$
mfragkoulis commented 7 years ago

Hi @cinterloper any updates on this? I'd like to close this if there is no confirmed bug with dgsh.

dspinellis commented 7 years ago

No answer, seems OK, closing.