syscalls: implement O_CLOEXEC properly

This commit is contained in:
Matheus
2024-05-08 20:57:52 -03:00
parent c894352bc8
commit ce3fad266b
3 changed files with 14 additions and 7 deletions
+2 -2
View File
@@ -45,7 +45,7 @@ syscallret_t syscall_accept(context_t *, int oldfd, abisockaddr_t *abisockaddr,
file_t *newfile;
int newfd;
ret.errno = fd_new(0, &newfile, &newfd);
ret.errno = fd_new(acceptflags & O_CLOEXEC, &newfile, &newfd);
if (ret.errno) {
// socket gets deleted by node cleanup
VOP_RELEASE(vnode);
@@ -53,7 +53,7 @@ syscallret_t syscall_accept(context_t *, int oldfd, abisockaddr_t *abisockaddr,
}
newfile->vnode = vnode;
newfile->flags = FILE_READ | FILE_WRITE | (acceptflags & (O_CLOEXEC | O_NONBLOCK));
newfile->flags = FILE_READ | FILE_WRITE | (acceptflags & (O_NONBLOCK));
newfile->offset = 0;
newfile->mode = 0777;
+11 -3
View File
@@ -21,6 +21,7 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
.ret = -1
};
// TODO shebang
// TODO user str ops
char *path = alloc(strlen(upath) + 1);
if (path == NULL) {
@@ -38,6 +39,7 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
vnode_t *node = NULL;
vnode_t *refnode = NULL;
char *interp = NULL;
void *stack = NULL;
while (uargv[argsize++]);
while (uenvp[envsize++]);
@@ -107,7 +109,7 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
VOP_RELEASE(interpnode);
}
void *stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp);
stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp);
if (stack == NULL) {
ret.errno = ENOMEM;
goto error;
@@ -115,10 +117,16 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
ret.ret = 0;
// TODO close CLOEXEC fds
sched_stopotherthreads();
// close O_CLOEXEC fds
proc_t *proc = _cpu()->thread->proc;
for (int fd = 0; fd < proc->fdcount; ++fd) {
if (proc->fd[fd].flags & O_CLOEXEC)
fd_close(fd);
}
error:
free(path);
if (argv)
+1 -2
View File
@@ -28,10 +28,9 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
ret.errno = dirfd_enter(pathbuf, dirfd, &dirfile, &dirnode);
// TODO pass CLOEXEC to fd
file_t *newfile = NULL;
int newfd;
ret.errno = fd_new(0, &newfile, &newfd);
ret.errno = fd_new(flags & O_CLOEXEC, &newfile, &newfd);
if (ret.errno)
goto cleanup;