diff options
author | dzwdz | 2024-02-21 21:21:47 +0100 |
---|---|---|
committer | dzwdz | 2024-02-21 21:21:47 +0100 |
commit | b694ae71492a6261d2ea91b93dff78bc8789ea55 (patch) | |
tree | bd90a3b78ad67be77c749cdbac7dd90ccd4646ad /src/libc/fs | |
parent | 8adaf0da869a17ba37ab7d5cf4fddbf5d878978f (diff) |
libc/fs: use threads in forward_open
Diffstat (limited to 'src/libc/fs')
-rw-r--r-- | src/libc/fs/misc.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/libc/fs/misc.c b/src/libc/fs/misc.c index 30e5ab4..f0925ba 100644 --- a/src/libc/fs/misc.c +++ b/src/libc/fs/misc.c @@ -1,29 +1,38 @@ +#include <camellia/compat.h> #include <camellia/flags.h> +#include <camellia/fs/dir.h> +#include <camellia/fs/misc.h> #include <camellia/syscalls.h> #include <errno.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <thread.h> #include <unistd.h> -#include <camellia/compat.h> -#include <camellia/fs/dir.h> -#include <camellia/fs/misc.h> + +typedef struct { + hid_t reqh; + char *path; + long len; + int flags; +} Delegate; + +static void delegate_thread(void *p) { + // TODO don't share file descriptors with parent + Delegate *d = p; + _sys_fs_respond(d->reqh, NULL, _sys_open(d->path, d->len, d->flags), FSR_DELEGATE); + free(d->path); + free(d); +} void forward_open(hid_t reqh, const char *path, long len, int flags) { - // TODO use threads - // TODO solve for more complex cases, e.g. fs_union - /* done in a separate thread/process because open() can block, - * but that should only hold the caller back, and not the fs driver. - * - * for example, running `httpd` in one term would prevent you from doing - * basically anything on the second term, because fs_dirinject would be - * stuck on open()ing the socket */ - if (!_sys_fork(FORK_NOREAP, NULL)) { - _sys_fs_respond(reqh, NULL, _sys_open(path, len, flags), FSR_DELEGATE); - exit(0); - } - close(reqh); + Delegate *d = malloc(sizeof(Delegate)); + d->reqh = reqh; + d->path = strdup(path); + d->len = len; + d->flags = flags; + thread_create(FORK_NOREAP, delegate_thread, d); } void fs_passthru(const char *prefix) { @@ -82,6 +91,7 @@ void fs_union(const char **list) { break; } + // TODO resolve union directories in a thread ret = -1; for (size_t i = 0; ret < 0 && list[i]; i++) { const char *prefix = list[i]; |