LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-23-2014, 01:11 PM   #1
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,053

Rep: Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205
$HOSTNAME in /etc/profile ?


A quick question to satisfy my curiosity:

Slackware sets $HOSTNAME within /etc/profile. Obviously I know what it is, but does anyone know what it's actually for? Are there any specific programs that reference it?
 
Old 08-23-2014, 01:18 PM   #2
willysr
Senior Member
 
Registered: Jul 2004
Location: Jogja, Indonesia
Distribution: Slackware-Current
Posts: 4,776

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
webmin?
 
Old 08-23-2014, 04:07 PM   #3
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quite a few, it seems:

ttk@wip:~> grep -ac HOSTNAME /usr/bin/* /bin/* /usr/local/bin/* /sbin/* /usr/sbin/* /usr/local/sbin/* | & grep -v :0 | grep -v grep:
/usr/bin/bash:2
/usr/bin/ccmake:3
/usr/bin/cmake:3
/usr/bin/cmake-gui:3
/usr/bin/cpack:3
/usr/bin/ctest:3
/usr/bin/curl:1
/usr/bin/distcc:1
/usr/bin/distccd:1
/usr/bin/distccmon-gnome:1
/usr/bin/distccmon-text:1
/usr/bin/epic5:1
/usr/bin/epic5-1.1.6:1
/usr/bin/esdplay:1
/usr/bin/gnome-keyring-daemon:1
/usr/bin/jed:1
/usr/bin/jed-script:1
/usr/bin/jmacs:1
/usr/bin/joe:1
/usr/bin/jpico:1
/usr/bin/jstar:1
/usr/bin/lsdistcc:1
/usr/bin/mysqldumpslow:1
/usr/bin/mysqltest:1
/usr/bin/mysqltest_embedded:1
/usr/bin/net:1
/usr/bin/netwatch:1
/usr/bin/newspost:1
/usr/bin/nn:1
/usr/bin/nnadmin:1
/usr/bin/nnbatch:1
/usr/bin/nncheck:1
/usr/bin/nngoback:1
/usr/bin/nnpost:1
/usr/bin/nntidy:1
/usr/bin/nnview:1
/usr/bin/patch-metamail:4
/usr/bin/perror:1
/usr/bin/rcs2log:1
/usr/bin/rjoe:1
/usr/bin/rn:1
/usr/bin/rtin:1
/usr/bin/slrn:1
/usr/bin/tin:1
/usr/bin/trn:1
/bin/bash:2
/bin/ksh:2
/bin/rksh:2
/bin/sh:2
/sbin/lvmdump:1
/sbin/netconfig:14
/usr/sbin/NetworkManager:2
/usr/sbin/bluetoothd:1
/usr/sbin/dnsmasq:1
/usr/sbin/mtr:1
/usr/sbin/openvpn:1
/usr/sbin/samba_dnsupdate:1
/usr/sbin/samba_spnupdate:1
/usr/sbin/samba_upgradedns:3
/usr/sbin/tcpdump:1
/usr/sbin/tcpdump.4.4.0:1
 
Old 08-23-2014, 04:35 PM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,053

Original Poster
Rep: Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205
I don't think a grep helps here. There's plenty of reasons the string HOSTNAME might show up in an executable that have little to do with environment variables.
 
Old 08-23-2014, 08:32 PM   #5
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by GazL View Post
I don't think a grep helps here. There's plenty of reasons the string HOSTNAME might show up in an executable that have little to do with environment variables.
It turns out that you're right. Grepping the sources shows that only some of them use HOSTNAME as a reference to the environment variable.

Code:
n/netwatch/netwatch-1.3.0-1.tar.gz:  if ((hostp = getenv ("HOSTNAME")) == NULL)
n/newspost/newspost-2.1.1.tar.gz:               envopt2 = getenv("HOSTNAME");
n/sendmail/sendmail.8.14.7.tar.gz:      APPENDDEF(`conf_sendmail_ENVDEF', `-DNEEDLOCAL_HOSTNAME_LENGTH=0')
sh/bash-4.1.tar.gz:(@env{HOSTTYPE}, @env{OSTYPE}, @env{MACHTYPE}, and @env{HOSTNAME}),
sh/bash-4.1.tar.gz:`HOSTNAME'
sh/bash-4.1.tar.gz:     host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
sh/bash-4.1.tar.gz:* HOSTNAME:                              Bash Variables.      (line 339)
octave/archive/octave-3.2.4.tar.gz:    host = getenv("HOSTNAME");

ttk@spork:~/tools/slackware/sw141/source> find -name "*.tar.bz2" -print -exec /bin/sh -c 'bzcat {} | grep -a HOSTNAME | grep -i env' \; | /usr/bin/less -X
./ap/jed/jed-0.99-19.tar.bz2
        b = getenv ("HOSTNAME");

ttk@spork:~/tools/slackware/sw141/source> find -name "*.tar.xz" -print -exec /bin/sh -c 'xzcat {} | grep -a HOSTNAME | grep -ai env' \; | /usr/bin/less -X
./a/tcsh/tcsh-6.18.01.tar.xz
        setenv HOSTNAME $COMPUTERNAME
./ap/joe/joe-3.7.tar.xz
        unsigned char *host = (unsigned char *)getenv("HOSTNAME");
./ap/mariadb/mariadb-5.5.32.tar.xz
  theEnvHostNamePtr = NdbEnv_GetEnv("HOSTNAME", buf, 255);
./d/distcc/distcc-3.1.tar.xz
    envh2 = getenv("HOSTNAME");
./d/guile/guile-2.0.9.tar.xz
  char *s = getenv ("HOSTNAME");
./d/subversion/subversion-1.7.13.tar.xz
                                         os.environ['HOSTNAME'],
./kde/src/kdesdk-4.10.5.tar.xz
                         (concat (getenv "LOGNAME") "@" (getenv "HOSTNAME"))
./kde/src/kdelibs-4.10.5.tar.xz
  local_file_3.setHost(getenv("HOSTNAME"));
./l/glib2/glib-2.36.4.tar.xz
            session_bus_address = g_getenv ("HOSTNAME");
./l/libcddb/libcddb-1.3.2.tar.xz
                                     to the value of the 'HOSTNAME' environment
  $USER and $HOSTNAME environment variables if they were present.
./n/mutt/mutt-1.5.22.tar.xz
if the environment variable $HOSTNAME is set to ?kremvax.? (See $record for
./n/slrn/slrn-1.0.1.tar.xz
   if ((NULL != (host1 = getenv ("HOSTNAME")))
./n/tin/tin-2.0.1.tar.xz
                        if ((ptr = getenv("HOSTNAME")) != NULL)
./xap/windowmaker/WindowMaker-0.95.5.tar.xz
        h = getenv("HOSTNAME");
so .. not as many as I thought, but some.
 
2 members found this post helpful.
Old 08-24-2014, 06:53 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,053

Original Poster
Rep: Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205Reputation: 5205
Thanks for that, ttk. I should have probably done that myself.

Looking at the 'jed' code, it does this:
Code:
 if ((-1 == gethostname (buf, sizeof (buf)))
       || (*buf == 0))
     {
        b = getenv ("HOSTNAME");
        if ((b == NULL) || (*b == 0))
          return NULL;
     }
... so the environment variable is just a fallback.

The 'distcc' code seems to be doing all manner of weird things rather than just calling gethostname(), but again the getenv() call is just one of many things it tries.

The 'guile' one just seems to be an example function in the documentation.

I didn't check any of the others, but I wouldn't be surprised to find that its mostly just a fallback mechanisn for when gethostname() isn't there.


Anyway, what sparked all of this off was that I was reviewing the contents of my /etc/profile to see what could be safely cleared out, and wondered what prompted HOSTNAME= to be added to it in the first place. I suspect it'll turn out to be one of those reasons that has been lost in time.

Last edited by GazL; 08-24-2014 at 06:56 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to import Thunderbird Profile backup containng mail archive with Profile Manager? Beukel Linux - Newbie 2 02-16-2014 04:01 AM
HOSTNAME = hostname -> HOSTNAME: command not found ? thomas2004ch Linux - Software 2 08-26-2013 09:25 PM
clients CAN resolve hostname of server w/nslookup, but CANNOT access by hostname WTF? psycroptic Linux - Networking 9 11-10-2012 12:24 PM
Changed hostname during install, now CUPS has wrong hostname on web interface slinx Linux - Software 1 08-07-2009 09:01 PM
after hostname change, syslogd still output previous hostname to messages file tiger2000 Linux - General 3 07-22-2009 10:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration