Beam wallet CLI behavior with bash scripting


#1

I noticed this some time ago - while writing my “beam_run.php” script so that I can easily “launch beam” and don’t have to remember what to do and launch and where and using what (e.g. screen) and so on. At the end of that script, I wanted to show my wallet info.

It never worked. I debugged it and it seemed the PHP script would die right at the exec() call without any errors (error reporting was E_ALL) and would never continue execution. Weird I thought, but I ignored it.

Then I noticed a simple one liner (in bash) like this doesn’t work:
./beam-wallet info; beam-wallet address_list

You will NEVER see the address list. When swapping the command around you will never see info command.

Even this doesn’t work:
./beam-wallet info; echo "ZZZZ"

Echo never gets executed. I’ve never seen such a behavior. Hence my latest bash script fails as well:

#!/bin/bash

cd /spc/beam
./beam-wallet info
sleep 10
echo "A"
./beam-wallet address_list

It never sleeps, never executes echo or the other wallet command. How is this possible? Running gdb --args ./beam-wallet info it seems like the wallet crashes after printing the info:

[Thread 0x7ffff7222700 (LWP 18223) exited]

Thread 1 "beam-wallet" received signal SIGINT, Interrupt.
0x00007ffff79c3c60 in __GI___nanosleep (requested_time=0x7fffffffe2b0, remaining=0x7fffffffe2c0) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.

Also it seems pipes break, this doesn’t work consistently:

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............5 beams 709888 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............5 beams 709888 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............5 beams 709888 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............5 beams 709888 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............5 beams 709888 groth

u@h:/spc/beam$ ./beam-wallet info | grep Total
Total coinbase............0 groth
Total fee.................0 groth
Total unspent.............50 beams 709888 groth

The farther in in the input you grep, the more chance there is to get no results (even though they are a part of the output).

What’s going on here? I’ve never seen a program that also always causes it’s parent to crash, I assume that’s what’s happening, but WHY? Running latest ubuntu 18.04 sever. Thank you! :slight_smile:


#2

OK if I do this in bash:

#!/bin/bash

trap '' INT

cd /spc/beam
./beam-wallet info
./beam-wallet address_list

Then it “works”. So the wallet generates an interrupt signal (CTRL+C) at end of it’s run, and we catch it, and do nothing about it (and continue execution). But the question is WHY?:smiley: I never knew a program could generate a signal like this. I knew a process can RECEIVE a signal, but generating it like this… glad I learned something new! :slight_smile:

Now, is this a bug, or is it intended?:slight_smile: