Asterisk 16 piped "-rx" breaks shell

Hello Everyone!

Recently we’ve installed Asterisk 16.0 to test it out and noticed one nasty thing.
We use asterisk -rx “something” on several occasions for monitoring purposes and it worked fine on 11, 13 versions. On Asterisk 16 it works as well but as soon as we pipe it to anything like grep or even simple wc -l like this
asterisk -rx 'pjsip show contacts' | wc -l
it gives you and output of the command but the shell immediately breaks down, the carriage return is not working anymore and you don’t see what you type in console, it is typed but not visible. This problem breaks our scripts and they are not working as expected anymore, i assume because some output written in variable is broken.
We use CentOS Linux release 7.5.1804 (Core).

Did anyone encounter this problem? Is it a bug or there is workaround for this?

Thank you.

It sounds like it has put console (not the shell) into canonical mode.presumably to allow more interactive use. This generally has to be done on standard input, not standard output, so will ignore the redirection. Really it should test whether standard output is a console before doing this. You could try redirecting standard input to null.

Normally you can resolve this by pressing line feed (control-J) typiing “reset” and then typing line feed again. LF, rather CR is the native Unix line separator, and reset is a shell command that attempts to put the terminal back into a sensible mode.

Hello David,

pressing line feed (control-J) typiing “reset” and then typing line feed again.

This returns console back to the normal state, thanks a lot for this! Is it Asterisk issue? Can it be fixed in future versions?

It sounds like it is an Asterisk issue. It should be checking for standard out to a console.

Thanks. I will then send bug report for this.

It may be due to Asterisk no longer including it’s own “libedit” library but instead relying on the system one instead. I wonder if it has a bug or problem. What version is it?

Hello jcolp,

Are you referring to libedit version? We have:
libedit-devel-3.0-12.20121213cvs.el7.x86_64
libedit-3.0-12.20121213cvs.el7.x86_64

If you install Asterisk 13 on the same system with both libedit and libedit-devel installed does the problem not occur?

Specifically we’re interested what happens if you configure and build Asterisk 13 with libedit-devel already installed.

How do i do that? Enable this option in configure?
I can recompile Asterisk 13 right now on this machine, should i perform make uninstall prior?

I recompiled Asterisk 13.23.1 with

./configure --with-libedit=internal --with-pjproject-bundled
make && make install

and then run

asterisk -rx ‘pjsip show contacts’ | grep Una

Everything works great, no issues, the output works as expected

Then i recompiled Asterisk 16.0 with

./configure --with-libedit=internal --with-jansson-bundled
make && make install

and run

asterisk -rx ‘pjsip show contacts’ | grep Una

The problem occurs and console breaks again. Hope that helps.

Please recompile Asterisk 13.23.1 with:

./configure --with-pjproject-bundled
make && make install
grep makeopts -e LIBEDIT

The goal is to see what happens when Asterisk 13 does not use the internal libedit. Please post the output from the grep of makeopts, that will confirm that the build uses the expected library.

Here is output after recompilation:

asterisk-13.23.1]# grep makeopts -e LIBEDIT
LIBEDIT_INTERNAL=no
LIBEDIT_INCLUDE=-I/usr/include/editline
LIBEDIT_LIB=-ledit -ltinfo

After this i run the same asterisk -rx command and console got broken now on 13 as well

I installed CentOS 7 in a virtual machine and I’m unable to reproduce this issue. Can you see if you’re able to reproduce the error using:

asterisk -rx 'core show application Exec'|wc -l

The goal of this is to rule out any possible “offensive” output from the pjsip contacts list, ‘core show application Exec’ will print the same thing for both of us.

In addition please let me know about your terminal. Are you running ‘asterisk -rx’ from the physical console or via SSH? If SSH please tell me what you are using to connect to the Asterisk server (SSH from Mac, putty from Windows, gnome-terminal or another from Linux)? Please tell me the value of your $TERM environmental variable in the shell which you used to run ‘asterisk -rx’.

How did you start the Asterisk daemon? If you are using systemd please provide the asterisk.service unit file you used to start it. If initrd then please provide the init script. If you directly started the Asterisk daemon from the terminal please let me know the value of your $TERM environmental variable from the terminal which started the daemon. Also any command-line arguments used to start the daemon.

Let me know if any changes were made to asterisk.conf compared to make samples.

coreyfarrel,

I can reproduce this issue with

asterisk -rx ‘core show application Exec’|wc -l

I get number of lines and broken console again.
I’m using Ubuntu 16.04.5 LTS

cat /etc/X11/default-display-manager
/usr/sbin/lightdm

and connect by SSH to the server.

ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.6, OpenSSL 1.0.2g 1 Mar 2016

The issue is the same using putty and Win10.

Asterisk box is VMWare Virtual box

Linux 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64
GNU/Linux

cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel® Xeon® CPU E5-2630 v3 @ 2.40GHz
stepping : 2
microcode : 0x3c
cpu MHz : 2399.998
cache size : 20480 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx hypervisor lahf_lm arat
bogomips : 4799.99
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

CLI> core show settings
PBX Core settings
----------------->
Version: 13.23.1
Build Options: BUILD_NATIVE, OPTIONAL_API
Maximum calls: 10000 (Current 0)
Maximum open file handles: 500000
Root console verbosity: 4
Current console verbosity: 4
Debug level: 0
Maximum load average: 0.000000
Minimum free memory: 0 MB
Startup time: 18:27:45
Last reload time: 18:27:45
System: Linux/3.10.0-514.26.2.el7.x86_64 built by root on x86_64 2018-10-30 12:58:14 UTC
System name:
Entity ID: 00:50:56:91:17:95
PBX UUID: 67e09d16-bebd-4101-a97d-6ca76740294f
Default language: en
Language prefix: Enabled
User name and group: asterisk/asterisk
Executable includes: Disabled
Transcode via SLIN: Enabled
Transmit silence during rec: Disabled
Generic PLC: Enabled
Generic PLC on equal codecs: Disabled
Min DTMF duration:: 50
Cache media frames: Enabled
RTP dynamic payload types: 96-127

  • Subsystems

Manager (AMI): Enabled
Web Manager (AMI/HTTP): Disabled
Call data records: Enabled
Realtime Architecture (ARA): Enabled

  • Directories

Configuration file: /etc/asterisk/asterisk.conf
Configuration directory: /etc/asterisk
Module directory: /usr/lib/asterisk/modules
Spool directory: /var/spool/asterisk
Log directory: /var/log/asterisk
Run/Sockets directory: /var/run/asterisk
PID file: /var/run/asterisk/asterisk.pid
VarLib directory: /var/lib/asterisk
Data directory: /var/lib/asterisk
ASTDB: /var/lib/asterisk/astdb
IAX2 Keys directory: /var/lib/asterisk/keys
AGI Scripts directory: /var/lib/asterisk/agi-bin

echo $TERM
xterm

I use /etc/init.d/asterisk script to control the service.
asterisk.txt (4.3 KB)

There were some changes in asterisk.conf but it is the same on our 11 and 13 boxes. Attaching it as well
asterisk.conf.txt (3.7 KB)

I am able to reproduce this issue. It seems to be related to having console=yes in asterisk.conf. Could you try removing that, instead set nofork=yes? The only difference from doing this is if you start the Asterisk daemon directly from the command-line (without init.d), you will need to run ‘asterisk -c’. When running from init.d this should not make any difference since init.d doesn’t need console enabled.

I’m working on a patch to fix the issue but I wanted to let you know how to work-around this issue with the existing versions.

1 Like

Hello coreyfarrell,

Thanks for the workaround, with nofork=yes no issues with output, i even didn’t have to restart asterisk.