[erlang-questions] Erlang 19.3 crashes when getting sockname of stdin
Mon Oct 16 14:31:33 CEST 2017
On Mon, Oct 16, 2017 at 02:14:13PM +0200, Attila Rajmund Nohl wrote:
> I have a oneliner that prints out which erlang process is listening on
> a given TCP port.
So basically the same thing as inet:i/0 does. Granted, it's not a
> Recently I upgraded from Debian 8.9 to Debian 9.2
> and on Erlang/OTP 19.3.1 this oneliner no longer works. The minimal
> example to reproduce:
> Erlang/OTP 19 [erts-8.3.1] [source] [64-bit] [smp:2:2]
> [async-threads:10] [hipe] [kernel-poll:false]
> Eshell V8.3.1 (abort with ^G)
> 1> inet:sockname(self()).
> ** exception error: no function clause matching prim_inet:sockname(<0.58.0>)
> 2> inet:sockname(hd(erlang:ports())).
> Failed to write to erl_child_setup: 9
> Crash dump is being written to: erl_crash.dump...done
inet:sockname() uses erlang:port_control(), which is a private command
interface. Each port driver can interpret the command as it sees fit,
without any guarantee that the result will be sane when you send
a command intended for a totally different driver.
In other words, don't do that even in local hacks unless you know inside
out the port driver you talk to.
If you need to use something that's not officially supported, use
inet:i() (shorter and bundled with the distribution) or dig out where
the TCP ports come from.
More information about the erlang-questions