From 433e64fe9fd2d291adb7f5445c2f530ad6896c9e Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Thu, 23 Apr 2015 16:19:26 +0200 Subject: [PATCH] MT#12547 Remove hardcoded port 42042 from tt2-wrapper/tt2-daemon We will use first free port instead which will be stored into /var/run/ngcpcfg.port file while tt2-daemon is up and running. Change-Id: I1a918f865d87863eef7d34be8abd1032282220b8 (cherry picked from commit e35944e2b5a264a80ab955a92c2988ec32999130) --- helper/tt2-daemon | 5 ++++- helper/tt2-wrapper | 14 +++++++++++++- scripts/build | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/helper/tt2-daemon b/helper/tt2-daemon index 0fe66e53..f8e1a3e5 100755 --- a/helper/tt2-daemon +++ b/helper/tt2-daemon @@ -31,7 +31,6 @@ sub get_server_port { my $server = IO::Socket::INET->new( 'Proto' => 'tcp', 'LocalAddr' => 'localhost', - 'LocalPort' => 42042, 'Listen' => SOMAXCONN, 'Reuse' => 1, ); @@ -39,6 +38,10 @@ sub get_server_port { binmode $server => ":encoding(utf8)"; + open (my $PORTFILE, '>', '/var/run/ngcpcfg.port'); + print $PORTFILE $server->sockport(); + close ($PORTFILE); + return $server; } diff --git a/helper/tt2-wrapper b/helper/tt2-wrapper index 4b4a4406..28a78d50 100755 --- a/helper/tt2-wrapper +++ b/helper/tt2-wrapper @@ -1,5 +1,17 @@ #!/bin/bash -echo "$@" | netcat localhost 42042 +if [ -r /var/run/ngcpcfg.port ] ; then + port=$(cat /var/run/ngcpcfg.port) +else + echo "ERROR: Couldn't read file /var/run/ngcpcfg.port" >&2 + exit 1 +fi + +if ! [[ $port =~ [0-9]+ ]] ; then + echo "ERROR: Wrong ngcpcfg tt2-daemon port: $port" >&2 + exit 1 +fi + +echo "$@" | netcat localhost "$port" exit $? diff --git a/scripts/build b/scripts/build index 9d6b5344..b5b56950 100755 --- a/scripts/build +++ b/scripts/build @@ -54,6 +54,7 @@ done # Kill all previous started tt2-daemon Perl processes if they were not stopped properly killall tt2-daemon 2>/dev/null || true +rm -f /var/run/ngcpcfg.port # Start new tt2-daemon Perl process ${HELPER}/tt2-daemon @@ -155,6 +156,7 @@ fi # Kill all previous started tt2-daemon Perl processes killall tt2-daemon 2>/dev/null || true +rm -f /var/run/ngcpcfg.port exit "$RC"