Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Jul 2004 22:25:21 -0500
From:      Miguel Cardenas <mfcardenas@prodigy.net.mx>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc:        freebsd-questions@freebsd.org
Subject:   getenv() fails II
Message-ID:  <200407132225.21260.mfcardenas@prodigy.net.mx>
In-Reply-To: <20040713064604.GB39956@orion.daedalusnetworks.priv>
References:  <200407130133.41534.mfcardenas@prodigy.net.mx> <20040713064604.GB39956@orion.daedalusnetworks.priv>

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

>      4	int
>      5	main(void)
>      6	{
>      7	        char *s;
>      8
>      9	        s = getenv("HOSTNAME");
>     10	        if (s == NULL) {
>     11	                fprintf(stderr, "getenv error\n");
>     12	                exit(EXIT_FAILURE);
>     13	        }
>     14	        printf("HOSTNAME=%s\n", s);
>     15	        return EXIT_SUCCESS;
>     16	}

It returns "getenv error"... at least in console at X11, will try on simlple 
shell...

> By running 'env' you can see what variables are exported to the child
> processes of your shell.
> : keramida@orion:~$ env | grep HOSTNAME
> : keramida@orion:~$ echo $HOSTNAME
> : orion.daedalusnetworks.priv

HOSTNAME was not exported... and echo $HOSTNAME returns "bsd.mydomain.org"

> Clearly HOSTNAME isn't one of them.  Using the program shown above and
>
> env(1) you can verify this:
> : keramida@orion:~$ gcc -O -Wall -o lala lala.c
> : keramida@orion:~$ ./lala
> : getenv error
> : keramida@orion:~$ env HOSTNAME="testhost" ./lala
> : HOSTNAME=testhost
> : keramida@orion:~$

Efectively was that way... in Linux it used to work fine... then my next 
question should be... is there any other way to retrieve the hostname? and... 
as a normal user?

Thanks!!



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