Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Nov 2006 15:36:24 -0500
From:      Joe Marcus Clarke <marcus@marcuscom.com>
To:        Sevan / Venture37 <venture37@hotmail.com>
Cc:        ports@freebsd.org
Subject:   Re: Dealing with clearenv()
Message-ID:  <1163968584.85615.3.camel@shumai.marcuscom.com>
In-Reply-To: <4560BEA2.3070809@hotmail.com>
References:  <4560BEA2.3070809@hotmail.com>

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

--=-0NaArx14r80BhX5VLGDr
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

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() !=3D 0) {
>      sys_err(LOG_ERR, __FILE__, __LINE__, errno,
>  	    "clearenv() did not return 0!");
>      exit(0);
>    }
> +#else
> +        extern char **environ;
> +	environ[0] =3D NULL;
> +        if (environ[0] !=3D 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] =3D NULL;
	return 0;
#endif
}
...

if (my_cleanenv() !=3D 0) {
...

Joe

--=20
PGP Key : http://www.marcuscom.com/pgp.asc

--=-0NaArx14r80BhX5VLGDr
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (FreeBSD)

iD8DBQBFYMBIb2iPiv4Uz4cRAgpfAJ94fMMQkMX2MN8GA/I2KeD9jg12NACfa6YM
Yew22bANCm764kzGobcxtKs=
=m1yf
-----END PGP SIGNATURE-----

--=-0NaArx14r80BhX5VLGDr--




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