[erlang-bugs] [escript] Arguments passed to emulator by "%%!" affect the os:cmd/1

Sergey Samokhin prikrutil@REDACTED
Tue May 19 00:24:46 CEST 2009


Hello.

I find escript awesome when it comes to writing CLI-interfaces. Thanks
for it! I tried to use one of new features which R13 (or R12B5?) had
introduced and found a bug.

Short description: a node started by os:cmd/1 from escript with some
"%%!"-arguments passed can't be accessed in the usual manner
(net_adm:ping/1, rpc:call/4 etc).

I've attached to this letter two almost the same escript's:

One of them (start_faulty_node.erl) uses "%%! -smp enable -sname cli"
string to give the node short name while other
(start_working_node.erl) calls net_kernel:start/1 for that.

Both of them are also available at http://gist.github.com/113740

Steps to reproduce:

1. Start start_faulty_node.erl. You will see the following:

[prikrutil@REDACTED tmp]$ ./start_faulty_node.erl
# I don't see the node. test@REDACTED
# But it's still running. You should stop the faulty node by smth like
"killall beam.smp"

In fact, the child node has been started, but for some reason can't be
accessed. Stop it using kill or killall.

2. After stopping node started at Step 1 run start_working_node.erl to
make sure that replacing "%%! ..." with net_kenrel:start/1 makes the
problem go away:

[prikrutil@REDACTED tmp]$ ./start_working_node.erl
# Node test@REDACTED has been successfully started, I'll stop it for you.

Now it works as it should.

Using htop I've found that these two escripts lead to slightly
different start commands.

start_faulty_node.erl:

/usr/lib/erlang/erts-5.7.1/bin/beam.smp -- -root /usr/lib/erlang
-progname erl -- -home /home/prikrutil -noshell -noinput -sname
test@REDACTED ! -smp enable -sname cli

start_working_node.erl:

usr/lib/erlang/erts-5.7.1/bin/beam.smp -- -root /usr/lib/erlang
-progname erl -- -home /home/prikrutil -noshell -noinput -sname
test@REDACTED

Take a look at the end of the start_faulty_node.erl's command. "! -smp
enable -sname cli" is what differs first command from second one. It
must be the key to this problem.

It looks like this tail is taken into account by newly started node.
For example, if your escript has "%%! -smp disable", then all the
nodes started from it by using os:cmd/1 will have smp disabled.

Erlang: R13B: Erlang R13B (erts-5.7.1) [source] [smp:2:2] [rq:2]
[async-threads:0] [hipe] [kernel-poll:false]
OS: Archlinux current (Linux myhost 2.6.29-ARCH #1 SMP PREEMPT Sat May
9 12:47:43 UTC 2009 i686 Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz
GenuineIntel GNU/Linux)

--
Sergey Samokhin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: start_faulty_node.erl
Type: application/octet-stream
Size: 650 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20090518/ad2a8b6d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: start_working_node.erl
Type: application/octet-stream
Size: 665 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20090518/ad2a8b6d/attachment-0001.obj>


More information about the erlang-bugs mailing list