ape: fix _grpmems(), access(), getppid(), cleanup
_grpmems() was broken tokenizing group list in place. we have to copy it to status buffer before tokenizing. dynamically alloc path for test file to check write permission on directory and add pid to the name to prevent races. use _OPEN instead of ape open to read /dev/ppid in getppid(). use mode enums instead of numeric constants for _OPEN() and _CREATE().
This commit is contained in:
parent
52b9a06896
commit
4661934e31
7 changed files with 34 additions and 27 deletions
|
@ -44,7 +44,7 @@ _envsetup(void)
|
|||
nohandle = 0;
|
||||
fdinited = 0;
|
||||
cnt = 0;
|
||||
dfd = _OPEN("/env", 0);
|
||||
dfd = _OPEN("/env", OREAD);
|
||||
if(dfd < 0)
|
||||
goto done;
|
||||
psize = Envhunk;
|
||||
|
@ -63,7 +63,7 @@ _envsetup(void)
|
|||
}
|
||||
strcpy(p, "/env/");
|
||||
memcpy(p+5, d9->name, n+1);
|
||||
f = _OPEN(p, 0);
|
||||
f = _OPEN(p, OREAD);
|
||||
memset(p, 0, n+6);
|
||||
memcpy(p, d9->name, n);
|
||||
p[n] = '=';
|
||||
|
|
|
@ -41,7 +41,7 @@ readprocfdinit(void)
|
|||
strcpy(buf, "/proc/");
|
||||
_ultoa(buf+6, getpid());
|
||||
strcat(buf, "/fd");
|
||||
pfd = _OPEN(buf, 0);
|
||||
pfd = _OPEN(buf, OREAD);
|
||||
if(pfd < 0)
|
||||
return -1;
|
||||
memset(buf, 0, sizeof buf);
|
||||
|
|
|
@ -153,20 +153,19 @@ _grpmems(char *list)
|
|||
char **v;
|
||||
char *p;
|
||||
static char *holdvec[200];
|
||||
static char holdlist[1000];
|
||||
static char holdlist[1024];
|
||||
|
||||
p = list;
|
||||
v = holdvec;
|
||||
if(p) {
|
||||
strncpy(holdlist, list, sizeof(holdlist));
|
||||
if(list != 0){
|
||||
memset(holdlist, 0, sizeof(holdlist));
|
||||
strncpy(holdlist, list, sizeof(holdlist)-1);
|
||||
p = holdlist;
|
||||
while(v< &holdvec[sizeof(holdvec)]-1 && *p){
|
||||
*v++ = p;
|
||||
p = strchr(p, ',');
|
||||
if(p){
|
||||
p++;
|
||||
*p = 0;
|
||||
}else
|
||||
if(p == 0)
|
||||
break;
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
*v = 0;
|
||||
|
|
|
@ -24,8 +24,6 @@ access(const char *name, int mode)
|
|||
2,
|
||||
2
|
||||
};
|
||||
char tname[1024];
|
||||
|
||||
if(mode == 0){
|
||||
db = _dirstat(name);
|
||||
if(db == nil){
|
||||
|
@ -48,13 +46,23 @@ access(const char *name, int mode)
|
|||
close(fd);
|
||||
}
|
||||
if(mode & W_OK){
|
||||
strncpy(tname, name, sizeof(tname)-9);
|
||||
strcat(tname, "/_AcChAcK");
|
||||
fd = creat(tname, 0666);
|
||||
if(fd < 0)
|
||||
char *tname;
|
||||
int nname;
|
||||
nname = strlen(name);
|
||||
tname = malloc(nname+32);
|
||||
if(tname == 0)
|
||||
return -1;
|
||||
close(fd);
|
||||
_REMOVE(tname);
|
||||
memset(tname, 0, nname+32);
|
||||
memcpy(tname, name, n);
|
||||
memcpy(tname+nname, "/_AcChAcK", 9);
|
||||
_ultoa(tname+nname+9, getpid());
|
||||
fd = _CREATE(tname, ORCLOSE, 0666);
|
||||
if(fd < 0){
|
||||
free(tname);
|
||||
return -1;
|
||||
}
|
||||
_CLOSE(fd);
|
||||
free(tname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "sys9.h"
|
||||
|
||||
pid_t
|
||||
|
@ -13,10 +13,10 @@ getppid(void)
|
|||
int f;
|
||||
|
||||
memset(b, 0, sizeof(b));
|
||||
f = open("/dev/ppid", 0);
|
||||
f = _OPEN("/dev/ppid", OREAD);
|
||||
if(f >= 0) {
|
||||
read(f, b, sizeof(b));
|
||||
close(f);
|
||||
_PREAD(f, b, sizeof(b), 0);
|
||||
_CLOSE(f);
|
||||
}
|
||||
return atol(b);
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ rename(const char *from, const char *to)
|
|||
int ffd, tfd;
|
||||
char buf[8192];
|
||||
|
||||
if((ffd = _OPEN(from, 0)) < 0 ||
|
||||
(tfd = _CREATE(to, 1, d->mode)) < 0){
|
||||
if((ffd = _OPEN(from, OREAD)) < 0 ||
|
||||
(tfd = _CREATE(to, OWRITE, d->mode)) < 0){
|
||||
_CLOSE(ffd);
|
||||
_syserrno();
|
||||
n = -1;
|
||||
}
|
||||
while(n>=0 && (n = _READ(ffd, buf, 8192)) > 0)
|
||||
while(n>=0 && (n = _READ(ffd, buf, sizeof(buf))) > 0)
|
||||
if(_WRITE(tfd, buf, n) != n){
|
||||
_syserrno();
|
||||
n = -1;
|
||||
|
|
|
@ -15,7 +15,7 @@ time(time_t *tp)
|
|||
time_t t;
|
||||
|
||||
memset(b, 0, sizeof(b));
|
||||
f = _OPEN("/dev/time", 0);
|
||||
f = _OPEN("/dev/time", OREAD);
|
||||
if(f >= 0) {
|
||||
_PREAD(f, b, sizeof(b), 0);
|
||||
_CLOSE(f);
|
||||
|
|
Loading…
Reference in a new issue