Dealing with clearenv()
Joe Marcus Clarke
marcus at marcuscom.com
Sun Nov 19 12:36:34 PST 2006
On Sun, 2006-11-19 at 20:29 +0000, Sevan / Venture37 wrote:
> Chillispot 1.1 uses clearenv() which is not available in FreeBSD. What's
> the best way for dealing with this, atm I'm using the following patch to
> the source code which seems to work & none of the testers have reported
> back with any problems. Is there a better way to deal with the issue??
> +#ifdef HAVE_CLEARENV
> if (clearenv() != 0) {
> sys_err(LOG_ERR, __FILE__, __LINE__, errno,
> "clearenv() did not return 0!");
> exit(0);
> }
> +#else
> + extern char **environ;
> + environ[0] = NULL;
> + if (environ[0] != NULL) {
> + sys_err(LOG_ERR, __FILE__, __LINE__, errno,
> + "Venture37 doesn't know what he's doing!!!");
> + exit(0);
> + }
> +#endif
This will work, but you do not need the check to make sure environ[0] is
NULL. And you should declare extern char **environ at the top of a
block so that the code compiles on non-C99 compilers. This might make
things a bit cleaner:
int
my_cleanenv (void)
{
#ifdef HAVE_CLEARENV
return cleanenv();
#else
extern char **environ;
environ[0] = NULL;
return 0;
#endif
}
...
if (my_cleanenv() != 0) {
...
Joe
--
PGP Key : http://www.marcuscom.com/pgp.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20061119/7f559117/attachment.pgp
More information about the freebsd-ports
mailing list