diff options
-rw-r--r-- | src/alloc.c | 1 | ||||
-rw-r--r-- | src/bfstd.c | 2 | ||||
-rw-r--r-- | src/config.h | 4 | ||||
-rw-r--r-- | src/eval.c | 4 | ||||
-rw-r--r-- | src/xspawn.c | 25 |
5 files changed, 33 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c index 3b9972f..ff3ec6d 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3,6 +3,7 @@ #include "alloc.h" #include "bit.h" +#include "config.h" #include "diag.h" #include "sanity.h" #include <errno.h> diff --git a/src/bfstd.c b/src/bfstd.c index 985a268..16cd82e 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -284,7 +284,7 @@ const char *xstrerror(int errnum) { const char *ret = NULL; static thread_local char buf[256]; -#if __APPLE__ +#if __APPLE__ || __COSMOPOLITAN__ // No strerror_l() on macOS if (strerror_r(errnum, buf, sizeof(buf)) == 0) { ret = buf; diff --git a/src/config.h b/src/config.h index 821e4a9..a474fb3 100644 --- a/src/config.h +++ b/src/config.h @@ -179,6 +179,10 @@ */ #define cache_align alignas(FALSE_SHARING_SIZE) +#if __COSMOPOLITAN__ +typedef long double max_align_t; +#endif + // Wrappers for attributes /** @@ -1558,7 +1558,9 @@ static const char *dump_bftw_strategy(enum bftw_strategy strategy) { /** Check if we need to enable BFTW_BUFFER. */ static bool eval_must_buffer(const struct bfs_expr *expr) { -#if __FreeBSD__ +#if __COSMOPOLITAN__ + return true; +#elif __FreeBSD__ // FreeBSD doesn't properly handle adding/removing directory entries // during readdir() on NFS mounts. Work around it by passing BFTW_BUFFER // whenever we could be mutating the directory ourselves through -delete diff --git a/src/xspawn.c b/src/xspawn.c index 01f21e9..6a2ebba 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -174,15 +174,38 @@ int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { int bfs_spawn_addsetrlimit(struct bfs_spawn *ctx, int resource, const struct rlimit *rl) { struct bfs_spawn_action *action = bfs_spawn_action(BFS_SPAWN_SETRLIMIT); if (!action) { - return -1; + goto fail; + } + +#ifdef POSIX_SPAWN_SETRLIMIT + short flags; + errno = posix_spawnattr_getflags(&ctx->attr, &flags); + if (errno != 0) { + goto fail; + } + + flags |= POSIX_SPAWN_SETRLIMIT; + errno = posix_spawnattr_setflags(&ctx->attr, flags); + if (errno != 0) { + goto fail; } + errno = posix_spawnattr_setrlimit(&ctx->attr, resource, rl); + if (errno != 0) { + goto fail; + } +#else ctx->flags &= ~BFS_SPAWN_USE_POSIX; +#endif action->resource = resource; action->rlimit = *rl; SLIST_APPEND(ctx, action); return 0; + +fail: + free(action); + return -1; } /** bfs_spawn() implementation using posix_spawn(). */ |