ape: fix putenv()
writing /env in putenv() doesnt work. exec will create new enviroment anyway. we have to modify environ array!
This commit is contained in:
parent
eb9de925c6
commit
84c930a078
6 changed files with 5 additions and 39 deletions
|
@ -36,7 +36,6 @@ extern int rresvport(int*);
|
|||
extern int rcmd(char**, int, char*, char*, char*, int*);
|
||||
extern char* strdup(char*);
|
||||
extern int strcasecmp(char*, char*);
|
||||
extern int putenv(char*);
|
||||
extern int strncasecmp(char*, char*,int);
|
||||
extern void* memccpy(void*, void*, int, size_t);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ extern void abort(void);
|
|||
extern int atexit(void (*func)(void));
|
||||
extern void exit(int);
|
||||
extern char *getenv(const char *);
|
||||
extern int putenv(char *);
|
||||
extern int system(const char *);
|
||||
extern void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
|
|
|
@ -17,6 +17,7 @@ ALLOFILES=\
|
|||
difftime.$O\
|
||||
div.$O\
|
||||
getenv.$O\
|
||||
putenv.$O\
|
||||
isalnum.$O\
|
||||
itoa.$O\
|
||||
itol.$O\
|
||||
|
|
|
@ -45,11 +45,8 @@ _envsetup(void)
|
|||
fdinited = 0;
|
||||
cnt = 0;
|
||||
dfd = _OPEN("/env", 0);
|
||||
if(dfd < 0) {
|
||||
static char **emptyenvp = 0;
|
||||
environ = emptyenvp;
|
||||
return;
|
||||
}
|
||||
if(dfd < 0)
|
||||
goto done;
|
||||
psize = Envhunk;
|
||||
ps = p = malloc(psize);
|
||||
nd = _dirreadall(dfd, &d9a);
|
||||
|
@ -92,6 +89,7 @@ _envsetup(void)
|
|||
free(d9a);
|
||||
if(!fdinited)
|
||||
_fdinit(0, 0);
|
||||
done:
|
||||
environ = pp = malloc((1+cnt)*sizeof(char *));
|
||||
p = ps;
|
||||
for(i = 0; i < cnt; i++) {
|
||||
|
|
|
@ -29,7 +29,6 @@ OFILES=\
|
|||
ntohl.$O\
|
||||
nptohl.$O\
|
||||
popen.$O\
|
||||
putenv.$O\
|
||||
rcmd.$O\
|
||||
readv.$O\
|
||||
rresvport.$O\
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
putenv(char *s)
|
||||
{
|
||||
int f, n;
|
||||
char *value;
|
||||
char buf[300];
|
||||
|
||||
value = strchr(s, '=');
|
||||
if (value) {
|
||||
n = value-s;
|
||||
if(n<=0 || n > sizeof(buf)-6)
|
||||
return -1;
|
||||
strcpy(buf, "/env/");
|
||||
strncpy(buf+5, s, n);
|
||||
buf[n+5] = 0;
|
||||
f = creat(buf, 0666);
|
||||
if(f < 0)
|
||||
return 1;
|
||||
value++;
|
||||
n = strlen(value);
|
||||
if(write(f, value, n) != n)
|
||||
return -1;
|
||||
close(f);
|
||||
return 0;
|
||||
} else
|
||||
return -1;
|
||||
}
|
Loading…
Reference in a new issue