Subject: bin/25038: sushi(8) ignores hostname setting in rc.conf
To: None <gnats-bugs@gnats.NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: netbsd-bugs
Date: 04/03/2004 19:07:15
>Number: 25038
>Category: bin
>Synopsis: sushi(8) ignores hostname setting in rc.conf
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Apr 03 17:08:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator: Peter Postma
>Release: NetBSD 2.0B
>Organization:
>Environment:
System: NetBSD mercury.pointless.nl 2.0B NetBSD 2.0B (mercury) #31: Thu Apr 1 17:26:31 CEST 2004 root@mercury.pointless.nl:/usr/obj/sys/arch/sparc64/compile/mercury sparc64
Architecture: sparc64
Machine: sparc64
>Description:
When changing the hostname in the "Network related configuration"
menu, sushi(8) writes the new hostname to /etc/myname. It ignores
the hostname setting in /etc/rc.conf if it exists.
>How-To-Repeat:
Make sure that the hostname setting is set to something in rc.conf.
Start sushi(8). Goto "Network related configuration", goto
"Modify this machine's hostname", modify the hostname,
press enter, enter. Check /etc/myname and /etc/rc.conf.
>Fix:
rc.conf should be checked if it contains a hostname.
The diff below does that. It also changes the command 'hostname -s'
to 'hostname' because we really want the full name.
Index: share/sushi/network/hostname/help
===================================================================
RCS file: /cvsroot/src/share/sushi/network/hostname/help,v
retrieving revision 1.1
diff -u -r1.1 help
--- share/sushi/network/hostname/help 25 Apr 2001 03:43:29 -0000 1.1
+++ share/sushi/network/hostname/help 3 Apr 2004 16:35:10 -0000
@@ -2,5 +2,3 @@
boot time, will only modify the /etc/myname file, and take effect on your
next reboot. Setting it now, will only modify the running hostname. By
selecting both, you can permanently change your hostname, immediately.
-
-$NetBSD: help,v 1.1 2001/04/25 03:43:29 garbled Exp $
Index: share/sushi/network/hostname/script
===================================================================
RCS file: /cvsroot/src/share/sushi/network/hostname/script,v
retrieving revision 1.1
diff -u -r1.1 script
--- share/sushi/network/hostname/script 25 Apr 2001 03:43:29 -0000 1.1
+++ share/sushi/network/hostname/script 3 Apr 2004 16:35:10 -0000
@@ -2,12 +2,24 @@
# $NetBSD: script,v 1.1 2001/04/25 03:43:29 garbled Exp $
if [ "$2" = "both" -o "$2" = "boot" ]; then
- echo "$1" >/etc/myname
+ . /etc/rc.conf
+ # $hostname is not set in rc.conf and /etc/myname exists
+ if [ -z "$hostname" ] && [ -f "/etc/myname" ]; then
+ echo "$1" >/etc/myname
+ # $hostname is set in rc.conf, edit it
+ elif [ -n "$hostname" ]; then
+ sed "s/hostname=.*/hostname=\"$1\"/" < /etc/rc.conf \
+ > /etc/rc.conf.new
+ mv /etc/rc.conf.new /etc/rc.conf
+ # Nothing is set, so set the new hostname in rc.conf
+ else
+ echo "hostname=\"$1\"" >>/etc/rc.conf
+ fi
fi
if [ "$2" = "both" -o "$2" = "now" ]; then
hostname $1
fi
-if [ "$?" = "0" ]; then
+if [ $? -eq 0 ]; then
echo "Hostname has been changed to $1"
else
echo "Failed to change hostname to $1"
Index: share/sushi/network/hostname/script1
===================================================================
RCS file: /cvsroot/src/share/sushi/network/hostname/script1,v
retrieving revision 1.1
diff -u -r1.1 script1
--- share/sushi/network/hostname/script1 25 Apr 2001 03:43:29 -0000 1.1
+++ share/sushi/network/hostname/script1 3 Apr 2004 16:35:10 -0000
@@ -1,8 +1,11 @@
#!/bin/sh
# $NetBSD: script1,v 1.1 2001/04/25 03:43:29 garbled Exp $
-if [ -f "/etc/myname" ]; then
+. /etc/rc.conf
+if [ -z "$hostname" ] && [ -f "/etc/myname" ]; then
cat /etc/myname
+elif [ -n "$hostname" ]; then
+ echo $hostname
else
- hostname -s
+ hostname
fi
>Release-Note:
>Audit-Trail:
>Unformatted: