Default list of exported variables in sh(1) - $HOSTNAME

Brian A. Seklecki bseklecki at collaborativefusion.com
Wed Dec 24 19:22:36 UTC 2008


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.  

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. 

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 
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="soundwave"

------------

It could be set in the sources for sh(1) or shells/bash, login(1),
possibly somehow related to PAM.
 
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[] = {
      "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 = 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.  

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

-- 
Brian A. Seklecki <bseklecki at collaborativefusion.com>
Collaborative Fusion, Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20081224/c9896f08/attachment.pgp


More information about the freebsd-questions mailing list