Back out all POSIXified *env() changes.
Not because I admit they are technically wrong and not because of bug reports (I receive nothing). But because I surprisingly meets so strong opposition and resistance so lost any desire to continue that. Anyone who interested in POSIX can dig out what changes and how through cvs diffs.
This commit is contained in:
parent
8d497697b2
commit
ba174a5e38
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169177
@ -131,14 +131,14 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
if (kflag)
|
||||
break;
|
||||
putenv(strdup("BLOCKSIZE=512"));
|
||||
putenv("BLOCKSIZE=512");
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'g':
|
||||
putenv(strdup("BLOCKSIZE=1g"));
|
||||
putenv("BLOCKSIZE=1g");
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'H':
|
||||
@ -152,7 +152,7 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
case 'k':
|
||||
kflag++;
|
||||
putenv(strdup("BLOCKSIZE=1024"));
|
||||
putenv("BLOCKSIZE=1024");
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'l':
|
||||
@ -162,7 +162,7 @@ main(int argc, char *argv[])
|
||||
lflag = 1;
|
||||
break;
|
||||
case 'm':
|
||||
putenv(strdup("BLOCKSIZE=1m"));
|
||||
putenv("BLOCKSIZE=1m");
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'n':
|
||||
|
13
bin/sh/var.c
13
bin/sh/var.c
@ -319,7 +319,7 @@ setvareq(char *s, int flags)
|
||||
if (vp == &vmpath || (vp == &vmail && ! mpathset()))
|
||||
chkmail(1);
|
||||
if ((vp->flags & VEXPORT) && localevar(s)) {
|
||||
(void) putenv(savestr(s));
|
||||
putenv(s);
|
||||
(void) setlocale(LC_ALL, "");
|
||||
}
|
||||
INTON;
|
||||
@ -335,7 +335,7 @@ setvareq(char *s, int flags)
|
||||
INTOFF;
|
||||
*vpp = vp;
|
||||
if ((vp->flags & VEXPORT) && localevar(s)) {
|
||||
(void) putenv(savestr(s));
|
||||
putenv(s);
|
||||
(void) setlocale(LC_ALL, "");
|
||||
}
|
||||
INTON;
|
||||
@ -596,7 +596,7 @@ exportcmd(int argc, char **argv)
|
||||
|
||||
vp->flags |= flag;
|
||||
if ((vp->flags & VEXPORT) && localevar(vp->text)) {
|
||||
(void) putenv(savestr(vp->text));
|
||||
putenv(vp->text);
|
||||
(void) setlocale(LC_ALL, "");
|
||||
}
|
||||
goto found;
|
||||
@ -776,7 +776,6 @@ unsetcmd(int argc __unused, char **argv __unused)
|
||||
int
|
||||
unsetvar(char *s)
|
||||
{
|
||||
char *eqp, *ss;
|
||||
struct var **vpp;
|
||||
struct var *vp;
|
||||
|
||||
@ -789,11 +788,7 @@ unsetvar(char *s)
|
||||
if (*(strchr(vp->text, '=') + 1) != '\0')
|
||||
setvar(s, nullstr, 0);
|
||||
if ((vp->flags & VEXPORT) && localevar(vp->text)) {
|
||||
ss = savestr(s);
|
||||
if ((eqp = strchr(ss, '=')) != NULL)
|
||||
*eqp = '\0';
|
||||
(void) unsetenv(ss);
|
||||
ckfree(ss);
|
||||
unsetenv(s);
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
vp->flags &= ~VEXPORT;
|
||||
|
@ -161,7 +161,7 @@ void _Exit(int) __dead2;
|
||||
int posix_memalign(void **, size_t, size_t); /* (ADV) */
|
||||
int rand_r(unsigned *); /* (TSF) */
|
||||
int setenv(const char *, const char *, int);
|
||||
int unsetenv(const char *);
|
||||
void unsetenv(const char *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -197,7 +197,7 @@ long mrand48(void);
|
||||
long nrand48(unsigned short[3]);
|
||||
int posix_openpt(int);
|
||||
char *ptsname(int);
|
||||
int putenv(char *);
|
||||
int putenv(const char *);
|
||||
long random(void);
|
||||
char *realpath(const char *, char resolved_path[]);
|
||||
unsigned short
|
||||
|
@ -32,7 +32,7 @@
|
||||
.\" @(#)getenv.3 8.2 (Berkeley) 12/11/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd April 30, 2007
|
||||
.Dd October 12, 2006
|
||||
.Dt GETENV 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -50,13 +50,22 @@
|
||||
.Ft int
|
||||
.Fn setenv "const char *name" "const char *value" "int overwrite"
|
||||
.Ft int
|
||||
.Fn putenv "char *string"
|
||||
.Ft int
|
||||
.Fn putenv "const char *string"
|
||||
.Ft void
|
||||
.Fn unsetenv "const char *name"
|
||||
.Sh DESCRIPTION
|
||||
These functions set, unset and fetch environment variables from the
|
||||
host
|
||||
.Em environment list .
|
||||
For compatibility with differing environment conventions,
|
||||
the given arguments
|
||||
.Fa name
|
||||
and
|
||||
.Fa value
|
||||
may be appended and prepended,
|
||||
respectively,
|
||||
with an equal sign
|
||||
.Dq Li \&= .
|
||||
.Pp
|
||||
The
|
||||
.Fn getenv
|
||||
@ -88,18 +97,11 @@ to the given
|
||||
.Pp
|
||||
The
|
||||
.Fn putenv
|
||||
function takes an argument of the form ``name=value'' and
|
||||
puts it directly into the current environment,
|
||||
so altering the argument shall change the environment.
|
||||
If the variable
|
||||
.Fa name
|
||||
does not exist in the list,
|
||||
it is inserted with the given
|
||||
.Fa value .
|
||||
If the variable
|
||||
.Fa name
|
||||
does exist, it is reset to the given
|
||||
.Fa value .
|
||||
function takes an argument of the form ``name=value'' and is
|
||||
equivalent to:
|
||||
.Bd -literal -offset indent
|
||||
setenv(name, value, 1);
|
||||
.Ed
|
||||
.Pp
|
||||
The
|
||||
.Fn unsetenv
|
||||
@ -119,21 +121,9 @@ is not in the current environment,
|
||||
.Dv NULL
|
||||
is returned.
|
||||
.Pp
|
||||
.Rv -std setenv putenv unsetenv
|
||||
.Rv -std setenv putenv
|
||||
.Sh ERRORS
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er EINVAL
|
||||
The function
|
||||
.Fn setenv
|
||||
or
|
||||
.Fn unsetenv
|
||||
failed because the
|
||||
.Fa name
|
||||
is a
|
||||
.Dv NULL
|
||||
pointer, points to an empty string, or points to a string containing an
|
||||
.Dq Li \&=
|
||||
character.
|
||||
.It Bq Er ENOMEM
|
||||
The function
|
||||
.Fn setenv
|
||||
@ -151,13 +141,6 @@ The
|
||||
.Fn getenv
|
||||
function conforms to
|
||||
.St -isoC .
|
||||
The
|
||||
.Fn setenv ,
|
||||
.Fn putenv
|
||||
and
|
||||
.Fn unsetenv
|
||||
functions conforms to
|
||||
.St -p1003.1-2001 .
|
||||
.Sh HISTORY
|
||||
The functions
|
||||
.Fn setenv
|
||||
|
@ -43,7 +43,7 @@ inline char *__findenv(const char *, int *);
|
||||
* __findenv --
|
||||
* Returns pointer to value associated with name, if any, else NULL.
|
||||
* Sets offset to be the offset of the name/value combination in the
|
||||
* environmental array, for use by putenv(3), setenv(3) and unsetenv(3).
|
||||
* environmental array, for use by setenv(3) and unsetenv(3).
|
||||
* Explicitly removes '=' in argument name.
|
||||
*
|
||||
* This routine *should* be a static; don't use it.
|
||||
@ -58,7 +58,7 @@ __findenv(name, offset)
|
||||
const char *np;
|
||||
char **p, *cp;
|
||||
|
||||
if (environ == NULL)
|
||||
if (name == NULL || environ == NULL)
|
||||
return (NULL);
|
||||
for (np = name; *np && *np != '='; ++np)
|
||||
continue;
|
||||
@ -85,8 +85,5 @@ getenv(name)
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (name == NULL || !*name || strchr(name, '=') != NULL)
|
||||
return (NULL);
|
||||
|
||||
return (__findenv(name, &offset));
|
||||
}
|
||||
|
@ -33,50 +33,24 @@ static char sccsid[] = "@(#)putenv.c 8.2 (Berkeley) 3/27/94";
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern char **__alloced; /* if allocated space before */
|
||||
|
||||
char *__findenv(const char *, int *);
|
||||
|
||||
int
|
||||
putenv(str)
|
||||
char *str;
|
||||
const char *str;
|
||||
{
|
||||
extern char **environ;
|
||||
char *eq;
|
||||
int offset;
|
||||
char *p, *equal;
|
||||
int rval;
|
||||
|
||||
if (str == NULL || (eq = strchr(str, '=')) == NULL || eq == str) {
|
||||
errno = EINVAL;
|
||||
if ((p = strdup(str)) == NULL)
|
||||
return (-1);
|
||||
if ((equal = index(p, '=')) == NULL) {
|
||||
(void)free(p);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Trimmed version of setenv(3). */
|
||||
if (__findenv(str, &offset) == NULL) {
|
||||
int cnt;
|
||||
char **p;
|
||||
|
||||
for (p = environ, cnt = 0; *p; ++p, ++cnt);
|
||||
if (__alloced == environ) { /* just increase size */
|
||||
p = (char **)realloc((char *)environ,
|
||||
(size_t)(sizeof(char *) * (cnt + 2)));
|
||||
if (!p)
|
||||
return (-1);
|
||||
}
|
||||
else { /* get new space */
|
||||
/* copy old entries into it */
|
||||
p = (char **)malloc((size_t)(sizeof(char *) * (cnt + 2)));
|
||||
if (!p)
|
||||
return (-1);
|
||||
bcopy(environ, p, cnt * sizeof(char *));
|
||||
}
|
||||
__alloced = environ = p;
|
||||
environ[cnt + 1] = NULL;
|
||||
offset = cnt;
|
||||
}
|
||||
environ[offset] = str;
|
||||
return (0);
|
||||
*equal = '\0';
|
||||
rval = setenv(p, equal + 1, 1);
|
||||
(void)free(p);
|
||||
return (rval);
|
||||
}
|
||||
|
@ -33,13 +33,10 @@ static char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char **__alloced; /* if allocated space before */
|
||||
|
||||
char *__findenv(const char *, int *);
|
||||
|
||||
/*
|
||||
@ -54,14 +51,12 @@ setenv(name, value, rewrite)
|
||||
int rewrite;
|
||||
{
|
||||
extern char **environ;
|
||||
static char **alloced; /* if allocated space before */
|
||||
char *c;
|
||||
int l_value, offset;
|
||||
|
||||
if (name == NULL || !*name || strchr(name, '=') != NULL) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (*value == '=') /* no `=' in value */
|
||||
++value;
|
||||
l_value = strlen(value);
|
||||
if ((c = __findenv(name, &offset))) { /* find if already exists */
|
||||
if (!rewrite)
|
||||
@ -75,25 +70,27 @@ setenv(name, value, rewrite)
|
||||
char **p;
|
||||
|
||||
for (p = environ, cnt = 0; *p; ++p, ++cnt);
|
||||
if (__alloced == environ) { /* just increase size */
|
||||
if (alloced == environ) { /* just increase size */
|
||||
p = (char **)realloc((char *)environ,
|
||||
(size_t)(sizeof(char *) * (cnt + 2)));
|
||||
if (!p)
|
||||
return (-1);
|
||||
alloced = environ = p;
|
||||
}
|
||||
else { /* get new space */
|
||||
/* copy old entries into it */
|
||||
p = (char **)malloc((size_t)(sizeof(char *) * (cnt + 2)));
|
||||
p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
|
||||
if (!p)
|
||||
return (-1);
|
||||
bcopy(environ, p, cnt * sizeof(char *));
|
||||
alloced = environ = p;
|
||||
}
|
||||
__alloced = environ = p;
|
||||
environ[cnt + 1] = NULL;
|
||||
offset = cnt;
|
||||
}
|
||||
for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */
|
||||
if (!(environ[offset] = /* name + `=' + value */
|
||||
(char *)malloc((size_t)(strlen(name) + l_value + 2))))
|
||||
malloc((size_t)((int)(c - name) + l_value + 2))))
|
||||
return (-1);
|
||||
for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
|
||||
for (*c++ = '='; (*c++ = *value++); );
|
||||
@ -104,7 +101,7 @@ setenv(name, value, rewrite)
|
||||
* unsetenv(name) --
|
||||
* Delete environmental variable "name".
|
||||
*/
|
||||
int
|
||||
void
|
||||
unsetenv(name)
|
||||
const char *name;
|
||||
{
|
||||
@ -112,14 +109,8 @@ unsetenv(name)
|
||||
char **p;
|
||||
int offset;
|
||||
|
||||
if (name == NULL || !*name || strchr(name, '=') != NULL) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
while (__findenv(name, &offset)) /* if set multiple times */
|
||||
for (p = &environ[offset];; ++p)
|
||||
if (!(*p = *(p + 1)))
|
||||
break;
|
||||
return (0);
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ Spawn(const char *prog, const char *acname, const char *provider,
|
||||
struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
|
||||
struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep);
|
||||
struct ngpppoe_init_data *data;
|
||||
char env[18], unknown[14], sessionid[5], *path;
|
||||
char env[sizeof(HISMACADDR)+18], unknown[14], sessionid[5], *path;
|
||||
unsigned char *macaddr;
|
||||
const char *msg;
|
||||
int ret, slen;
|
||||
@ -352,11 +352,11 @@ Spawn(const char *prog, const char *acname, const char *provider,
|
||||
/* Put the peer's MAC address in the environment */
|
||||
if (sz >= sizeof(struct ether_header)) {
|
||||
macaddr = ((struct ether_header *)request)->ether_shost;
|
||||
snprintf(env, sizeof(env), "%x:%x:%x:%x:%x:%x",
|
||||
snprintf(env, sizeof(env), "%s=%x:%x:%x:%x:%x:%x", HISMACADDR,
|
||||
macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4],
|
||||
macaddr[5]);
|
||||
if (setenv(HISMACADDR, env, 1) != 0)
|
||||
syslog(LOG_INFO, "setenv: cannot set %s: %m", HISMACADDR);
|
||||
if (putenv(env) != 0)
|
||||
syslog(LOG_INFO, "putenv: cannot set %s: %m", env);
|
||||
}
|
||||
|
||||
/* And send our request data to the waiting node */
|
||||
|
@ -57,7 +57,7 @@
|
||||
* is created, otherwise 1.
|
||||
*/
|
||||
#undef __FreeBSD_version
|
||||
#define __FreeBSD_version 700038 /* Master, propagated to newvers */
|
||||
#define __FreeBSD_version 700037 /* Master, propagated to newvers */
|
||||
|
||||
#ifndef LOCORE
|
||||
#include <sys/types.h>
|
||||
|
@ -140,16 +140,16 @@ main(int argc, char *argv[])
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
putenv(strdup("BLOCKSIZE=512"));
|
||||
putenv("BLOCKSIZE=512");
|
||||
hflag = 1;
|
||||
break;
|
||||
case 'k':
|
||||
hflag = 0;
|
||||
putenv(strdup("BLOCKSIZE=1024"));
|
||||
putenv("BLOCKSIZE=1024");
|
||||
break;
|
||||
case 'm':
|
||||
hflag = 0;
|
||||
putenv(strdup("BLOCKSIZE=1048576"));
|
||||
putenv("BLOCKSIZE=1048576");
|
||||
break;
|
||||
case 'n':
|
||||
nodumpflag = 1;
|
||||
|
6
usr.bin/env/env.c
vendored
6
usr.bin/env/env.c
vendored
@ -64,7 +64,7 @@ static void usage(void);
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *altpath, **ep, **parg;
|
||||
char *altpath, **ep, *p, **parg;
|
||||
char *cleanenv[1];
|
||||
int ch, want_clear;
|
||||
|
||||
@ -102,10 +102,10 @@ main(int argc, char **argv)
|
||||
if (env_verbosity)
|
||||
fprintf(stderr, "#env clearing environ\n");
|
||||
}
|
||||
for (argv += optind; *argv && strchr(*argv, '=') != NULL; ++argv) {
|
||||
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
|
||||
if (env_verbosity)
|
||||
fprintf(stderr, "#env setenv:\t%s\n", *argv);
|
||||
(void)putenv(strdup(*argv));
|
||||
(void)setenv(*argv, ++p, 1);
|
||||
}
|
||||
if (*argv) {
|
||||
if (altpath)
|
||||
|
@ -399,8 +399,8 @@ main(int argc, char *argv[])
|
||||
login_close(lc);
|
||||
|
||||
/* set leading environment variables, like eval(1) */
|
||||
while (*argv && strchr(*argv, '=') != NULL)
|
||||
(void)putenv(strdup(*argv++));
|
||||
while (*argv && (p = strchr(*argv, '=')))
|
||||
(void)setenv(*argv++, ++p, 1);
|
||||
|
||||
/* Set limits */
|
||||
for (rcswhich = 0; rcswhich < RLIM_NLIMITS; rcswhich++) {
|
||||
|
@ -745,7 +745,7 @@ export_pam_environment()
|
||||
pam_env = pam_getenvlist(pamh);
|
||||
if (pam_env != NULL) {
|
||||
for (pp = pam_env; *pp != NULL; pp++) {
|
||||
if (!export(*pp))
|
||||
(void)export(*pp);
|
||||
free(*pp);
|
||||
}
|
||||
}
|
||||
|
@ -567,8 +567,7 @@ export_pam_environment(void)
|
||||
|
||||
for (pp = environ_pam; *pp != NULL; pp++) {
|
||||
if (ok_to_export(*pp))
|
||||
(void)putenv(*pp);
|
||||
else
|
||||
putenv(*pp);
|
||||
free(*pp);
|
||||
}
|
||||
}
|
||||
|
@ -135,16 +135,16 @@ main(int argc, char *argv[])
|
||||
fileflag = 1;
|
||||
break;
|
||||
case 'g':
|
||||
putenv(strdup("BLOCKSIZE=1G"));
|
||||
putenv("BLOCKSIZE=1G");
|
||||
break;
|
||||
case 'h':
|
||||
humanflag = 1;
|
||||
break;
|
||||
case 'k':
|
||||
putenv(strdup("BLOCKSIZE=1K"));
|
||||
putenv("BLOCKSIZE=1K");
|
||||
break;
|
||||
case 'm':
|
||||
putenv(strdup("BLOCKSIZE=1M"));
|
||||
putenv("BLOCKSIZE=1M");
|
||||
break;
|
||||
case 'M':
|
||||
memf = optarg;
|
||||
|
@ -56,7 +56,7 @@ main(int argc, char **argv)
|
||||
/* XXX */
|
||||
char *p = getenv("TERM");
|
||||
if (p && strcmp(p, "cons25") == 0)
|
||||
(void)putenv(strdup("TERM=cons25w"));
|
||||
putenv("TERM=cons25w");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -307,7 +307,7 @@ pvariable_set(char *var)
|
||||
if (index(var, '=') == NULL)
|
||||
msgFatal("Invalid variable format: %s", var);
|
||||
strlcat(tmp, var, 1024);
|
||||
(void)putenv(strdup(tmp));
|
||||
putenv(tmp);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -74,7 +74,7 @@ main(int argc, char **argv)
|
||||
/* XXX */
|
||||
char *p = getenv("TERM");
|
||||
if (p && strcmp(p, "cons25") == 0)
|
||||
(void)putenv(strdup("TERM=cons25w"));
|
||||
putenv("TERM=cons25w");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -312,7 +312,7 @@ pvariable_set(char *var)
|
||||
if (index(var, '=') == NULL)
|
||||
msgFatal("Invalid variable format: %s", var);
|
||||
strlcat(tmp, var, 1024);
|
||||
(void)putenv(strdup(tmp));
|
||||
putenv(tmp);
|
||||
}
|
||||
|
||||
char *
|
||||
|
Loading…
Reference in New Issue
Block a user