Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Dec 2008 14:22:34 -0500
From:      "Brian A. Seklecki" <bseklecki@collaborativefusion.com>
To:        freebsd-questions@freebsd.org
Cc:        Bill Moran <wmoran@collaborativefusion.com>
Subject:   Default list of exported variables in sh(1) - $HOSTNAME
Message-ID:  <1230146554.4673.265.camel@soundwave.ws.pitbpa0.priv.collaborativefusion.com>

next in thread | raw e-mail | index | archive | help

--=-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 <bseklecki@collaborativefusion.com>
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--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1230146554.4673.265.camel>