From owner-freebsd-questions@FreeBSD.ORG Wed Dec 24 19:22:36 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 82315106564A for ; Wed, 24 Dec 2008 19:22:36 +0000 (UTC) (envelope-from bseklecki@collaborativefusion.com) Received: from collaborativefusion.com (mx01.pub.collaborativefusion.com [206.210.89.201]) by mx1.freebsd.org (Postfix) with ESMTP id 2EF1F8FC16 for ; Wed, 24 Dec 2008 19:22:36 +0000 (UTC) (envelope-from bseklecki@collaborativefusion.com) Received: from Internal Mail-Server by mx01 (envelope-from bseklecki@collaborativefusion.com) with SMTP; 24 Dec 2008 14:22:35 -0500 From: "Brian A. Seklecki" To: freebsd-questions@freebsd.org Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-y7lVL+ERac5USJy3F33W" Organization: Collaborative Fusion, Inc. Date: Wed, 24 Dec 2008 14:22:34 -0500 Message-Id: <1230146554.4673.265.camel@soundwave.ws.pitbpa0.priv.collaborativefusion.com> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 (2.22.3.1-1.fc9) Cc: Bill Moran Subject: Default list of exported variables in sh(1) - $HOSTNAME X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: bseklecki@collaborativefusion.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Dec 2008 19:22:36 -0000 --=-y7lVL+ERac5USJy3F33W Content-Type: text/plain Content-Transfer-Encoding: quoted-printable All: I've got a fun problem ... I'm having trouble tracking down where the default list of exported variables is set for sh(1). I've got a piece of PHP code that runs on GNU/Linux but not FreeBSD because (I think) $HOSTNAME is exported by default. =20 The PHP CLI calls $_ENV["HOSTNAME"], which under GNU/Linux returns: $ php -r 'print gethostbyaddr(gethostbyname($_ENV["HOSTNAME"]))' soundwave.ws....collaborativefusion.com In HTTP/CGI mode, I can call $_SERVER[]. But $_ENV[] should work in both CLI and HTTP mode.=20 However, because Apache is spawned from sh(1) from rc(8) and in FreeBSD 6.x, $HOSTNAME is not exported by default, which is what $_ENV[] uses (getenv()): $ uname -a FreeBSD bdb00 6.3-RELEASE-p2 $ export SSH_CLIENT USER MAIL HOME SSH_TTY PAGER ENV LOGNAME BLOCKSIZE TERM PATH SHELL SSH_CONNECTION FTP_PASSIVE_MODE EDITOR ----------- Compare to: linux$ uname -a Linux soundwave 2.6.25.14-108.fc9.x86_64=20 linux$ bash --version GNU bash, version 3.2.33(1)-release (x86_64-redhat-linux-gnu) linux$ export|wc -l 52 linux$ export|grep -i host declare -x HOSTNAME=3D"soundwave" ------------ It could be set in the sources for sh(1) or shells/bash, login(1), possibly somehow related to PAM. =20 src/usr.bin/login/login.c has : static int export(const char *s) { * - Do not export certain variables. This list was taken from the * Solaris pam_putenv(3) man page. * Then export it. static const char *noexport[] =3D { "SHELL", "HOME", "LOGNAME", "MAIL", "CDPATH", "IFS", "PATH", NULL }.. $HOSTNAME not listed here ------------------- src/bin/sh/var.c has environment(){} and at least one other call to getnamebyaddr() ------------ Bash has set_machine_vars() in variables.c: temp_var =3D set_if_not ("HOSTNAME", current_host_name); ------------- There are also about 500 calls to getenv() in the PHP source code under main/, however none explicitly for $HOSTNAME. =20 This is similar to bash, so unless the Redhat people are maintaining lots of SRPM patches to Bash _and_ PHP, I'm prepared to isolate the problem to FreeBSD and sh(1)/login(1) Thoughts? (Happy holidays all!) ~BAS --=20 Brian A. Seklecki Collaborative Fusion, Inc. --=-y7lVL+ERac5USJy3F33W Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAklSi/oACgkQCne6BNDQ+R8MEACdFoJ/bSMJcTk8XKRGcOJvHlOR GtEAn3O/EBh+LIH0IVpQj2S8DHvjYslI =Ka/h -----END PGP SIGNATURE----- --=-y7lVL+ERac5USJy3F33W--