getenv() fails II
Miguel Cardenas
mfcardenas at prodigy.net.mx
Tue Jul 13 20:19:48 PDT 2004
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 at orion:~$ env | grep HOSTNAME
> : keramida at 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 at orion:~$ gcc -O -Wall -o lala lala.c
> : keramida at orion:~$ ./lala
> : getenv error
> : keramida at orion:~$ env HOSTNAME="testhost" ./lala
> : HOSTNAME=testhost
> : keramida at 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!!
More information about the freebsd-questions
mailing list