summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2007-05-01 16:02:44 +0000
committerache <ache@FreeBSD.org>2007-05-01 16:02:44 +0000
commit6ccaf050cc62bc9d81ac3acb71ce640739caa0f7 (patch)
treee3e0b3658b8df3a905b3117d8535bb15f42c9e80
parent61e9800ad7707590037d6868c703475f36cf7058 (diff)
downloadFreeBSD-src-6ccaf050cc62bc9d81ac3acb71ce640739caa0f7.zip
FreeBSD-src-6ccaf050cc62bc9d81ac3acb71ce640739caa0f7.tar.gz
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.
-rw-r--r--bin/df/df.c8
-rw-r--r--bin/sh/var.c13
-rw-r--r--include/stdlib.h4
-rw-r--r--lib/libc/stdlib/getenv.353
-rw-r--r--lib/libc/stdlib/getenv.c7
-rw-r--r--lib/libc/stdlib/putenv.c48
-rw-r--r--lib/libc/stdlib/setenv.c29
-rw-r--r--libexec/pppoed/pppoed.c8
-rw-r--r--sys/sys/param.h2
-rw-r--r--usr.bin/du/du.c6
-rw-r--r--usr.bin/env/env.c6
-rw-r--r--usr.bin/limits/limits.c4
-rw-r--r--usr.bin/login/login.c4
-rw-r--r--usr.bin/su/su.c5
-rw-r--r--usr.sbin/pstat/pstat.c6
-rw-r--r--usr.sbin/sade/main.c2
-rw-r--r--usr.sbin/sade/variable.c2
-rw-r--r--usr.sbin/sysinstall/main.c2
-rw-r--r--usr.sbin/sysinstall/variable.c2
19 files changed, 75 insertions, 136 deletions
diff --git a/bin/df/df.c b/bin/df/df.c
index 0350d98..5420da9 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -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':
diff --git a/bin/sh/var.c b/bin/sh/var.c
index afb144a..54a0a84 100644
--- a/bin/sh/var.c
+++ b/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;
diff --git a/include/stdlib.h b/include/stdlib.h
index 98cb465..98fe8b7 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -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
diff --git a/lib/libc/stdlib/getenv.3 b/lib/libc/stdlib/getenv.3
index 9ebf30b..3d365f1 100644
--- a/lib/libc/stdlib/getenv.3
+++ b/lib/libc/stdlib/getenv.3
@@ -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
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index 9ff18d8..306b6a1 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -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));
}
diff --git a/lib/libc/stdlib/putenv.c b/lib/libc/stdlib/putenv.c
index 56b78cf..a5eea5d 100644
--- a/lib/libc/stdlib/putenv.c
+++ b/lib/libc/stdlib/putenv.c
@@ -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);
}
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 5725733..202c022 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -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);
}
diff --git a/libexec/pppoed/pppoed.c b/libexec/pppoed/pppoed.c
index dc87896..8dfebb7 100644
--- a/libexec/pppoed/pppoed.c
+++ b/libexec/pppoed/pppoed.c
@@ -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 */
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 93ad89d..b8d5d13 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -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>
diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c
index 459a451..00c1f5e 100644
--- a/usr.bin/du/du.c
+++ b/usr.bin/du/du.c
@@ -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;
diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c
index b5866ef..815976f 100644
--- a/usr.bin/env/env.c
+++ b/usr.bin/env/env.c
@@ -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)
diff --git a/usr.bin/limits/limits.c b/usr.bin/limits/limits.c
index 854803b..e976f36 100644
--- a/usr.bin/limits/limits.c
+++ b/usr.bin/limits/limits.c
@@ -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++) {
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c
index 4a2abb4..7827ea1 100644
--- a/usr.bin/login/login.c
+++ b/usr.bin/login/login.c
@@ -745,8 +745,8 @@ export_pam_environment()
pam_env = pam_getenvlist(pamh);
if (pam_env != NULL) {
for (pp = pam_env; *pp != NULL; pp++) {
- if (!export(*pp))
- free(*pp);
+ (void)export(*pp);
+ free(*pp);
}
}
}
diff --git a/usr.bin/su/su.c b/usr.bin/su/su.c
index 26f4a3e..76f76b6 100644
--- a/usr.bin/su/su.c
+++ b/usr.bin/su/su.c
@@ -567,9 +567,8 @@ export_pam_environment(void)
for (pp = environ_pam; *pp != NULL; pp++) {
if (ok_to_export(*pp))
- (void)putenv(*pp);
- else
- free(*pp);
+ putenv(*pp);
+ free(*pp);
}
}
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index 8fdd83d..95f782c 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -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;
diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c
index 65e14a9..45ed1bb 100644
--- a/usr.sbin/sade/main.c
+++ b/usr.sbin/sade/main.c
@@ -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
diff --git a/usr.sbin/sade/variable.c b/usr.sbin/sade/variable.c
index f09819e..bbbc2d2 100644
--- a/usr.sbin/sade/variable.c
+++ b/usr.sbin/sade/variable.c
@@ -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 *
diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c
index c1b4e34..7af8d44 100644
--- a/usr.sbin/sysinstall/main.c
+++ b/usr.sbin/sysinstall/main.c
@@ -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
diff --git a/usr.sbin/sysinstall/variable.c b/usr.sbin/sysinstall/variable.c
index ad783fc..e86104f 100644
--- a/usr.sbin/sysinstall/variable.c
+++ b/usr.sbin/sysinstall/variable.c
@@ -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 *
OpenPOWER on IntegriCloud