From owner-freebsd-questions@FreeBSD.ORG Wed Jul 14 03:19:48 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 41FB616A4CE for ; Wed, 14 Jul 2004 03:19:48 +0000 (GMT) Received: from smtp.prodigy.net.mx (nlpproxy03.prodigy.net.mx [148.235.52.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id DF66843D3F for ; Wed, 14 Jul 2004 03:19:47 +0000 (GMT) (envelope-from mfcardenas@prodigy.net.mx) Received: from smtp.prodigy.net.mx (nlpproxy03 [148.235.52.23]) by smtp.prodigy.net.mx (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0I0T00IMVNWUL7@smtp.prodigy.net.mx>; Tue, 13 Jul 2004 22:19:43 -0500 (CDT) Received: from dup-200-64-114-177.prodigy.net.mx (du-200-64-114-177.prodigy.net.mx [200.64.114.177])(built Sep 8 2003)) with ESMTP id <0I0T005J3NWS9X@smtp.prodigy.net.mx>; Tue, 13 Jul 2004 22:19:42 -0500 (CDT) Date: Tue, 13 Jul 2004 22:25:21 -0500 From: Miguel Cardenas In-reply-to: <20040713064604.GB39956@orion.daedalusnetworks.priv> To: Giorgos Keramidas Message-id: <200407132225.21260.mfcardenas@prodigy.net.mx> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline User-Agent: KMail/1.5.4 X-imss-version: 2.5 X-imss-result: Passed X-imss-scores: Clean:99.90000 C:22 M:2 S:5 R:5 X-imss-settings: Baseline:3 C:2 M:2 S:2 R:2 (0.5000 1.0000) References: <200407130133.41534.mfcardenas@prodigy.net.mx> <20040713064604.GB39956@orion.daedalusnetworks.priv> cc: freebsd-questions@freebsd.org Subject: getenv() fails II X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: mfcardenas@prodigy.net.mx List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jul 2004 03:19:48 -0000 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!!