From dcd2526f079cad6a27fc72284f0977780a8fe198 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Mon, 23 Mar 2009 13:24:05 -0400 Subject: Handle multiple IP addresses without choking in the stateless code. (#443945) If you have multiple addresses that resolve to different things, it will still be unpredictable. In which case... set your hostname yourself. --- rc.d/rc.sysinit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rc.d/rc.sysinit b/rc.d/rc.sysinit index 65bf678e..5e5698fe 100755 --- a/rc.d/rc.sysinit +++ b/rc.d/rc.sysinit @@ -489,9 +489,10 @@ if [ "$READONLY" = "yes" -o "$TEMPORARY_STATE" = "yes" ]; then ipaddr= if [ "$HOSTNAME" = "localhost" -o "$HOSTNAME" = "localhost.localdomain" ]; then ipaddr=$(ip addr show to 0.0.0.0/0 scope global | awk '/[[:space:]]inet / { print gensub("/.*","","g",$2) }') - if [ -n "$ipaddr" ]; then + for ip in $ipaddr ; do + HOSTNAME= eval $(ipcalc -h $ipaddr 2>/dev/null) - hostname ${HOSTNAME} + [ -n "$HOSTNAME" ] && { hostname ${HOSTNAME} ; break; } fi fi -- cgit v1.2.1