From owner-freebsd-hackers Wed Oct 23 13:29:36 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id NAA08923 for hackers-outgoing; Wed, 23 Oct 1996 13:29:36 -0700 (PDT) Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id NAA08885 for ; Wed, 23 Oct 1996 13:28:32 -0700 (PDT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by irz301.inf.tu-dresden.de (8.6.12/8.6.12-s1) with ESMTP id WAA26036; Wed, 23 Oct 1996 22:21:43 +0200 Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id WAA01114; Wed, 23 Oct 1996 22:21:42 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.7.6/8.6.9) id WAA27409; Wed, 23 Oct 1996 22:19:14 +0200 (MET DST) From: J Wunsch Message-Id: <199610232019.WAA27409@uriah.heep.sax.de> Subject: Re: Linux emulation, gethostid() To: freebsd-hackers@freebsd.org (FreeBSD hackers) Date: Wed, 23 Oct 1996 22:19:14 +0200 (MET DST) Cc: msmith@atrad.adelaide.edu.au (Michael Smith) Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: <199610230908.SAA26604@genesis.atrad.adelaide.edu.au> from Michael Smith at "Oct 23, 96 06:38:26 pm" X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E X-Mailer: ELM [version 2.4ME+ PL17 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk As Michael Smith wrote: > > Grab the number you like by any means you like somewhere in rc.local, > > and issue a sethostid(3) with it. No need to bloat the kernel for > > this. > > Gotcha; I hadn't seen kern.hostid before. Anyone recommend a quick example > I can look at for retrieving a sysctl value from inside an LKM? What do you need it for in an LKM? Put this as, say, /usr/sbin/sethostid, and invoke it from rc.local. It tries to find out the lower 32 bit of the (first) ethernet address, and failing to find any ethernet interfaces, it uses the first four bytes of the MD5 checksum of the hostname. #!/bin/sh export PATH="/bin:/usr/bin:/sbin:/usr/sbin" hostid=$(ifconfig -a | awk -F : '/ether/ {printf $3 $4 $5 $6; exit}') if [ "$hostid" = "" ] then hostid=$(hostname | md5 | sed -e 's/\(........\).*/\1/') fi hostid=$( (echo ibase=16; echo $hostid | tr '[a-z]' '[A-Z]') | bc) sysctl -wn kern.hostid=$hostid >/dev/null -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)